[asterisk-commits] tilghman: trunk r123952 - /trunk/res/res_config_ldap.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jun 19 12:22:27 CDT 2008


Author: tilghman
Date: Thu Jun 19 12:22:27 2008
New Revision: 123952

URL: http://svn.digium.com/view/asterisk?view=rev&rev=123952
Log:
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)

Modified:
    trunk/res/res_config_ldap.c

Modified: trunk/res/res_config_ldap.c
URL: http://svn.digium.com/view/asterisk/trunk/res/res_config_ldap.c?view=diff&rev=123952&r1=123951&r2=123952
==============================================================================
--- trunk/res/res_config_ldap.c (original)
+++ trunk/res/res_config_ldap.c Thu Jun 19 12:22:27 2008
@@ -282,33 +282,36 @@
 
 		values = ldap_get_values_len(ldapConn, ldap_entry, ldap_attribute_name); /* these are freed at the end */
 		if (values) {
-			struct berval **v = values;
-
-			while (*v) {
+			struct berval **v;
+			char *valptr;
+
+			for (v = values; *v; 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 (!strncasecmp(value->bv_val, "{md5}", 5))
-						value->bv_val += 5;
-					else
-						value->bv_val = NULL;
-					ast_debug(2, "md5: %s\n", value->bv_val);
+					if (!strncasecmp(valptr, "{md5}", 5)) {
+						valptr += 5;
+					} else {
+						valptr = NULL;
+					}
+					ast_debug(2, "md5: %s\n", valptr);
 				}
-				if (value->bv_val) {
+				if (valptr) {
 					/* ok, so looping through all delimited values except the last one (not, last character is not delimited...) */
 					if (is_delimited) {
 						i = 0;
 						pos = 0;
-						while (!ast_strlen_zero(value->bv_val + i)) {
-							if (value->bv_val[i] == ';'){
-								value->bv_val[i] = '\0';
+						while (!ast_strlen_zero(valptr + i)) {
+							if (valptr[i] == ';'){
+								valptr[i] = '\0';
 								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) {
 										prev = prev->next;
 									}
 								} 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;
 							}
@@ -317,15 +320,14 @@
 					}
 					/* for the last delimited value or if the value is not delimited: */
 					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) {
 							prev = prev->next;
 						}
 					} 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);
 		}
@@ -400,23 +402,26 @@
 
 				values = ldap_get_values_len(ldapConn, ldap_entry, ldap_attribute_name);
 				if (values) {
-					struct berval **v = values;
-
-					while (*v) {
+					struct berval **v;
+					char *valptr;
+
+					for (v = values; *v; v++) {
 						value = *v;
+						valptr = value->bv_val;
 						if (is_realmed_password_attribute) {
-							if (strncasecmp(value->bv_val, "{md5}", 5) == 0)
-								value->bv_val += 5;
-							else
-								value->bv_val = NULL;
-							ast_debug(2, "md5: %s\n", value->bv_val);
+							if (strncasecmp(valptr, "{md5}", 5) == 0) {
+								valptr += 5;
+							} else {
+								valptr = NULL;
+							}
+							ast_debug(2, "md5: %s\n", valptr);
 						}
-						if (value->bv_val) {
+						if (valptr) {
 							if (delim_value == NULL 
 								&& !is_realmed_password_attribute 
 								&& (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) {
 									ast_debug(4, "LINE(%d) is delimited %d times: %s\n", __LINE__, delim_tot_count, delim_value);
@@ -426,11 +431,10 @@
 
 							if (is_delimited != 0 
 								&& !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) ) {
 								/* for non-Static RealTime, first */
 
-								i = pos;
-								while (!ast_strlen_zero(value->bv_val + i)) {
+								for (i = pos; !ast_strlen_zero(valptr + i); i++) {
 									ast_debug(4, "LINE(%d) DELIM pos: %d i: %d\n", __LINE__, pos, i);
 									if (delim_value[i] == ';') {
 										delim_value[i] = '\0';
@@ -451,9 +455,8 @@
 											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);
 									/* Last delimited value */
 									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 @@
 									/* Remembering to free memory */
 									is_delimited = 0;
 									pos = 0;
-									free(delim_value);
-									delim_value = NULL;
 								}
+								free(delim_value);
+								delim_value = NULL;
 								
 								ast_debug(4, "LINE(%d) DELIM pos: %d i: %d\n", __LINE__, pos, i);
 							} else {
@@ -479,20 +482,19 @@
 									free(delim_value);
 									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) {
-									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) {
 										prev = prev->next;
 									}
 								} 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++;
-					} /*!< while(*v) */
+					} /*!< for (v = values; *v; v++) */
 					ldap_value_free_len(values);
 				}/*!< if (values) */
 				ldap_attribute_name = ldap_next_attribute(ldapConn, ldap_entry, ber);
@@ -1459,10 +1461,11 @@
 					static_table_config = table_config;
 			}
 			for (; var; var = var->next) {
-				if (!strcasecmp(var->name, "additionalFilter"))
-					table_config->additional_filter = strdup(var->value);
-				else
+				if (!strcasecmp(var->name, "additionalFilter")) {
+					table_config->additional_filter = ast_strdup(var->value);
+				} else {
 					ldap_table_config_add_attribute(table_config, var->name, var->value);
+				}
 			}
 		}
 	}




More information about the asterisk-commits mailing list