[asterisk-commits] wdoekes: branch 1.8 r396279 - in /branches/1.8: apps/ funcs/ main/ pbx/ utils/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Aug 6 03:15:11 CDT 2013


Author: wdoekes
Date: Tue Aug  6 03:14:59 2013
New Revision: 396279

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=396279
Log:
Check result of ast_var_assign() calls for memory allocation failure.

We try to keep the system running even when all available memory is
spent.

Review: https://reviewboard.asterisk.org/r/2734/

Modified:
    branches/1.8/apps/app_playback.c
    branches/1.8/apps/app_stack.c
    branches/1.8/funcs/func_global.c
    branches/1.8/funcs/func_strings.c
    branches/1.8/main/cdr.c
    branches/1.8/main/pbx.c
    branches/1.8/pbx/pbx_dundi.c
    branches/1.8/pbx/pbx_loopback.c
    branches/1.8/utils/extconf.c

Modified: branches/1.8/apps/app_playback.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/apps/app_playback.c?view=diff&rev=396279&r1=396278&r2=396279
==============================================================================
--- branches/1.8/apps/app_playback.c (original)
+++ branches/1.8/apps/app_playback.c Tue Aug  6 03:14:59 2013
@@ -211,6 +211,10 @@
 		s = x + 1;
 	ast_debug(2, "value is <%s>\n", s);
 	n = ast_var_assign("SAY", s);
+	if (!n) {
+		ast_log(LOG_ERROR, "Memory allocation error in do_say\n");
+		return -1;
+	}
 	AST_LIST_INSERT_HEAD(&head, n, entries);
 
 	/* scan the body, one piece at a time */

Modified: branches/1.8/apps/app_stack.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/apps/app_stack.c?view=diff&rev=396279&r1=396278&r2=396279
==============================================================================
--- branches/1.8/apps/app_stack.c (original)
+++ branches/1.8/apps/app_stack.c Tue Aug  6 03:14:59 2013
@@ -242,8 +242,9 @@
 	}
 
 	if (!found) {
-		variables = ast_var_assign(var, "");
-		AST_LIST_INSERT_HEAD(&frame->varshead, variables, entries);
+		if ((variables = ast_var_assign(var, ""))) {
+			AST_LIST_INSERT_HEAD(&frame->varshead, variables, entries);
+		}
 		pbx_builtin_pushvar_helper(chan, var, value);
 	} else {
 		pbx_builtin_setvar_helper(chan, var, value);

Modified: branches/1.8/funcs/func_global.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/funcs/func_global.c?view=diff&rev=396279&r1=396278&r2=396279
==============================================================================
--- branches/1.8/funcs/func_global.c (original)
+++ branches/1.8/funcs/func_global.c Tue Aug  6 03:14:59 2013
@@ -253,15 +253,16 @@
 	}
 	AST_LIST_TRAVERSE_SAFE_END;
 
-	var = ast_var_assign(args.var, S_OR(value, ""));
-	AST_LIST_INSERT_HEAD(varshead, var, entries);
-	manager_event(EVENT_FLAG_DIALPLAN, "VarSet", 
-		"Channel: %s\r\n"
-		"Variable: SHARED(%s)\r\n"
-		"Value: %s\r\n"
-		"Uniqueid: %s\r\n", 
-		chan ? chan->name : "none", args.var, value, 
-		chan ? chan->uniqueid : "none");
+	if ((var = ast_var_assign(args.var, S_OR(value, "")))) {
+		AST_LIST_INSERT_HEAD(varshead, var, entries);
+		manager_event(EVENT_FLAG_DIALPLAN, "VarSet", 
+			"Channel: %s\r\n"
+			"Variable: SHARED(%s)\r\n"
+			"Value: %s\r\n"
+			"Uniqueid: %s\r\n", 
+			chan ? chan->name : "none", args.var, value, 
+			chan ? chan->uniqueid : "none");
+	}
 
 	ast_channel_unlock(chan);
 

Modified: branches/1.8/funcs/func_strings.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/funcs/func_strings.c?view=diff&rev=396279&r1=396278&r2=396279
==============================================================================
--- branches/1.8/funcs/func_strings.c (original)
+++ branches/1.8/funcs/func_strings.c Tue Aug  6 03:14:59 2013
@@ -1591,6 +1591,12 @@
 
 	for (i = 0; i < ARRAY_LEN(test_args); i++) {
 		struct ast_var_t *var = ast_var_assign("FIELDS", test_args[i].fields);
+		if (!var) {
+			ast_test_status_update(test, "Out of memory\n");
+			res = AST_TEST_FAIL;
+			break;
+		}
+
 		AST_LIST_INSERT_HEAD(&chan->varshead, var, entries);
 
 		snprintf(expression, sizeof(expression), "${FIELDNUM(%s,%s,%s)}", var->name, test_args[i].delim, test_args[i].field);

Modified: branches/1.8/main/cdr.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/main/cdr.c?view=diff&rev=396279&r1=396278&r2=396279
==============================================================================
--- branches/1.8/main/cdr.c (original)
+++ branches/1.8/main/cdr.c Tue Aug  6 03:14:59 2013
@@ -372,8 +372,7 @@
 		}
 		AST_LIST_TRAVERSE_SAFE_END;
 
-		if (value) {
-			newvariable = ast_var_assign(name, value);
+		if (value && (newvariable = ast_var_assign(name, value))) {
 			AST_LIST_INSERT_HEAD(headp, newvariable, entries);
 		}
 	}
@@ -397,8 +396,8 @@
 	AST_LIST_TRAVERSE(headpa,variables,entries) {
 		if (variables &&
 		    (var = ast_var_name(variables)) && (val = ast_var_value(variables)) &&
-		    !ast_strlen_zero(var) && !ast_strlen_zero(val)) {
-			newvariable = ast_var_assign(var, val);
+		    !ast_strlen_zero(var) && !ast_strlen_zero(val) &&
+		    (newvariable = ast_var_assign(var, val))) {
 			AST_LIST_INSERT_HEAD(headpb, newvariable, entries);
 			x++;
 		}

Modified: branches/1.8/main/pbx.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/main/pbx.c?view=diff&rev=396279&r1=396278&r2=396279
==============================================================================
--- branches/1.8/main/pbx.c (original)
+++ branches/1.8/main/pbx.c Tue Aug  6 03:14:59 2013
@@ -10205,10 +10205,9 @@
 		headp = &globals;
 	}
 
-	if (value) {
+	if (value && (newvariable = ast_var_assign(name, value))) {
 		if (headp == &globals)
 			ast_verb(2, "Setting global variable '%s' to '%s'\n", name, value);
-		newvariable = ast_var_assign(name, value);
 		AST_LIST_INSERT_HEAD(headp, newvariable, entries);
 	}
 
@@ -10255,10 +10254,9 @@
 	}
 	AST_LIST_TRAVERSE_SAFE_END;
 
-	if (value) {
+	if (value && (newvariable = ast_var_assign(name, value))) {
 		if (headp == &globals)
 			ast_verb(2, "Setting global variable '%s' to '%s'\n", name, value);
-		newvariable = ast_var_assign(name, value);
 		AST_LIST_INSERT_HEAD(headp, newvariable, entries);
 		manager_event(EVENT_FLAG_DIALPLAN, "VarSet",
 			"Channel: %s\r\n"

Modified: branches/1.8/pbx/pbx_dundi.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/pbx/pbx_dundi.c?view=diff&rev=396279&r1=396278&r2=396279
==============================================================================
--- branches/1.8/pbx/pbx_dundi.c (original)
+++ branches/1.8/pbx/pbx_dundi.c Tue Aug  6 03:14:59 2013
@@ -594,14 +594,18 @@
 			ast_eid_to_str(dr[anscnt].eid_str, sizeof(dr[anscnt].eid_str), &dr[anscnt].eid);
 			if (ast_test_flag(&flags, DUNDI_FLAG_EXISTS)) {
 				AST_LIST_HEAD_INIT_NOLOCK(&headp);
-				newvariable = ast_var_assign("NUMBER", called_number);
-				AST_LIST_INSERT_HEAD(&headp, newvariable, entries);
-				newvariable = ast_var_assign("EID", dr[anscnt].eid_str);
-				AST_LIST_INSERT_HEAD(&headp, newvariable, entries);
-				newvariable = ast_var_assign("SECRET", cursecret);
-				AST_LIST_INSERT_HEAD(&headp, newvariable, entries);
-				newvariable = ast_var_assign("IPADDR", ipaddr);
-				AST_LIST_INSERT_HEAD(&headp, newvariable, entries);
+				if ((newvariable = ast_var_assign("NUMBER", called_number))) {
+					AST_LIST_INSERT_HEAD(&headp, newvariable, entries);
+				}
+				if ((newvariable = ast_var_assign("EID", dr[anscnt].eid_str))) {
+					AST_LIST_INSERT_HEAD(&headp, newvariable, entries);
+				}
+				if ((newvariable = ast_var_assign("SECRET", cursecret))) {
+					AST_LIST_INSERT_HEAD(&headp, newvariable, entries);
+				}
+				if ((newvariable = ast_var_assign("IPADDR", ipaddr))) {
+					AST_LIST_INSERT_HEAD(&headp, newvariable, entries);
+				}
 				pbx_substitute_variables_varshead(&headp, map->dest, dr[anscnt].dest, sizeof(dr[anscnt].dest));
 				while ((newvariable = AST_LIST_REMOVE_HEAD(&headp, entries)))
 					ast_var_delete(newvariable);

Modified: branches/1.8/pbx/pbx_loopback.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/pbx/pbx_loopback.c?view=diff&rev=396279&r1=396278&r2=396279
==============================================================================
--- branches/1.8/pbx/pbx_loopback.c (original)
+++ branches/1.8/pbx/pbx_loopback.c Tue Aug  6 03:14:59 2013
@@ -91,12 +91,15 @@
 
 	snprintf(tmp, sizeof(tmp), "%d", priority);
 	AST_LIST_HEAD_INIT_NOLOCK(&headp);
-	newvariable = ast_var_assign("EXTEN", exten);
-	AST_LIST_INSERT_HEAD(&headp, newvariable, entries);
-	newvariable = ast_var_assign("CONTEXT", context);
-	AST_LIST_INSERT_HEAD(&headp, newvariable, entries);
-	newvariable = ast_var_assign("PRIORITY", tmp);
-	AST_LIST_INSERT_HEAD(&headp, newvariable, entries);
+	if ((newvariable = ast_var_assign("EXTEN", exten))) {
+		AST_LIST_INSERT_HEAD(&headp, newvariable, entries);
+	}
+	if ((newvariable = ast_var_assign("CONTEXT", context))) {
+		AST_LIST_INSERT_HEAD(&headp, newvariable, entries);
+	}
+	if ((newvariable = ast_var_assign("PRIORITY", tmp))) {
+		AST_LIST_INSERT_HEAD(&headp, newvariable, entries);
+	}
 	/* Substitute variables */
 	pbx_substitute_variables_varshead(&headp, data, buf, buflen);
 	/* free the list */

Modified: branches/1.8/utils/extconf.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/utils/extconf.c?view=diff&rev=396279&r1=396278&r2=396279
==============================================================================
--- branches/1.8/utils/extconf.c (original)
+++ branches/1.8/utils/extconf.c Tue Aug  6 03:14:59 2013
@@ -3149,10 +3149,9 @@
 		}
 	}
 
-	if (value) {
+	if (value && (newvariable = ast_var_assign(name, value))) {
 		if ((option_verbose > 1) && (headp == &globals))
 			ast_verbose(VERBOSE_PREFIX_2 "Setting global variable '%s' to '%s'\n", name, value);
-		newvariable = ast_var_assign(name, value);
 		AST_LIST_INSERT_HEAD(headp, newvariable, entries);
 	}
 




More information about the asterisk-commits mailing list