mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-16 09:46:22 +00:00
Clean up and ensure proper usage of alloca()
This replaces all calls to alloca() with ast_alloca() which calls gcc's __builtin_alloca() to avoid BSD semantics and removes all NULL checks on memory allocated via ast_alloca() and ast_strdupa(). (closes issue ASTERISK-20125) Review: https://reviewboard.asterisk.org/r/2032/ Patch-by: Walter Doekes (wdoekes) ........ Merged revisions 370642 from http://svn.asterisk.org/svn/asterisk/branches/1.8 ........ Merged revisions 370643 from http://svn.asterisk.org/svn/asterisk/branches/10 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@370655 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -150,7 +150,7 @@ static int dictate_exec(struct ast_channel *chan, const char *data)
|
||||
ast_mkdir(base, 0755);
|
||||
len = strlen(base) + strlen(filein) + 2;
|
||||
if (!path || len > maxlen) {
|
||||
path = alloca(len);
|
||||
path = ast_alloca(len);
|
||||
memset(path, 0, len);
|
||||
maxlen = len;
|
||||
} else {
|
||||
|
@@ -158,7 +158,7 @@ static struct ast_channel *my_ast_get_channel_by_name_locked(const char *channam
|
||||
* debugging.
|
||||
*/
|
||||
pickup_args.len = strlen(channame) + 1;
|
||||
chkchan = alloca(pickup_args.len + 1);
|
||||
chkchan = ast_alloca(pickup_args.len + 1);
|
||||
strcpy(chkchan, channame);
|
||||
strcat(chkchan, "-");
|
||||
pickup_args.name = chkchan;
|
||||
|
@@ -344,12 +344,12 @@ static int festival_exec(struct ast_channel *chan, const char *vdata)
|
||||
const char *endcmd = "\" 'file)(quit)\n";
|
||||
|
||||
strln = strlen(startcmd) + strlen(args.text) + strlen(endcmd) + 1;
|
||||
newfestivalcommand = alloca(strln);
|
||||
newfestivalcommand = ast_alloca(strln);
|
||||
snprintf(newfestivalcommand, strln, "%s%s%s", startcmd, args.text, endcmd);
|
||||
festivalcommand = newfestivalcommand;
|
||||
} else { /* This else parses the festivalcommand that we're sent from the config file for \n's, etc */
|
||||
int x, j;
|
||||
newfestivalcommand = alloca(strlen(festivalcommand) + strlen(args.text) + 1);
|
||||
newfestivalcommand = ast_alloca(strlen(festivalcommand) + strlen(args.text) + 1);
|
||||
|
||||
for (x = 0, j = 0; x < strlen(festivalcommand); x++) {
|
||||
if (festivalcommand[x] == '\\' && festivalcommand[x + 1] == 'n') {
|
||||
|
@@ -76,7 +76,7 @@ static int cpeid_exec(struct ast_channel *chan, const char *idata)
|
||||
unsigned int x;
|
||||
|
||||
for (x = 0; x < 4; x++)
|
||||
data[x] = alloca(80);
|
||||
data[x] = ast_alloca(80);
|
||||
|
||||
strcpy(data[0], "** CPE Info **");
|
||||
strcpy(data[1], "Identifying CPE...");
|
||||
|
@@ -595,8 +595,7 @@ static int macroif_exec(struct ast_channel *chan, const char *data)
|
||||
char *expr = NULL, *label_a = NULL, *label_b = NULL;
|
||||
int res = 0;
|
||||
|
||||
if (!(expr = ast_strdupa(data)))
|
||||
return -1;
|
||||
expr = ast_strdupa(data);
|
||||
|
||||
if ((label_a = strchr(expr, '?'))) {
|
||||
*label_a = '\0';
|
||||
|
@@ -4322,8 +4322,7 @@ static int count_exec(struct ast_channel *chan, const char *data)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!(localdata = ast_strdupa(data)))
|
||||
return -1;
|
||||
localdata = ast_strdupa(data);
|
||||
|
||||
AST_STANDARD_APP_ARGS(args, localdata);
|
||||
|
||||
|
@@ -2054,10 +2054,6 @@ static int minivm_mwi_exec(struct ast_channel *chan, const char *data)
|
||||
return -1;
|
||||
}
|
||||
tmpptr = ast_strdupa((char *)data);
|
||||
if (!tmpptr) {
|
||||
ast_log(LOG_ERROR, "Out of memory\n");
|
||||
return -1;
|
||||
}
|
||||
argc = ast_app_separate_args(tmpptr, ',', argv, ARRAY_LEN(argv));
|
||||
if (argc < 4) {
|
||||
ast_log(LOG_ERROR, "%d arguments passed to MiniVM_MWI, need 4.\n", argc);
|
||||
@@ -2102,10 +2098,6 @@ static int minivm_notify_exec(struct ast_channel *chan, const char *data)
|
||||
return -1;
|
||||
}
|
||||
tmpptr = ast_strdupa((char *)data);
|
||||
if (!tmpptr) {
|
||||
ast_log(LOG_ERROR, "Out of memory\n");
|
||||
return -1;
|
||||
}
|
||||
argc = ast_app_separate_args(tmpptr, ',', argv, ARRAY_LEN(argv));
|
||||
|
||||
if (argc == 2 && !ast_strlen_zero(argv[1]))
|
||||
@@ -2186,10 +2178,6 @@ static int minivm_record_exec(struct ast_channel *chan, const char *data)
|
||||
return -1;
|
||||
}
|
||||
tmp = ast_strdupa((char *)data);
|
||||
if (!tmp) {
|
||||
ast_log(LOG_ERROR, "Out of memory\n");
|
||||
return -1;
|
||||
}
|
||||
argc = ast_app_separate_args(tmp, ',', argv, ARRAY_LEN(argv));
|
||||
if (argc == 2) {
|
||||
if (ast_app_parse_options(minivm_app_options, &flags, opts, argv[1])) {
|
||||
@@ -2249,10 +2237,6 @@ static int minivm_greet_exec(struct ast_channel *chan, const char *data)
|
||||
return -1;
|
||||
}
|
||||
tmpptr = ast_strdupa((char *)data);
|
||||
if (!tmpptr) {
|
||||
ast_log(LOG_ERROR, "Out of memory\n");
|
||||
return -1;
|
||||
}
|
||||
argc = ast_app_separate_args(tmpptr, ',', argv, ARRAY_LEN(argv));
|
||||
|
||||
if (argc == 2) {
|
||||
@@ -2474,14 +2458,9 @@ static int minivm_accmess_exec(struct ast_channel *chan, const char *data)
|
||||
if (ast_strlen_zero(data)) {
|
||||
ast_log(LOG_ERROR, "MinivmAccmess needs at least two arguments: account and option\n");
|
||||
error = TRUE;
|
||||
} else
|
||||
} else {
|
||||
tmpptr = ast_strdupa((char *)data);
|
||||
if (!error) {
|
||||
if (!tmpptr) {
|
||||
ast_log(LOG_ERROR, "Out of memory\n");
|
||||
error = TRUE;
|
||||
} else
|
||||
argc = ast_app_separate_args(tmpptr, ',', argv, ARRAY_LEN(argv));
|
||||
argc = ast_app_separate_args(tmpptr, ',', argv, ARRAY_LEN(argv));
|
||||
}
|
||||
|
||||
if (argc <=1) {
|
||||
@@ -2621,7 +2600,7 @@ static int create_vmaccount(char *name, struct ast_variable *var, int realtime)
|
||||
char *varname = ast_strdupa(var->value);
|
||||
struct ast_variable *tmpvar;
|
||||
|
||||
if (varname && (varval = strchr(varname, '='))) {
|
||||
if ((varval = strchr(varname, '='))) {
|
||||
*varval = '\0';
|
||||
varval++;
|
||||
if ((tmpvar = ast_variable_new(varname, varval, ""))) {
|
||||
@@ -2679,11 +2658,6 @@ static int timezone_add(const char *zonename, const char *config)
|
||||
return 0;
|
||||
|
||||
msg_format = ast_strdupa(config);
|
||||
if (msg_format == NULL) {
|
||||
ast_log(LOG_WARNING, "Out of memory.\n");
|
||||
ast_free(newzone);
|
||||
return 0;
|
||||
}
|
||||
|
||||
timezone_str = strsep(&msg_format, "|");
|
||||
if (!msg_format) {
|
||||
@@ -3199,10 +3173,7 @@ static int minivm_account_func_read(struct ast_channel *chan, const char *cmd, c
|
||||
struct minivm_account *vmu;
|
||||
char *username, *domain, *colname;
|
||||
|
||||
if (!(username = ast_strdupa(data))) {
|
||||
ast_log(LOG_ERROR, "Memory Error!\n");
|
||||
return -1;
|
||||
}
|
||||
username = ast_strdupa(data);
|
||||
|
||||
if ((colname = strchr(username, ':'))) {
|
||||
*colname = '\0';
|
||||
@@ -3352,10 +3323,8 @@ static int minivm_counter_func_read(struct ast_channel *chan, const char *cmd, c
|
||||
|
||||
*buf = '\0';
|
||||
|
||||
if (!(username = ast_strdupa(data))) { /* Copy indata to local buffer */
|
||||
ast_log(LOG_WARNING, "Memory error!\n");
|
||||
return -1;
|
||||
}
|
||||
username = ast_strdupa(data);
|
||||
|
||||
if ((countername = strchr(username, ':'))) {
|
||||
*countername = '\0';
|
||||
countername++;
|
||||
@@ -3410,10 +3379,7 @@ static int minivm_counter_func_write(struct ast_channel *chan, const char *cmd,
|
||||
return -1;
|
||||
change = atoi(value);
|
||||
|
||||
if (!(username = ast_strdupa(data))) { /* Copy indata to local buffer */
|
||||
ast_log(LOG_WARNING, "Memory error!\n");
|
||||
return -1;
|
||||
}
|
||||
username = ast_strdupa(data);
|
||||
|
||||
if ((countername = strchr(username, ':'))) {
|
||||
*countername = '\0';
|
||||
|
@@ -905,7 +905,7 @@ static char *filename_parse(char *filename, char *buffer, size_t len)
|
||||
ast_log(LOG_WARNING, "No file name was provided for a file save option.\n");
|
||||
} else if (filename[0] != '/') {
|
||||
char *build;
|
||||
build = alloca(strlen(ast_config_AST_MONITOR_DIR) + strlen(filename) + 3);
|
||||
build = ast_alloca(strlen(ast_config_AST_MONITOR_DIR) + strlen(filename) + 3);
|
||||
sprintf(build, "%s/%s", ast_config_AST_MONITOR_DIR, filename);
|
||||
filename = build;
|
||||
}
|
||||
|
@@ -2270,10 +2270,7 @@ static int ospauth_exec(
|
||||
AST_APP_ARG(options);
|
||||
);
|
||||
|
||||
if (!(tmp = ast_strdupa(data))) {
|
||||
ast_log(LOG_ERROR, "Out of memory\n");
|
||||
return OSP_AST_ERROR;
|
||||
}
|
||||
tmp = ast_strdupa(data);
|
||||
|
||||
AST_STANDARD_APP_ARGS(args, tmp);
|
||||
|
||||
@@ -2365,10 +2362,7 @@ static int osplookup_exec(
|
||||
return OSP_AST_ERROR;
|
||||
}
|
||||
|
||||
if (!(tmp = ast_strdupa(data))) {
|
||||
ast_log(LOG_ERROR, "Out of memory\n");
|
||||
return OSP_AST_ERROR;
|
||||
}
|
||||
tmp = ast_strdupa(data);
|
||||
|
||||
AST_STANDARD_APP_ARGS(args, tmp);
|
||||
|
||||
@@ -2654,10 +2648,7 @@ static int ospnext_exec(
|
||||
return OSP_AST_ERROR;
|
||||
}
|
||||
|
||||
if (!(tmp = ast_strdupa(data))) {
|
||||
ast_log(LOG_ERROR, "Out of memory\n");
|
||||
return OSP_AST_ERROR;
|
||||
}
|
||||
tmp = ast_strdupa(data);
|
||||
|
||||
AST_STANDARD_APP_ARGS(args, tmp);
|
||||
|
||||
@@ -2836,10 +2827,7 @@ static int ospfinished_exec(
|
||||
AST_APP_ARG(options);
|
||||
);
|
||||
|
||||
if (!(tmp = ast_strdupa(data))) {
|
||||
ast_log(LOG_ERROR, "Out of memory\n");
|
||||
return OSP_AST_ERROR;
|
||||
}
|
||||
tmp = ast_strdupa(data);
|
||||
|
||||
AST_STANDARD_APP_ARGS(args, tmp);
|
||||
|
||||
|
@@ -1604,7 +1604,7 @@ static int sms_generate(struct ast_channel *chan, void *data, int len, int sampl
|
||||
samples = MAXSAMPLES;
|
||||
}
|
||||
len = samples * sizeof(*buf) + AST_FRIENDLY_OFFSET;
|
||||
buf = alloca(len);
|
||||
buf = ast_alloca(len);
|
||||
|
||||
f.frametype = AST_FRAME_VOICE;
|
||||
ast_format_set(&f.subclass.format, __OUT_FMT, 0);
|
||||
|
@@ -1096,7 +1096,7 @@ static int inprocess_cmp_fn(void *obj, void *arg, int flags)
|
||||
|
||||
static int inprocess_count(const char *context, const char *mailbox, int delta)
|
||||
{
|
||||
struct inprocess *i, *arg = alloca(sizeof(*arg) + strlen(context) + strlen(mailbox) + 2);
|
||||
struct inprocess *i, *arg = ast_alloca(sizeof(*arg) + strlen(context) + strlen(mailbox) + 2);
|
||||
arg->context = arg->mailbox + strlen(mailbox) + 1;
|
||||
strcpy(arg->mailbox, mailbox); /* SAFE */
|
||||
strcpy(arg->context, context); /* SAFE */
|
||||
@@ -1719,10 +1719,10 @@ static void vm_change_password(struct ast_vm_user *vmu, const char *newpassword)
|
||||
}
|
||||
value = strstr(tmp, ",");
|
||||
if (!value) {
|
||||
new = alloca(strlen(newpassword)+1);
|
||||
new = ast_alloca(strlen(newpassword)+1);
|
||||
sprintf(new, "%s", newpassword);
|
||||
} else {
|
||||
new = alloca((strlen(value) + strlen(newpassword) + 1));
|
||||
new = ast_alloca((strlen(value) + strlen(newpassword) + 1));
|
||||
sprintf(new, "%s%s", newpassword, value);
|
||||
}
|
||||
if (!(cat = ast_category_get(cfg, category))) {
|
||||
@@ -1757,7 +1757,7 @@ static void vm_change_password(struct ast_vm_user *vmu, const char *newpassword)
|
||||
} else {
|
||||
var = NULL;
|
||||
}
|
||||
new = alloca(strlen(newpassword) + 1);
|
||||
new = ast_alloca(strlen(newpassword) + 1);
|
||||
sprintf(new, "%s", newpassword);
|
||||
if (!(cat = ast_category_get(cfg, category))) {
|
||||
ast_debug(4, "failed to get category!\n");
|
||||
@@ -4472,7 +4472,7 @@ static int vm_delete(char *file)
|
||||
int txtsize = 0;
|
||||
|
||||
txtsize = (strlen(file) + 5)*sizeof(char);
|
||||
txt = alloca(txtsize);
|
||||
txt = ast_alloca(txtsize);
|
||||
/* Sprintf here would safe because we alloca'd exactly the right length,
|
||||
* but trying to eliminate all sprintf's anyhow
|
||||
*/
|
||||
@@ -8782,7 +8782,7 @@ static int vm_play_folder_name_gr(struct ast_channel *chan, char *box)
|
||||
int cmd;
|
||||
char *buf;
|
||||
|
||||
buf = alloca(strlen(box) + 2);
|
||||
buf = ast_alloca(strlen(box) + 2);
|
||||
strcpy(buf, box);
|
||||
strcat(buf, "s");
|
||||
|
||||
@@ -11697,7 +11697,7 @@ static int append_mailbox(const char *context, const char *box, const char *data
|
||||
read_password_from_file(secretfn, vmu->password, sizeof(vmu->password));
|
||||
}
|
||||
|
||||
mailbox_full = alloca(strlen(box) + strlen(context) + 1);
|
||||
mailbox_full = ast_alloca(strlen(box) + strlen(context) + 1);
|
||||
strcpy(mailbox_full, box);
|
||||
strcat(mailbox_full, "@");
|
||||
strcat(mailbox_full, context);
|
||||
@@ -15229,12 +15229,7 @@ static int vm_msg_forward(const char *from_mailbox,
|
||||
goto vm_forward_cleanup;
|
||||
}
|
||||
|
||||
if (!(msg_nums = alloca(sizeof(int) * num_msgs)))
|
||||
{
|
||||
ast_log(LOG_ERROR, "Unable to allocate stack space! Expect awful things!\n");
|
||||
res = -1;
|
||||
goto vm_forward_cleanup;
|
||||
}
|
||||
msg_nums = ast_alloca(sizeof(int) * num_msgs);
|
||||
|
||||
if ((res = message_range_and_existence_check(&from_vms, msg_ids, num_msgs, msg_nums, vmu) < 0)) {
|
||||
goto vm_forward_cleanup;
|
||||
@@ -15359,11 +15354,7 @@ static int vm_msg_move(const char *mailbox,
|
||||
goto vm_move_cleanup;
|
||||
}
|
||||
|
||||
if (!(old_msg_nums = alloca(sizeof(int) * num_msgs))) {
|
||||
ast_log(LOG_ERROR, "Unable to allocate stack space! Expect awful things!\n");
|
||||
res = -1;
|
||||
goto vm_move_cleanup;
|
||||
}
|
||||
old_msg_nums = ast_alloca(sizeof(int) * num_msgs);
|
||||
|
||||
if ((res = message_range_and_existence_check(&vms, old_msg_ids, num_msgs, old_msg_nums, vmu)) < 0) {
|
||||
goto vm_move_cleanup;
|
||||
@@ -15464,11 +15455,7 @@ static int vm_msg_remove(const char *mailbox,
|
||||
goto vm_remove_cleanup;
|
||||
}
|
||||
|
||||
if (!(msg_nums = alloca(sizeof(int) * num_msgs))) {
|
||||
ast_log(LOG_ERROR, "Unable to allocate stack space! Expect awful things\n");
|
||||
res = -1;
|
||||
goto vm_remove_cleanup;
|
||||
}
|
||||
msg_nums = ast_alloca(sizeof(int) * num_msgs);
|
||||
|
||||
if ((res = message_range_and_existence_check(&vms, msgs, num_msgs, msg_nums, vmu)) < 0) {
|
||||
goto vm_remove_cleanup;
|
||||
|
@@ -236,7 +236,7 @@ static int _while_exec(struct ast_channel *chan, const char *data, int end)
|
||||
condition = ast_strdupa(data);
|
||||
|
||||
size = strlen(ast_channel_context(chan)) + strlen(ast_channel_exten(chan)) + 32;
|
||||
my_name = alloca(size);
|
||||
my_name = ast_alloca(size);
|
||||
memset(my_name, 0, size);
|
||||
snprintf(my_name, size, "%s_%s_%d", ast_channel_context(chan), ast_channel_exten(chan), ast_channel_priority(chan));
|
||||
|
||||
@@ -281,7 +281,7 @@ static int _while_exec(struct ast_channel *chan, const char *data, int end)
|
||||
if (!end && !while_pri) {
|
||||
char *goto_str;
|
||||
size = strlen(ast_channel_context(chan)) + strlen(ast_channel_exten(chan)) + 32;
|
||||
goto_str = alloca(size);
|
||||
goto_str = ast_alloca(size);
|
||||
memset(goto_str, 0, size);
|
||||
snprintf(goto_str, size, "%s,%s,%d", ast_channel_context(chan), ast_channel_exten(chan), ast_channel_priority(chan));
|
||||
pbx_builtin_setvar_helper(chan, varname, goto_str);
|
||||
@@ -293,7 +293,7 @@ static int _while_exec(struct ast_channel *chan, const char *data, int end)
|
||||
if (! pbx_builtin_getvar_helper(chan, end_varname)) {
|
||||
char *goto_str;
|
||||
size = strlen(ast_channel_context(chan)) + strlen(ast_channel_exten(chan)) + 32;
|
||||
goto_str = alloca(size);
|
||||
goto_str = ast_alloca(size);
|
||||
memset(goto_str, 0, size);
|
||||
snprintf(goto_str, size, "%s,%s,%d", ast_channel_context(chan), ast_channel_exten(chan), ast_channel_priority(chan)+1);
|
||||
pbx_builtin_setvar_helper(chan, end_varname, goto_str);
|
||||
|
Reference in New Issue
Block a user