From: Arran Cudbard-Bell Date: Mon, 21 May 2018 16:41:32 +0000 (+0600) Subject: Fix leak of LDAP server string on init X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ced064fd6273fd0ff68deaf39baf7e0b84a70848;p=thirdparty%2Ffreeradius-server.git Fix leak of LDAP server string on init --- diff --git a/src/modules/rlm_ldap/rlm_ldap.c b/src/modules/rlm_ldap/rlm_ldap.c index 69d7b0b8a6d..7f8094ba73d 100644 --- a/src/modules/rlm_ldap/rlm_ldap.c +++ b/src/modules/rlm_ldap/rlm_ldap.c @@ -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