mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-13 08:13:22 +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/ ........ Merged revisions 396279 from http://svn.asterisk.org/svn/asterisk/branches/1.8 ........ Merged revisions 396287 from http://svn.asterisk.org/svn/asterisk/branches/11 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@396309 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -220,6 +220,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 */
|
||||
|
@@ -273,8 +273,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);
|
||||
|
@@ -282,11 +282,12 @@ 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);
|
||||
if ((var = ast_var_assign(args.var, S_OR(value, "")))) {
|
||||
AST_LIST_INSERT_HEAD(varshead, var, entries);
|
||||
|
||||
sprintf(shared_buffer, "SHARED(%s)", args.var);
|
||||
ast_channel_publish_varset(chan, shared_buffer, value);
|
||||
sprintf(shared_buffer, "SHARED(%s)", args.var);
|
||||
ast_channel_publish_varset(chan, shared_buffer, value);
|
||||
}
|
||||
|
||||
ast_channel_unlock(chan);
|
||||
|
||||
|
@@ -1698,6 +1698,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(ast_channel_varshead(chan), var, entries);
|
||||
|
||||
snprintf(expression, sizeof(expression), "${FIELDNUM(%s,%s,%s)}", var->name, test_args[i].delim, test_args[i].field);
|
||||
|
13
main/cdr.c
13
main/cdr.c
@@ -699,8 +699,8 @@ static int copy_variables(struct varshead *to_list, struct varshead *from_list)
|
||||
AST_LIST_TRAVERSE(from_list, 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(to_list, newvariable, entries);
|
||||
x++;
|
||||
}
|
||||
@@ -1033,8 +1033,7 @@ static void set_variable(struct varshead *headp, const char *name, const char *v
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1113,15 +1112,15 @@ static struct ast_cdr *cdr_object_create_public_records(struct cdr_object *cdr)
|
||||
copy_variables(&cdr_copy->varshead, &it_cdr->party_a.variables);
|
||||
AST_LIST_TRAVERSE(&it_cdr->party_b.variables, it_var, entries) {
|
||||
int found = 0;
|
||||
struct ast_var_t *newvariable;
|
||||
AST_LIST_TRAVERSE(&cdr_copy->varshead, it_copy_var, entries) {
|
||||
if (!strcmp(ast_var_name(it_var), ast_var_name(it_copy_var))) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
AST_LIST_INSERT_TAIL(&cdr_copy->varshead, ast_var_assign(ast_var_name(it_var),
|
||||
ast_var_value(it_var)), entries);
|
||||
if (!found && (newvariable = ast_var_assign(ast_var_name(it_var), ast_var_value(it_var)))) {
|
||||
AST_LIST_INSERT_TAIL(&cdr_copy->varshead, newvariable, entries);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -10911,10 +10911,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);
|
||||
}
|
||||
|
||||
@@ -10961,10 +10960,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);
|
||||
ast_channel_publish_varset(chan, name, value);
|
||||
|
||||
|
@@ -607,14 +607,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));
|
||||
dr[anscnt].weight = get_mapping_weight(map, &headp);
|
||||
while ((newvariable = AST_LIST_REMOVE_HEAD(&headp, entries)))
|
||||
|
@@ -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 */
|
||||
|
@@ -3164,10 +3164,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