[svn-commits] tilghman: branch 1.6.1 r251875 - /branches/1.6.1/funcs/func_odbc.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Mar 11 13:21:25 CST 2010


Author: tilghman
Date: Thu Mar 11 13:21:19 2010
New Revision: 251875

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=251875
Log:
Verify whether the created buffer was actually large enough to hold the expanded value.

For certain types of queries, where the size of the substituted query was much
larger than the template, it was possible for the substitution buffer to be too
small.  This is only an issue in 1.6.1 and 1.6.2, as previously we used a static
buffer anyway, and we have a substitution routine in trunk (1.8) that
automatically sizes itself appropriately to handle larger expansions.

(closes issue #17006)
 Reported by: viniciusfontes
 Patches: 
       20100311__issue17006.diff.txt uploaded by tilghman (license 14)
 Tested by: tilghman

Modified:
    branches/1.6.1/funcs/func_odbc.c

Modified: branches/1.6.1/funcs/func_odbc.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.6.1/funcs/func_odbc.c?view=diff&rev=251875&r1=251874&r2=251875
==============================================================================
--- branches/1.6.1/funcs/func_odbc.c (original)
+++ branches/1.6.1/funcs/func_odbc.c Thu Mar 11 13:21:19 2010
@@ -169,8 +169,6 @@
 	if (chan)
 		ast_autoservice_start(chan);
 
-	ast_str_make_space(&buf, strlen(query->sql_write) * 2);
-
 	/* Parse our arguments */
 	t = value ? ast_strdupa(value) : "";
 
@@ -201,7 +199,11 @@
 	/* Additionally set the value as a whole (but push an empty string if value is NULL) */
 	pbx_builtin_pushvar_helper(chan, "VALUE", value ? value : "");
 
-	pbx_substitute_variables_helper(chan, query->sql_write, buf->str, buf->len - 1);
+	do {
+		ast_str_make_space(&buf, 2 * (strlen(query->sql_write) > ast_str_size(buf) ? strlen(query->sql_write) : ast_str_size(buf)));
+		pbx_substitute_variables_helper(chan, query->sql_write, ast_str_buffer(buf), ast_str_size(buf) - 1);
+		ast_str_update(buf);
+	} while (ast_str_strlen(buf) > ast_str_size(buf) - 5);
 
 	/* Restore prior values */
 	for (i = 0; i < args.argc; i++) {
@@ -308,8 +310,11 @@
 		pbx_builtin_pushvar_helper(chan, varname, args.field[x]);
 	}
 
-	ast_str_make_space(&sql, strlen(query->sql_read) * 2);
-	pbx_substitute_variables_helper(chan, query->sql_read, sql->str, sql->len - 1);
+	do {
+		ast_str_make_space(&sql, 2 * (strlen(query->sql_read) > ast_str_size(sql) ? strlen(query->sql_read) : ast_str_size(sql)));
+		pbx_substitute_variables_helper(chan, query->sql_read, ast_str_buffer(sql), ast_str_size(sql) - 1);
+		ast_str_update(sql);
+	} while (ast_str_strlen(sql) > ast_str_size(sql) - 5);
 
 	/* Restore prior values */
 	for (x = 0; x < args.argc; x++) {




More information about the svn-commits mailing list