Don't change pointers that need to be later passed back for deallocation.

(closes issue #12572)
 Reported by: flyn
 Patches: 
       20080613__bug12572.diff.txt uploaded by Corydon76 (license 14)


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@123952 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Tilghman Lesher
2008-06-19 17:22:27 +00:00
parent 56654fc0f2
commit 5791b6680d

View File

@@ -282,33 +282,36 @@ static struct ast_variable *realtime_ldap_entry_to_var(struct ldap_table_config
values = ldap_get_values_len(ldapConn, ldap_entry, ldap_attribute_name); /* these are freed at the end */ values = ldap_get_values_len(ldapConn, ldap_entry, ldap_attribute_name); /* these are freed at the end */
if (values) { if (values) {
struct berval **v = values; struct berval **v;
char *valptr;
while (*v) { for (v = values; *v; v++) {
value = *v; value = *v;
ast_debug(2, "LINE(%d) attribute_name: %s LDAP value: %s\n", __LINE__, attribute_name, value->bv_val); valptr = value->bv_val;
ast_debug(2, "LINE(%d) attribute_name: %s LDAP value: %s\n", __LINE__, attribute_name, valptr);
if (is_realmed_password_attribute) { if (is_realmed_password_attribute) {
if (!strncasecmp(value->bv_val, "{md5}", 5)) if (!strncasecmp(valptr, "{md5}", 5)) {
value->bv_val += 5; valptr += 5;
else } else {
value->bv_val = NULL; valptr = NULL;
ast_debug(2, "md5: %s\n", value->bv_val);
} }
if (value->bv_val) { ast_debug(2, "md5: %s\n", valptr);
}
if (valptr) {
/* ok, so looping through all delimited values except the last one (not, last character is not delimited...) */ /* ok, so looping through all delimited values except the last one (not, last character is not delimited...) */
if (is_delimited) { if (is_delimited) {
i = 0; i = 0;
pos = 0; pos = 0;
while (!ast_strlen_zero(value->bv_val + i)) { while (!ast_strlen_zero(valptr + i)) {
if (value->bv_val[i] == ';'){ if (valptr[i] == ';'){
value->bv_val[i] = '\0'; valptr[i] = '\0';
if (prev) { if (prev) {
prev->next = ast_variable_new(attribute_name, &value->bv_val[pos], table_config->table_name); prev->next = ast_variable_new(attribute_name, &valptr[pos], table_config->table_name);
if (prev->next) { if (prev->next) {
prev = prev->next; prev = prev->next;
} }
} else { } else {
prev = var = ast_variable_new(attribute_name, &value->bv_val[pos], table_config->table_name); prev = var = ast_variable_new(attribute_name, &valptr[pos], table_config->table_name);
} }
pos = i + 1; pos = i + 1;
} }
@@ -317,15 +320,14 @@ static struct ast_variable *realtime_ldap_entry_to_var(struct ldap_table_config
} }
/* for the last delimited value or if the value is not delimited: */ /* for the last delimited value or if the value is not delimited: */
if (prev) { if (prev) {
prev->next = ast_variable_new(attribute_name, &value->bv_val[pos], table_config->table_name); prev->next = ast_variable_new(attribute_name, &valptr[pos], table_config->table_name);
if (prev->next) { if (prev->next) {
prev = prev->next; prev = prev->next;
} }
} else { } else {
prev = var = ast_variable_new(attribute_name, &value->bv_val[pos], table_config->table_name); prev = var = ast_variable_new(attribute_name, &valptr[pos], table_config->table_name);
} }
} }
v++;
} }
ldap_value_free_len(values); ldap_value_free_len(values);
} }
@@ -400,23 +402,26 @@ static struct ast_variable **realtime_ldap_result_to_vars(struct ldap_table_conf
values = ldap_get_values_len(ldapConn, ldap_entry, ldap_attribute_name); values = ldap_get_values_len(ldapConn, ldap_entry, ldap_attribute_name);
if (values) { if (values) {
struct berval **v = values; struct berval **v;
char *valptr;
while (*v) { for (v = values; *v; v++) {
value = *v; value = *v;
valptr = value->bv_val;
if (is_realmed_password_attribute) { if (is_realmed_password_attribute) {
if (strncasecmp(value->bv_val, "{md5}", 5) == 0) if (strncasecmp(valptr, "{md5}", 5) == 0) {
value->bv_val += 5; valptr += 5;
else } else {
value->bv_val = NULL; valptr = NULL;
ast_debug(2, "md5: %s\n", value->bv_val);
} }
if (value->bv_val) { ast_debug(2, "md5: %s\n", valptr);
}
if (valptr) {
if (delim_value == NULL if (delim_value == NULL
&& !is_realmed_password_attribute && !is_realmed_password_attribute
&& (static_table_config != table_config || strcmp(attribute_name, "variable_value") == 0)) { && (static_table_config != table_config || strcmp(attribute_name, "variable_value") == 0)) {
delim_value = ast_strdup(value->bv_val); delim_value = ast_strdup(valptr);
if ((delim_tot_count = semicolon_count_str(delim_value)) > 0) { if ((delim_tot_count = semicolon_count_str(delim_value)) > 0) {
ast_debug(4, "LINE(%d) is delimited %d times: %s\n", __LINE__, delim_tot_count, delim_value); ast_debug(4, "LINE(%d) is delimited %d times: %s\n", __LINE__, delim_tot_count, delim_value);
@@ -429,8 +434,7 @@ static struct ast_variable **realtime_ldap_result_to_vars(struct ldap_table_conf
&& (static_table_config != table_config || strcmp(attribute_name, "variable_value") == 0) ) { && (static_table_config != table_config || strcmp(attribute_name, "variable_value") == 0) ) {
/* for non-Static RealTime, first */ /* for non-Static RealTime, first */
i = pos; for (i = pos; !ast_strlen_zero(valptr + i); i++) {
while (!ast_strlen_zero(value->bv_val + i)) {
ast_debug(4, "LINE(%d) DELIM pos: %d i: %d\n", __LINE__, pos, i); ast_debug(4, "LINE(%d) DELIM pos: %d i: %d\n", __LINE__, pos, i);
if (delim_value[i] == ';') { if (delim_value[i] == ';') {
delim_value[i] = '\0'; delim_value[i] = '\0';
@@ -451,9 +455,8 @@ static struct ast_variable **realtime_ldap_result_to_vars(struct ldap_table_conf
break; break;
} }
} }
i++;
} }
if (ast_strlen_zero(value->bv_val + i)) { if (ast_strlen_zero(valptr + i)) {
ast_debug(4, "LINE(%d) DELIM pos: %d i: %d delim_count: %d\n", __LINE__, pos, i, delim_count); ast_debug(4, "LINE(%d) DELIM pos: %d i: %d delim_count: %d\n", __LINE__, pos, i, delim_count);
/* Last delimited value */ /* Last delimited value */
ast_debug(4, "LINE(%d) DELIM - attribute_name: %s value: %s pos: %d\n", __LINE__, attribute_name, &delim_value[pos], pos); ast_debug(4, "LINE(%d) DELIM - attribute_name: %s value: %s pos: %d\n", __LINE__, attribute_name, &delim_value[pos], pos);
@@ -468,9 +471,9 @@ static struct ast_variable **realtime_ldap_result_to_vars(struct ldap_table_conf
/* Remembering to free memory */ /* Remembering to free memory */
is_delimited = 0; is_delimited = 0;
pos = 0; pos = 0;
}
free(delim_value); free(delim_value);
delim_value = NULL; delim_value = NULL;
}
ast_debug(4, "LINE(%d) DELIM pos: %d i: %d\n", __LINE__, pos, i); ast_debug(4, "LINE(%d) DELIM pos: %d i: %d\n", __LINE__, pos, i);
} else { } else {
@@ -479,20 +482,19 @@ static struct ast_variable **realtime_ldap_result_to_vars(struct ldap_table_conf
free(delim_value); free(delim_value);
delim_value = NULL; delim_value = NULL;
} }
ast_debug(2, "LINE(%d) attribute_name: %s value: %s\n", __LINE__, attribute_name, value->bv_val); ast_debug(2, "LINE(%d) attribute_name: %s value: %s\n", __LINE__, attribute_name, valptr);
if (prev) { if (prev) {
prev->next = ast_variable_new(attribute_name, value->bv_val, table_config->table_name); prev->next = ast_variable_new(attribute_name, valptr, table_config->table_name);
if (prev->next) { if (prev->next) {
prev = prev->next; prev = prev->next;
} }
} else { } else {
prev = var = ast_variable_new(attribute_name, value->bv_val, table_config->table_name); prev = var = ast_variable_new(attribute_name, valptr, table_config->table_name);
} }
} }
} }
v++; } /*!< for (v = values; *v; v++) */
} /*!< while(*v) */
ldap_value_free_len(values); ldap_value_free_len(values);
}/*!< if (values) */ }/*!< if (values) */
ldap_attribute_name = ldap_next_attribute(ldapConn, ldap_entry, ber); ldap_attribute_name = ldap_next_attribute(ldapConn, ldap_entry, ber);
@@ -1459,13 +1461,14 @@ int parse_config(void)
static_table_config = table_config; static_table_config = table_config;
} }
for (; var; var = var->next) { for (; var; var = var->next) {
if (!strcasecmp(var->name, "additionalFilter")) if (!strcasecmp(var->name, "additionalFilter")) {
table_config->additional_filter = strdup(var->value); table_config->additional_filter = ast_strdup(var->value);
else } else {
ldap_table_config_add_attribute(table_config, var->name, var->value); ldap_table_config_add_attribute(table_config, var->name, var->value);
} }
} }
} }
}
ast_config_destroy(config); ast_config_destroy(config);