From 010c4fbdc56bb293803797b1a8b3b416709a54a2 Mon Sep 17 00:00:00 2001 From: Keith Buck Date: Mon, 3 Mar 2014 03:58:40 +0000 Subject: [PATCH] s_conf: Don't leak strings when loading default conf This change prevents conf strings from being leaked when resetting the conf to default prior to a rehash. Additionally, some default strings are now rb_strdup'd into the ConfigFileEntry structure after loading the conf so that they aren't allocated and then immediately freed by the conf loading process. --- src/s_conf.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/s_conf.c b/src/s_conf.c index 203e59f5..e858dce8 100644 --- a/src/s_conf.c +++ b/src/s_conf.c @@ -673,8 +673,8 @@ set_default_conf(void) /* ServerInfo.name is not rehashable */ /* ServerInfo.name = ServerInfo.name; */ ServerInfo.description = NULL; - ServerInfo.network_name = rb_strdup(NETWORK_NAME_DEFAULT); - ServerInfo.network_desc = rb_strdup(NETWORK_DESC_DEFAULT); + ServerInfo.network_name = NULL; + ServerInfo.network_desc = NULL; memset(&ServerInfo.ip, 0, sizeof(ServerInfo.ip)); ServerInfo.specific_ipv4_vhost = 0; @@ -689,9 +689,9 @@ set_default_conf(void) AdminInfo.email = NULL; AdminInfo.description = NULL; - ConfigFileEntry.default_operstring = rb_strdup("is an IRC operator"); - ConfigFileEntry.default_adminstring = rb_strdup("is a Server Administrator"); - ConfigFileEntry.servicestring = rb_strdup("is a Network Service"); + ConfigFileEntry.default_operstring = NULL; + ConfigFileEntry.default_adminstring = NULL; + ConfigFileEntry.servicestring = NULL; ConfigFileEntry.default_umodes = UMODE_INVISIBLE; ConfigFileEntry.failed_oper_notice = YES; @@ -875,6 +875,16 @@ validate_conf(void) } + /* General conf */ + if (ConfigFileEntry.default_operstring == NULL) + ConfigFileEntry.default_operstring = rb_strdup("is an IRC operator"); + + if (ConfigFileEntry.default_adminstring == NULL) + ConfigFileEntry.default_adminstring = rb_strdup("is a Server Administrator"); + + if (ConfigFileEntry.servicestring == NULL) + ConfigFileEntry.servicestring = rb_strdup("is a Network Service"); + /* RFC 1459 says 1 message per 2 seconds on average and bursts of * 5 messages are acceptable, so allow at least that. */ @@ -1468,6 +1478,12 @@ clear_out_old_conf(void) */ /* clean out general */ + rb_free(ConfigFileEntry.default_operstring); + ConfigFileEntry.default_operstring = NULL; + rb_free(ConfigFileEntry.default_adminstring); + ConfigFileEntry.default_adminstring = NULL; + rb_free(ConfigFileEntry.servicestring); + ConfigFileEntry.servicestring = NULL; rb_free(ConfigFileEntry.kline_reason); ConfigFileEntry.kline_reason = NULL;