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.
This commit is contained in:
Keith Buck 2014-03-03 03:58:40 +00:00
parent 9e26f0008b
commit 010c4fbdc5

View file

@ -673,8 +673,8 @@ set_default_conf(void)
/* ServerInfo.name is not rehashable */ /* ServerInfo.name is not rehashable */
/* ServerInfo.name = ServerInfo.name; */ /* ServerInfo.name = ServerInfo.name; */
ServerInfo.description = NULL; ServerInfo.description = NULL;
ServerInfo.network_name = rb_strdup(NETWORK_NAME_DEFAULT); ServerInfo.network_name = NULL;
ServerInfo.network_desc = rb_strdup(NETWORK_DESC_DEFAULT); ServerInfo.network_desc = NULL;
memset(&ServerInfo.ip, 0, sizeof(ServerInfo.ip)); memset(&ServerInfo.ip, 0, sizeof(ServerInfo.ip));
ServerInfo.specific_ipv4_vhost = 0; ServerInfo.specific_ipv4_vhost = 0;
@ -689,9 +689,9 @@ set_default_conf(void)
AdminInfo.email = NULL; AdminInfo.email = NULL;
AdminInfo.description = NULL; AdminInfo.description = NULL;
ConfigFileEntry.default_operstring = rb_strdup("is an IRC operator"); ConfigFileEntry.default_operstring = NULL;
ConfigFileEntry.default_adminstring = rb_strdup("is a Server Administrator"); ConfigFileEntry.default_adminstring = NULL;
ConfigFileEntry.servicestring = rb_strdup("is a Network Service"); ConfigFileEntry.servicestring = NULL;
ConfigFileEntry.default_umodes = UMODE_INVISIBLE; ConfigFileEntry.default_umodes = UMODE_INVISIBLE;
ConfigFileEntry.failed_oper_notice = YES; 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 /* RFC 1459 says 1 message per 2 seconds on average and bursts of
* 5 messages are acceptable, so allow at least that. * 5 messages are acceptable, so allow at least that.
*/ */
@ -1468,6 +1478,12 @@ clear_out_old_conf(void)
*/ */
/* clean out general */ /* 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); rb_free(ConfigFileEntry.kline_reason);
ConfigFileEntry.kline_reason = NULL; ConfigFileEntry.kline_reason = NULL;