]> jfr.im git - solanum.git/commitdiff
s_conf: Don't leak strings when loading default conf
authorKeith Buck <redacted>
Mon, 3 Mar 2014 03:58:40 +0000 (03:58 +0000)
committerKeith Buck <redacted>
Mon, 3 Mar 2014 03:58:40 +0000 (03:58 +0000)
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

index 203e59f58acf86212885bac8bf8f69b0aa377bc0..e858dce887b01ee9cf5f8896672e38a995a0a79e 100644 (file)
@@ -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;