mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-16 14:58:25 +00:00
Use LDAP memory management functions instead of Asterisk's
When MALLOC_DEBUG is enabled with res_config_ldap, issues (munmap_chunk: invalid pointer errors) can occur as the memory is being allocated with Asterisk's wrappers around malloc/calloc/free/strdup, as opposed to the LDAP library's wrappers. This patch uses the LDAP library's wrappers where appropriate, so that compiling with MALLOC_DEBUG doesn't cause more problems than it solves. Note that the patch listed below was modified slightly for this commit to account for some additional memory allocation/deallocations. (closes issue ASTERISK-17386) Reported by: John Covert Tested by: Andrew Latham patches: issue18789-1.8-r316873.patch uploaded by seanbright (License 5060) ........ Merged revisions 385190 from http://svn.asterisk.org/svn/asterisk/branches/1.8 git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/11@385199 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -1236,14 +1236,14 @@ static int update_ldap(const char *basedn, const char *table_name, const char *a
|
|||||||
}
|
}
|
||||||
|
|
||||||
mods_size = 2; /* one for the first param/value pair and one for the the terminating NULL */
|
mods_size = 2; /* one for the first param/value pair and one for the the terminating NULL */
|
||||||
ldap_mods = ast_calloc(sizeof(LDAPMod *), mods_size);
|
ldap_mods = ldap_memcalloc(sizeof(LDAPMod *), mods_size);
|
||||||
ldap_mods[0] = ast_calloc(1, sizeof(LDAPMod));
|
ldap_mods[0] = ldap_memcalloc(1, sizeof(LDAPMod));
|
||||||
|
|
||||||
ldap_mods[0]->mod_op = LDAP_MOD_REPLACE;
|
ldap_mods[0]->mod_op = LDAP_MOD_REPLACE;
|
||||||
ldap_mods[0]->mod_type = ast_strdup(newparam);
|
ldap_mods[0]->mod_type = ldap_strdup(newparam);
|
||||||
|
|
||||||
ldap_mods[0]->mod_values = ast_calloc(sizeof(char *), 2);
|
ldap_mods[0]->mod_values = ast_calloc(sizeof(char *), 2);
|
||||||
ldap_mods[0]->mod_values[0] = ast_strdup(newval);
|
ldap_mods[0]->mod_values[0] = ldap_strdup(newval);
|
||||||
|
|
||||||
while ((newparam = va_arg(ap, const char *))) {
|
while ((newparam = va_arg(ap, const char *))) {
|
||||||
newparam = convert_attribute_name_to_ldap(table_config, newparam);
|
newparam = convert_attribute_name_to_ldap(table_config, newparam);
|
||||||
@@ -1253,7 +1253,7 @@ static int update_ldap(const char *basedn, const char *table_name, const char *a
|
|||||||
for (i = 0; i < mods_size - 1; i++) {
|
for (i = 0; i < mods_size - 1; i++) {
|
||||||
if (ldap_mods[i]&& !strcmp(ldap_mods[i]->mod_type, newparam)) {
|
if (ldap_mods[i]&& !strcmp(ldap_mods[i]->mod_type, newparam)) {
|
||||||
/* We have the parameter allready, adding the value as a semicolon delimited value */
|
/* We have the parameter allready, adding the value as a semicolon delimited value */
|
||||||
ldap_mods[i]->mod_values[0] = ast_realloc(ldap_mods[i]->mod_values[0], sizeof(char) * (strlen(ldap_mods[i]->mod_values[0]) + strlen(newval) + 2));
|
ldap_mods[i]->mod_values[0] = ldap_memrealloc(ldap_mods[i]->mod_values[0], sizeof(char) * (strlen(ldap_mods[i]->mod_values[0]) + strlen(newval) + 2));
|
||||||
strcat(ldap_mods[i]->mod_values[0], ";");
|
strcat(ldap_mods[i]->mod_values[0], ";");
|
||||||
strcat(ldap_mods[i]->mod_values[0], newval);
|
strcat(ldap_mods[i]->mod_values[0], newval);
|
||||||
mod_exists = 1;
|
mod_exists = 1;
|
||||||
@@ -1264,12 +1264,12 @@ static int update_ldap(const char *basedn, const char *table_name, const char *a
|
|||||||
/* create new mod */
|
/* create new mod */
|
||||||
if (!mod_exists) {
|
if (!mod_exists) {
|
||||||
mods_size++;
|
mods_size++;
|
||||||
ldap_mods = ast_realloc(ldap_mods, sizeof(LDAPMod *) * mods_size);
|
ldap_mods = ldap_memrealloc(ldap_mods, sizeof(LDAPMod *) * mods_size);
|
||||||
ldap_mods[mods_size - 1] = NULL;
|
ldap_mods[mods_size - 1] = NULL;
|
||||||
|
|
||||||
ldap_mods[mods_size - 2] = ast_calloc(1, sizeof(LDAPMod));
|
ldap_mods[mods_size - 2] = ldap_memcalloc(1, sizeof(LDAPMod));
|
||||||
|
|
||||||
ldap_mods[mods_size - 2]->mod_type = ast_calloc(sizeof(char), strlen(newparam) + 1);
|
ldap_mods[mods_size - 2]->mod_type = ldap_memcalloc(sizeof(char), strlen(newparam) + 1);
|
||||||
strcpy(ldap_mods[mods_size - 2]->mod_type, newparam);
|
strcpy(ldap_mods[mods_size - 2]->mod_type, newparam);
|
||||||
|
|
||||||
if (strlen(newval) == 0) {
|
if (strlen(newval) == 0) {
|
||||||
@@ -1277,8 +1277,8 @@ static int update_ldap(const char *basedn, const char *table_name, const char *a
|
|||||||
} else {
|
} else {
|
||||||
ldap_mods[mods_size - 2]->mod_op = LDAP_MOD_REPLACE;
|
ldap_mods[mods_size - 2]->mod_op = LDAP_MOD_REPLACE;
|
||||||
|
|
||||||
ldap_mods[mods_size - 2]->mod_values = ast_calloc(sizeof(char *), 2);
|
ldap_mods[mods_size - 2]->mod_values = ldap_memcalloc(sizeof(char *), 2);
|
||||||
ldap_mods[mods_size - 2]->mod_values[0] = ast_calloc(sizeof(char), strlen(newval) + 1);
|
ldap_mods[mods_size - 2]->mod_values[0] = ldap_memcalloc(sizeof(char), strlen(newval) + 1);
|
||||||
strcpy(ldap_mods[mods_size - 2]->mod_values[0], newval);
|
strcpy(ldap_mods[mods_size - 2]->mod_values[0], newval);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user