mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-09 11:28:25 +00:00
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/ git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8@396279 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -211,6 +211,10 @@ static int do_say(say_args_t *a, const char *s, const char *options, int depth)
|
||||
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 */
|
||||
|
||||
@@ -242,8 +242,9 @@ static int frame_set_var(struct ast_channel *chan, struct gosub_stack_frame *fra
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
@@ -253,15 +253,16 @@ static int shared_write(struct ast_channel *chan, const char *cmd, char *data, c
|
||||
}
|
||||
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);
|
||||
|
||||
|
||||
@@ -1591,6 +1591,12 @@ AST_TEST_DEFINE(test_FIELDNUM)
|
||||
|
||||
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);
|
||||
|
||||
@@ -372,8 +372,7 @@ int ast_cdr_setvar(struct ast_cdr *cdr, const char *name, const char *value, int
|
||||
}
|
||||
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 @@ int ast_cdr_copy_vars(struct ast_cdr *to_cdr, struct ast_cdr *from_cdr)
|
||||
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++;
|
||||
}
|
||||
|
||||
@@ -10205,10 +10205,9 @@ void pbx_builtin_pushvar_helper(struct ast_channel *chan, const char *name, cons
|
||||
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 @@ int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const
|
||||
}
|
||||
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"
|
||||
|
||||
@@ -594,14 +594,18 @@ static int dundi_lookup_local(struct dundi_result *dr, struct dundi_mapping *map
|
||||
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);
|
||||
|
||||
@@ -91,12 +91,15 @@ static char *loopback_subst(char *buf, int buflen, const char *exten, const char
|
||||
|
||||
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 */
|
||||
|
||||
@@ -3149,10 +3149,9 @@ static void pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user