[asterisk-commits] mjordan: branch 1.8 r382021 - /branches/1.8/addons/res_config_mysql.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Feb 25 06:48:56 CST 2013


Author: mjordan
Date: Mon Feb 25 06:48:52 2013
New Revision: 382021

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=382021
Log:
Clean up use of va_end/va_args in res_config_mysql

There were several problems using variadic argument macros in res_config_mysql.
 * Improper use of va_end. Multiple calls to va_end were possible resulting in
   an unbalanced matching of va_start/va_end.
 * Calls to va_arg after a possible encounter of a SENTINEL value.

This patch corrects those errors.

(closes issue ASTERISK-19451)
Reported by: wdoekes
patches:
  ASTERISK-19451-1.8--2.diff uploaded by wdoekes (License 5674)


Modified:
    branches/1.8/addons/res_config_mysql.c

Modified: branches/1.8/addons/res_config_mysql.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/addons/res_config_mysql.c?view=diff&rev=382021&r1=382020&r2=382021
==============================================================================
--- branches/1.8/addons/res_config_mysql.c (original)
+++ branches/1.8/addons/res_config_mysql.c Mon Feb 25 06:48:52 2013
@@ -343,9 +343,7 @@
 	}
 
 	/* Get the first parameter and first value in our list of passed paramater/value pairs */
-	newparam = va_arg(ap, const char *);
-	newval = va_arg(ap, const char *);
-	if (!newparam || !newval)  {
+	if (!(newparam = va_arg(ap, const char *)) || !(newval = va_arg(ap, const char *)))  {
 		ast_log(LOG_WARNING, "MySQL RealTime: Realtime retrieval requires at least 1 parameter and 1 value to search on.\n");
 		release_database(dbh);
 		return NULL;
@@ -376,7 +374,6 @@
 		ESCAPE_STRING(buf, newval);
 		ast_str_append(&sql, 0, " AND %s%s '%s'", newparam, op, ast_str_buffer(buf));
 	}
-	va_end(ap);
 
 	ast_debug(1, "MySQL RealTime: Retrieve SQL: %s\n", ast_str_buffer(sql));
 
@@ -457,9 +454,7 @@
 	}
 
 	/* Get the first parameter and first value in our list of passed paramater/value pairs */
-	newparam = va_arg(ap, const char *);
-	newval = va_arg(ap, const char *);
-	if (!newparam || !newval)  {
+	if (!(newparam = va_arg(ap, const char *)) || !(newval = va_arg(ap, const char *)))  {
 		ast_log(LOG_WARNING, "MySQL RealTime: Realtime retrieval requires at least 1 parameter and 1 value to search on.\n");
 		ast_config_destroy(cfg);
 		release_database(dbh);
@@ -498,8 +493,6 @@
 	if (initfield) {
 		ast_str_append(&sql, 0, " ORDER BY %s", initfield);
 	}
-
-	va_end(ap);
 
 	ast_debug(1, "MySQL RealTime: Retrieve SQL: %s\n", ast_str_buffer(sql));
 
@@ -581,9 +574,7 @@
 	}
 
 	/* Get the first parameter and first value in our list of passed paramater/value pairs */
-	newparam = va_arg(ap, const char *);
-	newval = va_arg(ap, const char *);
-	if (!newparam || !newval)  {
+	if (!(newparam = va_arg(ap, const char *)) || !(newval = va_arg(ap, const char *)))  {
 		ast_log(LOG_WARNING, "MySQL RealTime: Realtime update requires at least 1 parameter and 1 value to update.\n");
 		release_table(table);
 		release_database(dbh);
@@ -633,7 +624,6 @@
 			internal_require(database, tablename, newparam, RQ_CHAR, ast_str_strlen(buf), SENTINEL);
 		}
 	}
-	va_end(ap);
 
 	ESCAPE_STRING(buf, lookup);
 	ast_str_append(&sql, 0, " WHERE `%s` = '%s'", keyfield, ast_str_buffer(buf));
@@ -667,7 +657,7 @@
 {
 	struct mysql_conn *dbh;
 	my_ulonglong numrows;
-	int first = 1;
+	int first;
 	const char *newparam, *newval;
 	struct ast_str *sql = ast_str_thread_get(&sql_buf, 100), *buf = ast_str_thread_get(&scratch_buf, 100);
 	struct ast_str *where = ast_str_thread_get(&sql2_buf, 100);
@@ -706,6 +696,7 @@
 		return -1;
 	}
 
+	first = 1;
 	while ((newparam = va_arg(ap, const char *))) {
 		if (!(column = find_column(table, newparam))) {
 			ast_log(LOG_ERROR, "Updating on column '%s', but that column does not exist within the table '%s'!\n", newparam, tablename);
@@ -753,7 +744,7 @@
 			internal_require(database, tablename, newparam, RQ_CHAR, ast_str_strlen(buf), SENTINEL);
 		}
 	}
-	va_end(ap);
+
 	release_table(table);
 
 	ast_str_append(&sql, 0, " %s", ast_str_buffer(where));
@@ -802,9 +793,7 @@
 		return -1;
 	}
 	/* Get the first parameter and first value in our list of passed paramater/value pairs */
-	newparam = va_arg(ap, const char *);
-	newval = va_arg(ap, const char *);
-	if (!newparam || !newval)  {
+	if (!(newparam = va_arg(ap, const char *)) || !(newval = va_arg(ap, const char *))) {
 		ast_log(LOG_WARNING, "MySQL RealTime: Realtime storage requires at least 1 parameter and 1 value to search on.\n");
 		release_database(dbh);
 		return -1;
@@ -833,7 +822,6 @@
 			ast_str_append(&sql2, 0, ", '%s'", ast_str_buffer(buf));
 		}
 	}
-	va_end(ap);
 	ast_str_append(&sql, 0, "%s)", ast_str_buffer(sql2));
 	ast_debug(1,"MySQL RealTime: Insert SQL: %s\n", ast_str_buffer(sql));
 
@@ -901,7 +889,6 @@
 		ESCAPE_STRING(buf, newval);
 		ast_str_append(&sql, 0, " AND `%s` = '%s'", newparam, ast_str_buffer(buf));
 	}
-	va_end(ap);
 
 	ast_debug(1, "MySQL RealTime: Delete SQL: %s\n", ast_str_buffer(sql));
 




More information about the asterisk-commits mailing list