]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Fix leak of LDAP server string on init
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 21 May 2018 16:41:32 +0000 (22:41 +0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 21 May 2018 16:41:32 +0000 (22:41 +0600)
src/modules/rlm_ldap/rlm_ldap.c

index 69d7b0b8a6d64a49531a6c5e77c05a42ec087f35..7f8094ba73dc1642ca6af0f47302e18b514522ee 100644 (file)
@@ -1596,6 +1596,12 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf)
        }
 #endif
 
+       /*
+        *      Initialise server with zero length string to
+        *      make code below simpler.
+        */
+       inst->handle_config.server = talloc_strdup(inst, "");
+
        /*
         *      Now iterate over all the 'server' config items
         */
@@ -1712,7 +1718,8 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf)
                                        cf_log_err(conf, "Failed recombining URL components");
                                        goto ldap_url_error;
                                }
-                               inst->handle_config.server = talloc_asprintf_append(inst->handle_config.server, "%s ", url);
+                               inst->handle_config.server = talloc_asprintf_append(inst->handle_config.server,
+                                                                                   "%s ", url);
                                free(url);
                        }
 #  else
@@ -1739,8 +1746,9 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf)
                        }
 
                        inst->handle_config.server = talloc_asprintf_append(inst->handle_config.server, "%s:%i ",
-                                                             ldap_url->lud_host ? ldap_url->lud_host : "localhost",
-                                                             ldap_url->lud_port);
+                                                                           ldap_url->lud_host ? ldap_url->lud_host :
+                                                                                                "localhost",
+                                                                           ldap_url->lud_port);
 #  endif
                        /*
                         *      @todo We could set a few other top level
@@ -1792,7 +1800,9 @@ static int mod_instantiate(void *instance, CONF_SECTION *conf)
                        }
                        if (port == 0) port = LDAP_PORT;
 
-                       inst->handle_config.server = talloc_asprintf_append(inst->handle_config.server, "ldap://%.*s:%i ", (int) len, value, port);
+                       inst->handle_config.server = talloc_asprintf_append(inst->handle_config.server,
+                                                                           "ldap://%.*s:%i ",
+                                                                           (int) len, value, port);
 #else
                        /*
                         *      ldap_init takes port, which can be overridden by :port so