Clean up and ensure proper usage of alloca()
authorKinsey Moore <kmoore@digium.com>
Tue, 31 Jul 2012 20:21:43 +0000 (20:21 +0000)
committerKinsey Moore <kmoore@digium.com>
Tue, 31 Jul 2012 20:21:43 +0000 (20:21 +0000)
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

64 files changed:
addons/app_mysql.c
addons/chan_mobile.c
addons/res_config_mysql.c
apps/app_dictate.c
apps/app_directed_pickup.c
apps/app_festival.c
apps/app_getcpeid.c
apps/app_macro.c
apps/app_meetme.c
apps/app_minivm.c
apps/app_mixmonitor.c
apps/app_osplookup.c
apps/app_sms.c
apps/app_voicemail.c
apps/app_while.c
cdr/cdr_pgsql.c
channels/chan_alsa.c
channels/chan_dahdi.c
channels/chan_gtalk.c
channels/chan_iax2.c
channels/chan_jingle.c
channels/chan_sip.c
channels/sig_analog.c
channels/sig_pri.c
channels/sig_ss7.c
funcs/func_channel.c
funcs/func_cut.c
funcs/func_global.c
funcs/func_logic.c
funcs/func_strings.c
include/asterisk/strings.h
include/asterisk/utils.h
main/app.c
main/asterisk.c
main/astmm.c
main/callerid.c
main/channel.c
main/config.c
main/db.c
main/dsp.c
main/event.c
main/features.c
main/file.c
main/http.c
main/logger.c
main/manager.c
main/pbx.c
main/say.c
main/strcompat.c
main/tcptls.c
main/threadstorage.c
main/utils.c
pbx/pbx_ael.c
pbx/pbx_dundi.c
pbx/pbx_lua.c
pbx/pbx_realtime.c
pbx/pbx_spool.c
res/ael/pval.c
res/res_agi.c
res/res_config_pgsql.c
res/res_http_websocket.c
res/res_jabber.c
tests/test_linkedlists.c
utils/extconf.c

index 594b78e..2e9cae9 100644 (file)
@@ -295,7 +295,7 @@ static int aMYSQL_set(struct ast_channel *chan, char *data)
        AST_NONSTANDARD_APP_ARGS(args, data, ' ');
 
        if (args.argc == 3) {
-               var = alloca(6 + strlen(args.variable) + 1);
+               var = ast_alloca(6 + strlen(args.variable) + 1);
                sprintf(var, "MYSQL_%s", args.variable);
 
                /* Make the parameter case-insensitive */
index 618d4e4..be00221 100644 (file)
@@ -557,7 +557,7 @@ static char *handle_cli_mobile_search(struct ast_cli_entry *e, int cmd, struct a
        max_rsp = 255;
        flags = IREQ_CACHE_FLUSH;
 
-       ii = alloca(max_rsp * sizeof(inquiry_info));
+       ii = ast_alloca(max_rsp * sizeof(inquiry_info));
        num_rsp = hci_inquiry(adapter->dev_id, len, max_rsp, NULL, &ii, flags);
        if (num_rsp > 0) {
                ast_cli(a->fd, FORMAT1, "Address", "Name", "Usable", "Type", "Port");
index 0eac432..4984dbd 100644 (file)
@@ -144,7 +144,7 @@ static struct mysql_conn *find_database(const char *database, int for_write)
                if (for_write) {
                        whichdb = ast_strdupa(ptr + 1);
                } else {
-                       whichdb = alloca(ptr - database + 1);
+                       whichdb = ast_alloca(ptr - database + 1);
                        strncpy(whichdb, database, ptr - database);
                        whichdb[ptr - database] = '\0';
                }
@@ -467,7 +467,7 @@ static struct ast_config *realtime_multi_mysql(const char *database, const char
        }
 
        initfield = ast_strdupa(newparam);
-       if (initfield && (op = strchr(initfield, ' '))) {
+       if ((op = strchr(initfield, ' '))) {
                *op = '\0';
        }
 
index 32ee594..1820a1f 100644 (file)
@@ -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 {
index 77a6e46..9ae3fc8 100644 (file)
@@ -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;
index fe38bb6..d875b7a 100644 (file)
@@ -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') {
index 30b5d78..5cdeca1 100644 (file)
@@ -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...");
index 337091f..9ec3b86 100644 (file)
@@ -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';
index 5b787b8..98b7f42 100644 (file)
@@ -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);
        
index 0b46311..1674f7e 100644 (file)
@@ -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';
index 7da3bea..9ebea1a 100644 (file)
@@ -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;
        }
index d63c6da..88edbd5 100644 (file)
@@ -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);
 
index c7a0825..36e7dd6 100644 (file)
@@ -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);
index 6d01603..a4deb9b 100644 (file)
@@ -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;
index d1e03f6..90d3d58 100644 (file)
@@ -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);
index 61ab2b8..4b536ab 100644 (file)
@@ -617,7 +617,7 @@ static int config_module(int reload)
                        if (strchr(schemaname, '\\') || strchr(schemaname, '\'')) {
                                char *tmp = schemaname, *ptr;
 
-                               ptr = schemaname = alloca(strlen(tmp) * 2 + 1);
+                               ptr = schemaname = ast_alloca(strlen(tmp) * 2 + 1);
                                for (; *tmp; tmp++) {
                                        if (strchr("\\'", *tmp)) {
                                                *ptr++ = *tmp;
@@ -630,7 +630,7 @@ static int config_module(int reload)
                        if (strchr(tablename, '\\') || strchr(tablename, '\'')) {
                                char *tmp = tablename, *ptr;
 
-                               ptr = tablename = alloca(strlen(tmp) * 2 + 1);
+                               ptr = tablename = ast_alloca(strlen(tmp) * 2 + 1);
                                for (; *tmp; tmp++) {
                                        if (strchr("\\'", *tmp)) {
                                                *ptr++ = *tmp;
index e535a3a..71d51ad 100644 (file)
@@ -182,7 +182,7 @@ static snd_pcm_t *alsa_card_init(char *dev, snd_pcm_stream_t stream)
                ast_debug(1, "Opening device %s in %s mode\n", dev, (stream == SND_PCM_STREAM_CAPTURE) ? "read" : "write");
        }
 
-       hwparams = alloca(snd_pcm_hw_params_sizeof());
+       hwparams = ast_alloca(snd_pcm_hw_params_sizeof());
        memset(hwparams, 0, snd_pcm_hw_params_sizeof());
        snd_pcm_hw_params_any(handle, hwparams);
 
@@ -223,7 +223,7 @@ static snd_pcm_t *alsa_card_init(char *dev, snd_pcm_stream_t stream)
        if (err < 0)
                ast_log(LOG_ERROR, "Couldn't set the new hw params: %s\n", snd_strerror(err));
 
-       swparams = alloca(snd_pcm_sw_params_sizeof());
+       swparams = ast_alloca(snd_pcm_sw_params_sizeof());
        memset(swparams, 0, snd_pcm_sw_params_sizeof());
        snd_pcm_sw_params_current(handle, swparams);
 
index 28212e5..c0afc57 100644 (file)
@@ -4181,7 +4181,7 @@ static void dahdi_r2_on_call_disconnect(openr2_chan_t *r2chan, openr2_call_disco
 
        snprintf(cause_str, sizeof(cause_str), "R2 DISCONNECT (%s)", openr2_proto_get_disconnect_string(cause));
        datalen += strlen(cause_str);
-       cause_code = alloca(datalen);
+       cause_code = ast_alloca(datalen);
        cause_code->ast_cause = dahdi_r2_cause_to_ast_cause(cause);
        ast_copy_string(cause_code->chan_name, ast_channel_name(p->owner), AST_CHANNEL_NAME);
        ast_copy_string(cause_code->code, cause_str, datalen + 1 - sizeof(*cause_code));
index e1d3ab4..9864f78 100644 (file)
@@ -1908,15 +1908,17 @@ static struct ast_channel *gtalk_request(const char *type, struct ast_format_cap
 
        if (data) {
                s = ast_strdupa(data);
-               if (s) {
-                       sender = strsep(&s, "/");
-                       if (sender && (sender[0] != '\0')) {
-                               to = strsep(&s, "/");
-                       }
-                       if (!to) {
-                               ast_log(LOG_ERROR, "Bad arguments in Gtalk Dialstring: %s\n", data);
-                               return NULL;
-                       }
+               sender = strsep(&s, "/");
+               if (sender && (sender[0] != '\0')) {
+                       to = strsep(&s, "/");
+               }
+               if (!to) {
+                       ast_log(LOG_ERROR, "Bad arguments in Gtalk Dialstring: %s\n", data);
+                       return NULL;
+               }
+               if (!to) {
+                       ast_log(LOG_ERROR, "Bad arguments in Gtalk Dialstring: %s\n", (char*) data);
+                       return NULL;
                }
        }
 
index 70318a1..51e777c 100644 (file)
@@ -3084,10 +3084,7 @@ static int try_firmware(char *s)
        unsigned char sum[16], buf[1024];
        char *s2, *last;
 
-       if (!(s2 = alloca(strlen(s) + 100))) {
-               ast_log(LOG_WARNING, "Alloca failed!\n");
-               return -1;
-       }
+       s2 = ast_alloca(strlen(s) + 100);
 
        last = strrchr(s, '/');
        if (last)
@@ -6340,7 +6337,7 @@ static int decode_frame(ast_aes_decrypt_key *dcx, struct ast_iax2_full_hdr *fh,
        int padding;
        unsigned char *workspace;
 
-       workspace = alloca(*datalen);
+       workspace = ast_alloca(*datalen);
        memset(f, 0, sizeof(*f));
        if (ntohs(fh->scallno) & IAX_FLAG_FULL) {
                struct ast_iax2_full_enc_hdr *efh = (struct ast_iax2_full_enc_hdr *)fh;
@@ -6386,9 +6383,7 @@ static int encrypt_frame(ast_aes_encrypt_key *ecx, struct ast_iax2_full_hdr *fh,
 {
        int padding;
        unsigned char *workspace;
-       workspace = alloca(*datalen + 32);
-       if (!workspace)
-               return -1;
+       workspace = ast_alloca(*datalen + 32);
        if (ntohs(fh->scallno) & IAX_FLAG_FULL) {
                struct ast_iax2_full_enc_hdr *efh = (struct ast_iax2_full_enc_hdr *)fh;
                if (iaxdebug)
@@ -10016,9 +10011,9 @@ static int socket_process_helper(struct iax2_thread *thread)
        char *using_prefs = "mine";
 
        /* allocate an iax_frame with 4096 bytes of data buffer */
-       fr = alloca(sizeof(*fr) + 4096);
+       fr = ast_alloca(sizeof(*fr) + 4096);
        memset(fr, 0, sizeof(*fr));
-       fr->afdatalen = 4096; /* From alloca() above */
+       fr->afdatalen = 4096; /* From ast_alloca() above */
 
        /* Copy frequently used parameters to the stack */
        res = thread->buf_len;
@@ -10236,7 +10231,7 @@ static int socket_process_helper(struct iax2_thread *thread)
                /* add length of subclass */
                data_size += strlen(subclass);
 
-               cause_code = alloca(data_size);
+               cause_code = ast_alloca(data_size);
                ast_copy_string(cause_code->chan_name, ast_channel_name(iaxs[fr->callno]->owner), AST_CHANNEL_NAME);
 
                cause_code->ast_cause = ies.causecode;
@@ -12470,9 +12465,7 @@ static int peer_set_srcaddr(struct iax2_peer *peer, const char *srcaddr)
        char *host;
        char *portstr;
 
-       if (!(tmp = ast_strdupa(srcaddr)))
-               return -1;
-
+       tmp = ast_strdupa(srcaddr);
        ast_sockaddr_split_hostport(tmp, &host, &portstr, 0);
 
        if (portstr) {
@@ -12935,7 +12928,7 @@ static struct iax2_user *build_user(const char *name, struct ast_variable *v, st
                                ast_append_acl(v->name, v->value, &user->acl, NULL, &subscribe_acl_change);
                        } else if (!strcasecmp(v->name, "setvar")) {
                                varname = ast_strdupa(v->value);
-                               if (varname && (varval = strchr(varname,'='))) {
+                               if ((varval = strchr(varname, '='))) {
                                        *varval = '\0';
                                        varval++;
                                        if((tmpvar = ast_variable_new(varname, varval, ""))) {
index 4f4af23..a3adb65 100644 (file)
@@ -1553,14 +1553,16 @@ static struct ast_channel *jingle_request(const char *type, struct ast_format_ca
 
        if (data) {
                s = ast_strdupa(data);
-               if (s) {
-                       sender = strsep(&s, "/");
-                       if (sender && (sender[0] != '\0'))
-                               to = strsep(&s, "/");
-                       if (!to) {
-                               ast_log(LOG_ERROR, "Bad arguments in Jingle Dialstring: %s\n", data);
-                               return NULL;
-                       }
+               sender = strsep(&s, "/");
+               if (sender && (sender[0] != '\0'))
+                       to = strsep(&s, "/");
+               if (!to) {
+                       ast_log(LOG_ERROR, "Bad arguments in Jingle Dialstring: %s\n", data);
+                       return NULL;
+               }
+               if (!to) {
+                       ast_log(LOG_ERROR, "Bad arguments in Jingle Dialstring: %s\n", (char*) data);
+                       return NULL;
                }
        }
 
index 6c2ff43..367aeee 100644 (file)
@@ -5657,7 +5657,7 @@ static int create_addr_from_peer(struct sip_pvt *dialog, struct sip_peer *peer)
 
                                /* Change the dialog callid. */
                                callid_size = strlen(tmpcall) + strlen(peer->fromdomain) + 2;
-                               new_callid = alloca(callid_size);
+                               new_callid = ast_alloca(callid_size);
                                snprintf(new_callid, callid_size, "%s@%s", tmpcall, peer->fromdomain);
                                change_callid_pvt(dialog, new_callid);
                        }
@@ -13829,7 +13829,7 @@ static void state_notify_build_xml(struct state_notify_data *data, int full, con
                                        cid_num = S_COR(ast_channel_caller(caller)->id.number.valid,
                                                ast_channel_caller(caller)->id.number.str, "");
                                        need = strlen(cid_num) + strlen(p->fromdomain) + sizeof("sip:@");
-                                       remote_target = alloca(need);
+                                       remote_target = ast_alloca(need);
                                        snprintf(remote_target, need, "sip:%s@%s", cid_num, p->fromdomain);
 
                                        remote_display = ast_strdupa(S_COR(ast_channel_caller(caller)->id.name.valid,
@@ -13838,7 +13838,7 @@ static void state_notify_build_xml(struct state_notify_data *data, int full, con
                                        connected_num = S_COR(ast_channel_connected(caller)->id.number.valid,
                                                ast_channel_connected(caller)->id.number.str, "");
                                        need = strlen(connected_num) + strlen(p->fromdomain) + sizeof("sip:@");
-                                       local_target = alloca(need);
+                                       local_target = ast_alloca(need);
                                        snprintf(local_target, need, "sip:%s@%s", connected_num, p->fromdomain);
 
                                        local_display = ast_strdupa(S_COR(ast_channel_connected(caller)->id.name.valid,
@@ -25025,7 +25025,8 @@ static int local_attended_transfer(struct sip_pvt *transferer, struct sip_dual *
                        payload_size = ast_connected_line_build_data(connected_line_data,
                                sizeof(connected_line_data), &connected_to_target, NULL);
                        frame_size = payload_size + sizeof(*frame_payload);
-                       if (payload_size != -1 && (frame_payload = alloca(frame_size))) {
+                       if (payload_size != -1) {
+                               frame_payload = ast_alloca(frame_size);
                                frame_payload->payload_size = payload_size;
                                memcpy(frame_payload->payload, connected_line_data, payload_size);
                                frame_payload->action = AST_FRAME_READ_ACTION_CONNECTED_LINE_MACRO;
@@ -27037,7 +27038,7 @@ static int handle_incoming(struct sip_pvt *p, struct sip_request *req, struct as
                                int data_size = sizeof(*cause_code);
                                /* size of the string making up the cause code is "SIP " + cause length */
                                data_size += 4 + strlen(REQ_OFFSET_TO_STR(req, rlpart2));
-                               cause_code = alloca(data_size);
+                               cause_code = ast_alloca(data_size);
 
                                ast_copy_string(cause_code->chan_name, ast_channel_name(p->owner), AST_CHANNEL_NAME);
 
@@ -31734,7 +31735,7 @@ static int sip_addheader(struct ast_channel *chan, const char *data)
        }
        if (ok) {
                size_t len = strlen(inbuf);
-               subbuf = alloca(len + 1);
+               subbuf = ast_alloca(len + 1);
                ast_get_encoded_str(inbuf, subbuf, len + 1);
                pbx_builtin_setvar_helper(chan, varbuf, subbuf);
                if (sipdebug) {
index 608f82b..2b81eb4 100644 (file)
@@ -2734,7 +2734,7 @@ static struct ast_frame *__analog_handle_event(struct analog_pvt *p, struct ast_
                data_size += 7;
                subclass = analog_event2str(res);
                data_size += strlen(subclass);
-               cause_code = alloca(data_size);
+               cause_code = ast_alloca(data_size);
                cause_code->ast_cause = AST_CAUSE_NORMAL_CLEARING;
                ast_copy_string(cause_code->chan_name, ast_channel_name(ast), AST_CHANNEL_NAME);
                snprintf(cause_code->code, data_size - sizeof(*cause_code) + 1, "ANALOG %s", subclass);
index 30d11e7..4bb4066 100644 (file)
@@ -1286,7 +1286,7 @@ static void pri_queue_pvt_cause_data(struct sig_pri_span *pri, int chanpos, cons
        chan = pri->pvts[chanpos]->owner;
        if (chan) {
                int datalen = sizeof(*cause_code) + strlen(cause);
-               cause_code = alloca(datalen);
+               cause_code = ast_alloca(datalen);
                cause_code->ast_cause = ast_cause;
                ast_copy_string(cause_code->chan_name, ast_channel_name(chan), AST_CHANNEL_NAME);
                ast_copy_string(cause_code->code, cause, datalen + 1 - sizeof(*cause_code));
index 810a0d5..1e4e7f3 100644 (file)
@@ -389,7 +389,7 @@ static void ss7_queue_pvt_cause_data(struct ast_channel *owner, const char *caus
        struct ast_control_pvt_cause_code *cause_code;
        int datalen = sizeof(*cause_code) + strlen(cause);
 
-       cause_code = alloca(datalen);
+       cause_code = ast_alloca(datalen);
        cause_code->ast_cause = ast_cause;
        ast_copy_string(cause_code->chan_name, ast_channel_name(owner), AST_CHANNEL_NAME);
        ast_copy_string(cause_code->code, cause, datalen + 1 - sizeof(*cause_code));
index 699f3b6..bd3367d 100644 (file)
@@ -684,7 +684,7 @@ static int func_mchan_read(struct ast_channel *chan, const char *function,
                             char *data, struct ast_str **buf, ssize_t len)
 {
        struct ast_channel *mchan = ast_channel_get_by_name(ast_channel_linkedid(chan));
-       char *template = alloca(4 + strlen(data));
+       char *template = ast_alloca(4 + strlen(data));
        sprintf(template, "${%s}", data); /* SAFE */
        ast_str_substitute_variables(buf, len, mchan ? mchan : chan, template);
        if (mchan) {
index 762dd61..4b6dc9d 100644 (file)
@@ -119,7 +119,7 @@ static int sort_internal(struct ast_channel *chan, char *data, char *buffer, siz
                        count++;
        }
 
-       sortable_keys = alloca(count * sizeof(struct sortable_keys));
+       sortable_keys = ast_alloca(count * sizeof(struct sortable_keys));
 
        memset(sortable_keys, 0, count * sizeof(struct sortable_keys));
 
@@ -170,9 +170,8 @@ static int cut_internal(struct ast_channel *chan, char *data, struct ast_str **b
        /* Check arguments */
        if (args.argc < 3) {
                return ERROR_NOARG;
-       } else if (!(var_expr = alloca(strlen(args.varname) + 4))) {
-               return ERROR_NOMEM;
        }
+       var_expr = ast_alloca(strlen(args.varname) + 4);
 
        /* Get the value of the variable named in the 1st argument */
        snprintf(var_expr, strlen(args.varname) + 4, "${%s}", args.varname);
index e16b60a..0a4b89d 100644 (file)
@@ -148,7 +148,7 @@ static int shared_read(struct ast_channel *chan, const char *cmd, char *data, ch
        AST_STANDARD_APP_ARGS(args, data);
 
        if (!ast_strlen_zero(args.chan)) {
-               char *prefix = alloca(strlen(args.chan) + 2);
+               char *prefix = ast_alloca(strlen(args.chan) + 2);
                sprintf(prefix, "%s-", args.chan);
                if (!(c_ref = ast_channel_get_by_name(args.chan)) && !(c_ref = ast_channel_get_by_name_prefix(prefix, strlen(prefix)))) {
                        ast_log(LOG_ERROR, "Channel '%s' not found!  Variable '%s' will be blank.\n", args.chan, args.var);
@@ -206,7 +206,7 @@ static int shared_write(struct ast_channel *chan, const char *cmd, char *data, c
        AST_STANDARD_APP_ARGS(args, data);
 
        if (!ast_strlen_zero(args.chan)) {
-               char *prefix = alloca(strlen(args.chan) + 2);
+               char *prefix = ast_alloca(strlen(args.chan) + 2);
                sprintf(prefix, "%s-", args.chan);
                if (!(c_ref = ast_channel_get_by_name(args.chan)) && !(c_ref = ast_channel_get_by_name_prefix(prefix, strlen(prefix)))) {
                        ast_log(LOG_ERROR, "Channel '%s' not found!  Variable '%s' not set to '%s'.\n", args.chan, args.var, value);
index 21f08a1..e371f7e 100644 (file)
@@ -250,17 +250,15 @@ static int import_helper(struct ast_channel *chan, const char *cmd, char *data,
                struct ast_channel *chan2;
 
                if ((chan2 = ast_channel_get_by_name(args.channel))) {
-                       char *s = alloca(strlen(args.varname) + 4);
-                       if (s) {
-                               sprintf(s, "${%s}", args.varname);
-                               ast_channel_lock(chan2);
-                               if (buf) {
-                                       pbx_substitute_variables_helper(chan2, s, buf, len);
-                               } else {
-                                       ast_str_substitute_variables(str, len, chan2, s);
-                               }
-                               ast_channel_unlock(chan2);
+                       char *s = ast_alloca(strlen(args.varname) + 4);
+                       sprintf(s, "${%s}", args.varname);
+                       ast_channel_lock(chan2);
+                       if (buf) {
+                               pbx_substitute_variables_helper(chan2, s, buf, len);
+                       } else {
+                               ast_str_substitute_variables(str, len, chan2, s);
                        }
+                       ast_channel_unlock(chan2);
                        chan2 = ast_channel_unref(chan2);
                }
        }
index 5bf687b..2ba1d53 100644 (file)
@@ -456,7 +456,7 @@ static int function_fieldqty_helper(struct ast_channel *chan, const char *cmd,
        if (args.delim) {
                ast_get_encoded_char(args.delim, delim, &delim_used);
 
-               varsubst = alloca(strlen(args.varname) + 4);
+               varsubst = ast_alloca(strlen(args.varname) + 4);
 
                sprintf(varsubst, "${%s}", args.varname);
                ast_str_substitute_variables(&str, 0, chan, varsubst);
@@ -522,7 +522,7 @@ static int function_fieldnum_helper(struct ast_channel *chan, const char *cmd,
                ast_log(LOG_ERROR, "Usage: FIELDNUM(<listname>,<delimiter>,<fieldvalue>)\n");
                res = -1;
        } else {
-               varsubst = alloca(strlen(args.varname) + 4);
+               varsubst = ast_alloca(strlen(args.varname) + 4);
                sprintf(varsubst, "${%s}", args.varname);
 
                ast_str_substitute_variables(&str, 0, chan, varsubst);
@@ -606,7 +606,7 @@ static int listfilter(struct ast_channel *chan, const char *cmd, char *parse, ch
                return -1;
        }
 
-       varsubst = alloca(strlen(args.listname) + 4);
+       varsubst = ast_alloca(strlen(args.listname) + 4);
        sprintf(varsubst, "${%s}", args.listname);
 
        /* If we don't lock the channel, the variable could disappear out from underneath us. */
@@ -636,7 +636,7 @@ static int listfilter(struct ast_channel *chan, const char *cmd, char *parse, ch
        }
 
        dlen = strlen(args.delimiter);
-       delim = alloca(dlen + 1);
+       delim = ast_alloca(dlen + 1);
        ast_get_encoded_str(args.delimiter, delim, dlen + 1);
 
        if ((dlen = strlen(delim)) == 0) {
@@ -819,7 +819,7 @@ static int replace(struct ast_channel *chan, const char *cmd, char *data, struct
                return -1;
        }
 
-       varsubst = alloca(strlen(args.varname) + 4);
+       varsubst = ast_alloca(strlen(args.varname) + 4);
        sprintf(varsubst, "${%s}", args.varname);
        ast_str_substitute_variables(&str, 0, chan, varsubst);
 
@@ -906,7 +906,7 @@ static int strreplace(struct ast_channel *chan, const char *cmd, char *data, str
        find_size = strlen(args.find_string);
 
        /* set varsubstr to the matching variable */
-       varsubstr = alloca(strlen(args.varname) + 4);
+       varsubstr = ast_alloca(strlen(args.varname) + 4);
        sprintf(varsubstr, "${%s}", args.varname);
        ast_str_substitute_variables(&str, 0, chan, varsubstr);
 
@@ -1026,9 +1026,10 @@ static int array(struct ast_channel *chan, const char *cmd, char *var,
        char *origvar = "", *value2, varname[256];
        int i, ishash = 0;
 
-       value2 = ast_strdupa(value);
-       if (!var || !value2)
+       if (!var) {
                return -1;
+       }
+       value2 = ast_strdupa(value);
 
        if (!strcmp(cmd, "HASH")) {
                const char *var2 = pbx_builtin_getvar_helper(chan, "~ODBCFIELDS~");
@@ -1544,7 +1545,7 @@ static int shift_pop(struct ast_channel *chan, const char *cmd, char *data, stru
                return -1;
        }
 
-       varsubst = alloca(strlen(args.var) + 4);
+       varsubst = ast_alloca(strlen(args.var) + 4);
        sprintf(varsubst, "${%s}", args.var);
        ast_str_substitute_variables(&before, 0, chan, varsubst);
 
@@ -1608,7 +1609,7 @@ static int unshift_push(struct ast_channel *chan, const char *cmd, char *data, c
                ast_get_encoded_char(args.delimiter, delimiter, &unused);
        }
 
-       varsubst = alloca(strlen(args.var) + 4);
+       varsubst = ast_alloca(strlen(args.var) + 4);
        sprintf(varsubst, "${%s}", args.var);
        ast_str_substitute_variables(&previous_value, 0, chan, varsubst);
 
index 7a77722..7d80690 100644 (file)
@@ -372,7 +372,7 @@ int ast_get_timeval(const char *src, struct timeval *tv, struct timeval _default
 /*! \brief The descriptor of a dynamic string
  *  XXX storage will be optimized later if needed
  * We use the ts field to indicate the type of storage.
- * Three special constants indicate malloc, alloca() or static
+ * Three special constants indicate malloc, ast_alloca() or static
  * variables, all other values indicate a
  * struct ast_threadstorage pointer.
  */
@@ -623,7 +623,7 @@ int ast_str_copy_string(struct ast_str **dst, struct ast_str *src),
 #define ast_str_alloca(init_len)                       \
        ({                                              \
                struct ast_str *__ast_str_buf;                  \
-               __ast_str_buf = alloca(sizeof(*__ast_str_buf) + init_len);      \
+               __ast_str_buf = ast_alloca(sizeof(*__ast_str_buf) + init_len);  \
                __ast_str_buf->__AST_STR_LEN = init_len;                        \
                __ast_str_buf->__AST_STR_USED = 0;                              \
                __ast_str_buf->__AST_STR_TS = DS_ALLOCA;                        \
index edc01d4..a417cf4 100644 (file)
@@ -646,6 +646,15 @@ int _ast_vasprintf(char **ret, const char *file, int lineno, const char *func, c
 
 #endif /* AST_DEBUG_MALLOC */
 
+/*!
+  \brief call __builtin_alloca to ensure we get gcc builtin semantics
+  \param size The size of the buffer we want allocated
+
+  This macro will attempt to allocate memory from the stack.  If it fails
+  you won't get a NULL returned, but a SEGFAULT if you're lucky.
+*/
+#define ast_alloca(size) __builtin_alloca(size)
+
 #if !defined(ast_strdupa) && defined(__GNUC__)
 /*!
  * \brief duplicate a string in memory from the stack
index f6a3095..c8cb29c 100644 (file)
@@ -947,7 +947,7 @@ static int control_streamfile(struct ast_channel *chan,
        }
 
        if (blen > 2) {
-               breaks = alloca(blen + 1);
+               breaks = ast_alloca(blen + 1);
                breaks[0] = '\0';
                if (stop) {
                        strcat(breaks, stop);
@@ -1719,8 +1719,8 @@ static enum AST_LOCK_RESULT ast_lock_path_lockfile(const char *path)
        int lp = strlen(path);
        time_t start;
 
-       s = alloca(lp + 10);
-       fs = alloca(lp + 20);
+       s = ast_alloca(lp + 10);
+       fs = ast_alloca(lp + 20);
 
        snprintf(fs, strlen(path) + 19, "%s/.lock-%08lx", path, ast_random());
        fd = open(fs, O_WRONLY | O_CREAT | O_EXCL, AST_FILE_MODE);
@@ -1752,7 +1752,7 @@ static int ast_unlock_path_lockfile(const char *path)
        char *s;
        int res;
 
-       s = alloca(strlen(path) + 10);
+       s = ast_alloca(strlen(path) + 10);
 
        snprintf(s, strlen(path) + 9, "%s/%s", path, ".lock");
 
@@ -1793,7 +1793,7 @@ static enum AST_LOCK_RESULT ast_lock_path_flock(const char *path)
        struct path_lock *pl;
        struct stat st, ost;
 
-       fs = alloca(strlen(path) + 20);
+       fs = ast_alloca(strlen(path) + 20);
 
        snprintf(fs, strlen(path) + 19, "%s/lock", path);
        if (lstat(fs, &st) == 0) {
@@ -1874,7 +1874,7 @@ static int ast_unlock_path_flock(const char *path)
        char *s;
        struct path_lock *p;
 
-       s = alloca(strlen(path) + 20);
+       s = ast_alloca(strlen(path) + 20);
 
        AST_LIST_LOCK(&path_lock_list);
        AST_LIST_TRAVERSE_SAFE_BEGIN(&path_lock_list, p, le) {
index e06d70a..8e6d1a4 100644 (file)
@@ -2896,7 +2896,7 @@ static void ast_remotecontrol(char *data)
        }
        if (data) {
                char prefix[] = "cli quit after ";
-               char *tmp = alloca(strlen(data) + strlen(prefix) + 1);
+               char *tmp = ast_alloca(strlen(data) + strlen(prefix) + 1);
                sprintf(tmp, "%s%s", prefix, data);
                if (write(ast_consock, tmp, strlen(tmp) + 1) < 0) {
                        ast_log(LOG_ERROR, "write() failed: %s\n", strerror(errno));
index 125eb8c..7413582 100644 (file)
@@ -430,7 +430,7 @@ static char *handle_memory_show_summary(struct ast_cli_entry *e, int cmd, struct
                                        break;
                        }
                        if (!cur) {
-                               cur = alloca(sizeof(*cur));
+                               cur = ast_alloca(sizeof(*cur));
                                memset(cur, 0, sizeof(*cur));
                                ast_copy_string(cur->fn, fn ? reg->func : reg->file, sizeof(cur->fn));
                                cur->next = list;
index 3af60bd..d9f7418 100644 (file)
@@ -314,7 +314,7 @@ int callerid_feed_jp(struct callerid_state *cid, unsigned char *ubuf, int len, s
        int x;
        short *buf;
 
-       buf = alloca(2 * len + cid->oldlen);
+       buf = ast_alloca(2 * len + cid->oldlen);
 
        memcpy(buf, cid->oldstuff, cid->oldlen);
        mylen += cid->oldlen / 2;
@@ -552,7 +552,7 @@ int callerid_feed(struct callerid_state *cid, unsigned char *ubuf, int len, stru
        int x;
        short *buf;
 
-       buf = alloca(2 * len + cid->oldlen);
+       buf = ast_alloca(2 * len + cid->oldlen);
 
        memcpy(buf, cid->oldstuff, cid->oldlen);
        mylen += cid->oldlen/2;
index f2660e1..fdb4f00 100644 (file)
@@ -3065,8 +3065,8 @@ struct ast_channel *ast_waitfor_nandfds(struct ast_channel **c, int n, int *fds,
        }
 
        if ((sz = n * AST_MAX_FDS + nfds)) {
-               pfds = alloca(sizeof(*pfds) * sz);
-               fdmap = alloca(sizeof(*fdmap) * sz);
+               pfds = ast_alloca(sizeof(*pfds) * sz);
+               fdmap = ast_alloca(sizeof(*fdmap) * sz);
        } else {
                /* nothing to allocate and no FDs to check */
                return NULL;
@@ -6609,7 +6609,7 @@ static void masquerade_colp_transfer(struct ast_channel *transferee, struct xfer
                sizeof(connected_line_data), &colp->target_id, NULL);
        if (payload_size != -1) {
                frame_size = payload_size + sizeof(*frame_payload);
-               frame_payload = alloca(frame_size);
+               frame_payload = ast_alloca(frame_size);
                frame_payload->action = AST_FRAME_READ_ACTION_CONNECTED_LINE_MACRO;
                frame_payload->payload_size = payload_size;
                memcpy(frame_payload->payload, connected_line_data, payload_size);
index fee6d9e..9abc602 100644 (file)
@@ -118,7 +118,7 @@ static void  CB_ADD(struct ast_str **cb, const char *str)
 
 static void  CB_ADD_LEN(struct ast_str **cb, const char *str, int len)
 {
-       char *s = alloca(len + 1);
+       char *s = ast_alloca(len + 1);
        ast_copy_string(s, str, len);
        ast_str_append(cb, 0, "%s", str);
 }
@@ -3099,7 +3099,7 @@ static char *handle_cli_config_reload(struct ast_cli_entry *e, int cmd, struct a
        AST_LIST_LOCK(&cfmtime_head);
        AST_LIST_TRAVERSE(&cfmtime_head, cfmtime, list) {
                if (!strcmp(cfmtime->filename, a->argv[2])) {
-                       char *buf = alloca(strlen("module reload ") + strlen(cfmtime->who_asked) + 1);
+                       char *buf = ast_alloca(strlen("module reload ") + strlen(cfmtime->who_asked) + 1);
                        sprintf(buf, "module reload %s", cfmtime->who_asked);
                        ast_cli_command(a->fd, buf);
                }
index 9d5fe1c..42a4b9c 100644 (file)
--- a/main/db.c
+++ b/main/db.c
@@ -192,7 +192,7 @@ static int db_open(void)
        char *dbname;
        struct stat dont_care;
 
-       if (!(dbname = alloca(strlen(ast_config_AST_DB) + sizeof(".sqlite3")))) {
+       if (!(dbname = ast_alloca(strlen(ast_config_AST_DB) + sizeof(".sqlite3")))) {
                return -1;
        }
        strcpy(dbname, ast_config_AST_DB);
index c5da2df..33db505 100644 (file)
@@ -1336,13 +1336,13 @@ static int ast_dsp_silence_noise_with_energy(struct ast_dsp *dsp, struct ast_fra
                len = f->datalen;
                switch (f->subclass.format.id) {
                        case AST_FORMAT_ULAW:
-                               s = alloca(len * 2);
+                               s = ast_alloca(len * 2);
                                for (x = 0;x < len; x++) {
                                        s[x] = AST_MULAW(odata[x]);
                                }
                                break;
                        case AST_FORMAT_ALAW:
-                               s = alloca(len * 2);
+                               s = ast_alloca(len * 2);
                                for (x = 0;x < len; x++) {
                                        s[x] = AST_ALAW(odata[x]);
                                }
@@ -1406,13 +1406,13 @@ struct ast_frame *ast_dsp_process(struct ast_channel *chan, struct ast_dsp *dsp,
                switch (af->subclass.format.id) {
                case AST_FORMAT_ULAW:
                case AST_FORMAT_TESTLAW:
-                       shortdata = alloca(af->datalen * 2);
+                       shortdata = ast_alloca(af->datalen * 2);
                        for (x = 0;x < len; x++) {
                                shortdata[x] = AST_MULAW(odata[x]);
                        }
                        break;
                case AST_FORMAT_ALAW:
-                       shortdata = alloca(af->datalen * 2);
+                       shortdata = ast_alloca(af->datalen * 2);
                        for (x = 0; x < len; x++) {
                                shortdata[x] = AST_ALAW(odata[x]);
                        }
index 7470ead..23e20f3 100644 (file)
@@ -480,7 +480,7 @@ enum ast_event_subscriber_res ast_event_check_subscriber(enum ast_event_type typ
                ie_type != AST_EVENT_IE_END;
                ie_type = va_arg(ap, enum ast_event_ie_type))
        {
-               struct ast_event_ie_val *ie_value = alloca(sizeof(*ie_value));
+               struct ast_event_ie_val *ie_value = ast_alloca(sizeof(*ie_value));
                int insert = 0;
 
                memset(ie_value, 0, sizeof(*ie_value));
@@ -504,7 +504,7 @@ enum ast_event_subscriber_res ast_event_check_subscriber(enum ast_event_type typ
                        void *data = va_arg(ap, void *);
                        size_t datalen = va_arg(ap, size_t);
 
-                       ie_value->payload.raw = alloca(datalen);
+                       ie_value->payload.raw = ast_alloca(datalen);
                        memcpy(ie_value->payload.raw, data, datalen);
                        ie_value->raw_datalen = datalen;
                        insert = 1;
@@ -1157,7 +1157,7 @@ int ast_event_append_ie_str(struct ast_event **event, enum ast_event_ie_type ie_
        size_t payload_len;
 
        payload_len = sizeof(*str_payload) + strlen(str);
-       str_payload = alloca(payload_len);
+       str_payload = ast_alloca(payload_len);
 
        strcpy(str_payload->str, str);
        if (ie_type == AST_EVENT_IE_DEVICE) {
@@ -1229,7 +1229,7 @@ struct ast_event *ast_event_new(enum ast_event_type type, ...)
                ie_type != AST_EVENT_IE_END;
                ie_type = va_arg(ap, enum ast_event_ie_type))
        {
-               struct ast_event_ie_val *ie_value = alloca(sizeof(*ie_value));
+               struct ast_event_ie_val *ie_value = ast_alloca(sizeof(*ie_value));
                int insert = 0;
 
                memset(ie_value, 0, sizeof(*ie_value));
@@ -1252,7 +1252,7 @@ struct ast_event *ast_event_new(enum ast_event_type type, ...)
                {
                        void *data = va_arg(ap, void *);
                        size_t datalen = va_arg(ap, size_t);
-                       ie_value->payload.raw = alloca(datalen);
+                       ie_value->payload.raw = ast_alloca(datalen);
                        memcpy(ie_value->payload.raw, data, datalen);
                        ie_value->raw_datalen = datalen;
                        insert = 1;
index dd62c0c..5d0f8ec 100644 (file)
@@ -857,7 +857,7 @@ static void set_new_chan_name(struct ast_channel *chan)
        ast_channel_lock(chan);
        seq_num = ast_atomic_fetchadd_int(&seq_num_last, +1);
        len = snprintf(dummy, sizeof(dummy), "%s<XFER_%x>", ast_channel_name(chan), seq_num) + 1;
-       chan_name = alloca(len);
+       chan_name = ast_alloca(len);
        snprintf(chan_name, len, "%s<XFER_%x>", ast_channel_name(chan), seq_num);
        ast_channel_unlock(chan);
 
@@ -2289,8 +2289,8 @@ static int builtin_automonitor(struct ast_channel *chan, struct ast_channel *pee
 
        if (touch_monitor) {
                len = strlen(touch_monitor) + 50;
-               args = alloca(len);
-               touch_filename = alloca(len);
+               args = ast_alloca(len);
+               touch_filename = ast_alloca(len);
                snprintf(touch_filename, len, "%s-%ld-%s", S_OR(touch_monitor_prefix, "auto"), (long)time(NULL), touch_monitor);
                snprintf(args, len, "%s,%s,m", S_OR(touch_format, "wav"), touch_filename);
        } else {
@@ -2299,8 +2299,8 @@ static int builtin_automonitor(struct ast_channel *chan, struct ast_channel *pee
                callee_chan_id = ast_strdupa(S_COR(ast_channel_caller(callee_chan)->id.number.valid,
                        ast_channel_caller(callee_chan)->id.number.str, ast_channel_name(callee_chan)));
                len = strlen(caller_chan_id) + strlen(callee_chan_id) + 50;
-               args = alloca(len);
-               touch_filename = alloca(len);
+               args = ast_alloca(len);
+               touch_filename = ast_alloca(len);
                snprintf(touch_filename, len, "%s-%ld-%s-%s", S_OR(touch_monitor_prefix, "auto"), (long)time(NULL), caller_chan_id, callee_chan_id);
                snprintf(args, len, "%s,%s,m", S_OR(touch_format, "wav"), touch_filename);
        }
@@ -2401,8 +2401,8 @@ static int builtin_automixmonitor(struct ast_channel *chan, struct ast_channel *
 
        if (touch_monitor) {
                len = strlen(touch_monitor) + 50;
-               args = alloca(len);
-               touch_filename = alloca(len);
+               args = ast_alloca(len);
+               touch_filename = ast_alloca(len);
                snprintf(touch_filename, len, "auto-%ld-%s", (long)time(NULL), touch_monitor);
                snprintf(args, len, "%s.%s,b", touch_filename, (touch_format) ? touch_format : "wav");
        } else {
@@ -2411,8 +2411,8 @@ static int builtin_automixmonitor(struct ast_channel *chan, struct ast_channel *
                callee_chan_id = ast_strdupa(S_COR(ast_channel_caller(callee_chan)->id.number.valid,
                        ast_channel_caller(callee_chan)->id.number.str, ast_channel_name(callee_chan)));
                len = strlen(caller_chan_id) + strlen(callee_chan_id) + 50;
-               args = alloca(len);
-               touch_filename = alloca(len);
+               args = ast_alloca(len);
+               touch_filename = ast_alloca(len);
                snprintf(touch_filename, len, "auto-%ld-%s-%s", (long)time(NULL), caller_chan_id, callee_chan_id);
                snprintf(args, len, "%s.%s,b", touch_filename, S_OR(touch_format, "wav"));
        }
@@ -3884,7 +3884,7 @@ static struct ast_channel *feature_request_and_dial(struct ast_channel *caller,
 
                disconnect_code = builtin_features[x].exten;
                len = strlen(disconnect_code) + 1;
-               dialed_code = alloca(len);
+               dialed_code = ast_alloca(len);
                memset(dialed_code, 0, len);
                break;
        }
index 3f52e0a..4c25b98 100644 (file)
@@ -689,9 +689,7 @@ struct ast_filestream *ast_openstream_full(struct ast_channel *chan, const char
        if (preflang == NULL)
                preflang = "";
        buflen = strlen(preflang) + strlen(filename) + 4;
-       buf = alloca(buflen);
-       if (buf == NULL)
-               return NULL;
+       buf = ast_alloca(buflen);
 
        if (!(file_fmt_cap = ast_format_cap_alloc_nolock())) {
                return NULL;
@@ -735,9 +733,7 @@ struct ast_filestream *ast_openvstream(struct ast_channel *chan, const char *fil
        if (preflang == NULL)
                preflang = "";
        buflen = strlen(preflang) + strlen(filename) + 4;
-       buf = alloca(buflen);
-       if (buf == NULL)
-               return NULL;
+       buf = ast_alloca(buflen);
 
        /* is the channel capable of video without translation ?*/
        if (!ast_format_cap_has_type(ast_channel_nativeformats(chan), AST_FORMAT_TYPE_VIDEO)) {
@@ -987,9 +983,7 @@ int ast_fileexists(const char *filename, const char *fmt, const char *preflang)
        if (preflang == NULL)
                preflang = "";
        buflen = strlen(preflang) + strlen(filename) + 4;       /* room for everything */
-       buf = alloca(buflen);
-       if (buf == NULL)
-               return 0;
+       buf = ast_alloca(buflen);
        return fileexists_core(filename, fmt, preflang, buf, buflen, NULL) ? 1 : 0;
 }
 
@@ -1168,7 +1162,7 @@ struct ast_filestream *ast_writefile(const char *filename, const char *type, con
                                        *c = '_';
 
                        size = strlen(fn) + strlen(record_cache_dir) + 2;
-                       buf = alloca(size);
+                       buf = ast_alloca(size);
                        strcpy(buf, record_cache_dir);
                        strcat(buf, "/");
                        strcat(buf, fn);
index 5bbeca3..2df8e9c 100644 (file)
@@ -251,7 +251,7 @@ static int static_callback(struct ast_tcptls_session_instance *ser,
                goto out403;
        }
 
-       path = alloca(len);
+       path = ast_alloca(len);
        sprintf(path, "%s/static-http/%s", ast_config_AST_DATA_DIR, uri);
        if (stat(path, &st)) {
                goto out404;
@@ -624,9 +624,7 @@ struct ast_variable *ast_http_get_post_vars(
                return NULL;
        }
 
-       if (!(buf = alloca(content_length))) {
-               return NULL;
-       }
+       buf = ast_alloca(content_length);
        if (!fgets(buf, content_length, ser->f)) {
                return NULL;
        }
@@ -767,7 +765,7 @@ cleanup:
 static HOOK_T ssl_write(void *cookie, const char *buf, LEN_T len)
 {
 #if 0
-       char *s = alloca(len+1);
+       char *s = ast_alloca(len+1);
        strncpy(s, buf, len);
        s[len] = '\0';
        ast_verbose("ssl write size %d <%s>\n", (int)len, s);
index 515e344..e856768 100644 (file)
@@ -1749,11 +1749,11 @@ void __ast_verbose_ap(const char *file, int line, const char *func, int level, s
                now = ast_tvnow();
                ast_localtime(&now, &tm, NULL);
                ast_strftime(date, sizeof(date), dateformat, &tm);
-               datefmt = alloca(strlen(date) + 3 + strlen(prefix) + strlen(fmt) + 1);
+               datefmt = ast_alloca(strlen(date) + 3 + strlen(prefix) + strlen(fmt) + 1);
                sprintf(datefmt, "%c[%s] %s%s", (char) magic, date, prefix, fmt);
                fmt = datefmt;
        } else {
-               char *tmp = alloca(strlen(prefix) + strlen(fmt) + 2);
+               char *tmp = ast_alloca(strlen(prefix) + strlen(fmt) + 2);
                sprintf(tmp, "%c%s%s", (char) magic, prefix, fmt);
                fmt = tmp;
        }
index c94e94c..84eb33d 100644 (file)
@@ -2694,7 +2694,7 @@ static void astman_append_json(struct mansession *s, const char *str)
 {
        char *buf;
 
-       buf = alloca(2 * strlen(str) + 1);
+       buf = ast_alloca(2 * strlen(str) + 1);
        json_escape(buf, str);
        astman_append(s, "%s", buf);
 }
index a1ed1b5..ef04d66 100644 (file)
@@ -4191,7 +4191,7 @@ void pbx_substitute_variables_helper_full(struct ast_channel *c, struct varshead
                        whereweare += (len + 3);
 
                        if (!var)
-                               var = alloca(VAR_BUF_SIZE);
+                               var = ast_alloca(VAR_BUF_SIZE);
 
                        /* Store variable name (and truncate) */
                        ast_copy_string(var, vars, len + 1);
@@ -4200,7 +4200,7 @@ void pbx_substitute_variables_helper_full(struct ast_channel *c, struct varshead
                        if (needsub) {
                                size_t used;
                                if (!ltmp)
-                                       ltmp = alloca(VAR_BUF_SIZE);
+                                       ltmp = ast_alloca(VAR_BUF_SIZE);
 
                                pbx_substitute_variables_helper_full(c, headp, var, ltmp, VAR_BUF_SIZE - 1, &used);
                                vars = ltmp;
@@ -4209,7 +4209,7 @@ void pbx_substitute_variables_helper_full(struct ast_channel *c, struct varshead
                        }
 
                        if (!workspace)
-                               workspace = alloca(VAR_BUF_SIZE);
+                               workspace = ast_alloca(VAR_BUF_SIZE);
 
                        workspace[0] = '\0';
 
@@ -4280,7 +4280,7 @@ void pbx_substitute_variables_helper_full(struct ast_channel *c, struct varshead
                        whereweare += (len + 3);
 
                        if (!var)
-                               var = alloca(VAR_BUF_SIZE);
+                               var = ast_alloca(VAR_BUF_SIZE);
 
                        /* Store variable name (and truncate) */
                        ast_copy_string(var, vars, len + 1);
@@ -4289,7 +4289,7 @@ void pbx_substitute_variables_helper_full(struct ast_channel *c, struct varshead
                        if (needsub) {
                                size_t used;
                                if (!ltmp)
-                                       ltmp = alloca(VAR_BUF_SIZE);
+                                       ltmp = ast_alloca(VAR_BUF_SIZE);
 
                                pbx_substitute_variables_helper_full(c, headp, var, ltmp, VAR_BUF_SIZE - 1, &used);
                                vars = ltmp;
@@ -4850,7 +4850,7 @@ static int handle_statechange(void *datap)
                return -1;
        }
 
-       cmpdevice = alloca(sizeof(*cmpdevice) + strlen(sc->dev));
+       cmpdevice = ast_alloca(sizeof(*cmpdevice) + strlen(sc->dev));
        strcpy(cmpdevice->hintdevice, sc->dev);
 
        ast_mutex_lock(&context_merge_lock);/* Hold off ast_merge_contexts_and_delete */
@@ -11046,11 +11046,9 @@ int pbx_builtin_importvar(struct ast_channel *chan, const char *data)
        if (channel && value && name) { /*! \todo XXX should do !ast_strlen_zero(..) of the args ? */
                struct ast_channel *chan2 = ast_channel_get_by_name(channel);
                if (chan2) {
-                       char *s = alloca(strlen(value) + 4);
-                       if (s) {
-                               sprintf(s, "${%s}", value);
-                               pbx_substitute_variables_helper(chan2, s, tmp, sizeof(tmp) - 1);
-                       }
+                       char *s = ast_alloca(strlen(value) + 4);
+                       sprintf(s, "${%s}", value);
+                       pbx_substitute_variables_helper(chan2, s, tmp, sizeof(tmp) - 1);
                        chan2 = ast_channel_unref(chan2);
                }
                pbx_builtin_setvar_helper(chan, name, tmp);
index 0f20d95..d8122e3 100644 (file)
@@ -8328,7 +8328,7 @@ int ast_say_counted_noun(struct ast_channel *chan, int num, const char noun[])
        } else {                                            /* English and default */
                ending = counted_noun_ending_en(num);
        }
-       temp = alloca((temp_len = (strlen(noun) + strlen(ending) + 1)));
+       temp = ast_alloca((temp_len = (strlen(noun) + strlen(ending) + 1)));
        snprintf(temp, temp_len, "%s%s", noun, ending);
        return ast_play_and_wait(chan, temp);
 }
@@ -8370,7 +8370,7 @@ int ast_say_counted_adjective(struct ast_channel *chan, int num, const char adje
        } else {                                               /* English and default */
                ending = "";
        }
-       temp = alloca((temp_len = (strlen(adjective) + strlen(ending) + 1)));
+       temp = ast_alloca((temp_len = (strlen(adjective) + strlen(ending) + 1)));
        snprintf(temp, temp_len, "%s%s", adjective, ending);
        return ast_play_and_wait(chan, temp);
 }
index 03c3041..dcd84d8 100644 (file)
@@ -68,12 +68,12 @@ int setenv(const char *name, const char *value, int overwrite)
        unsigned char *buf;
        int buflen;
 
-       buflen = strlen(name) + strlen(value) + 2;
-       buf = alloca(buflen);
-
        if (!overwrite && getenv(name))
                return 0;
 
+       buflen = strlen(name) + strlen(value) + 2;
+       buf = ast_alloca(buflen);
+
        snprintf(buf, buflen, "%s=%s", name, value);
 
        return putenv(buf);
@@ -105,23 +105,19 @@ static char *upper(const char *orig, char *buf, int bufsize)
 char *strcasestr(const char *haystack, const char *needle)
 {
        char *u1, *u2;
+       char *offset;
        int u1len = strlen(haystack) + 1, u2len = strlen(needle) + 1;
 
-       u1 = alloca(u1len);
-       u2 = alloca(u2len);
-       if (u1 && u2) {
-               char *offset;
-               if (u2len > u1len) {
-                       /* Needle bigger than haystack */
-                       return NULL;
-               }
-               offset = strstr(upper(haystack, u1, u1len), upper(needle, u2, u2len));
-               if (offset) {
-                       /* Return the offset into the original string */
-                       return ((char *)((unsigned long)haystack + (unsigned long)(offset - u1)));
-               } else {
-                       return NULL;
-               }
+       if (u2len > u1len) {
+               /* Needle bigger than haystack */
+               return NULL;
+       }
+       u1 = ast_alloca(u1len);
+       u2 = ast_alloca(u2len);
+       offset = strstr(upper(haystack, u1, u1len), upper(needle, u2, u2len));
+       if (offset) {
+               /* Return the offset into the original string */
+               return ((char *)((unsigned long)haystack + (unsigned long)(offset - u1)));
        } else {
                return NULL;
        }
index 8197265..2ad3a10 100644 (file)
@@ -71,7 +71,7 @@ static HOOK_T ssl_read(void *cookie, char *buf, LEN_T len)
 static HOOK_T ssl_write(void *cookie, const char *buf, LEN_T len)
 {
 #if 0
-       char *s = alloca(len+1);
+       char *s = ast_alloca(len+1);
 
        strncpy(s, buf, len);
        s[len] = '\0';
index 403045b..c89d107 100644 (file)
@@ -215,7 +215,7 @@ static char *handle_cli_threadstorage_show_summary(struct ast_cli_entry *e, int
                }
 
                if (!file) {
-                       file = alloca(sizeof(*file));
+                       file = ast_alloca(sizeof(*file));
                        memset(file, 0, sizeof(*file));
                        file->name = fn ? to->function : to->file;
                        AST_LIST_INSERT_TAIL(&file_summary, file, entry);
index 395d2d1..e52c819 100644 (file)
@@ -1041,7 +1041,7 @@ int ast_pthread_create_stack(pthread_t *thread, pthread_attr_t *attr, void *(*st
 #endif
 
        if (!attr) {
-               attr = alloca(sizeof(*attr));
+               attr = ast_alloca(sizeof(*attr));
                pthread_attr_init(attr);
        }
 
@@ -1089,7 +1089,7 @@ int ast_pthread_create_detached_stack(pthread_t *thread, pthread_attr_t *attr, v
        int res;
 
        if (!attr) {
-               attr = alloca(sizeof(*attr));
+               attr = ast_alloca(sizeof(*attr));
                pthread_attr_init(attr);
                attr_destroy = 1;
        }
@@ -1982,7 +1982,7 @@ int ast_mkdir(const char *path, int mode)
        int len = strlen(path), count = 0, x, piececount = 0;
        char *tmp = ast_strdupa(path);
        char **pieces;
-       char *fullpath = alloca(len + 1);
+       char *fullpath = ast_alloca(len + 1);
        int res = 0;
 
        for (ptr = tmp; *ptr; ptr++) {
@@ -1991,7 +1991,7 @@ int ast_mkdir(const char *path, int mode)
        }
 
        /* Count the components to the directory path */
-       pieces = alloca(count * sizeof(*pieces));
+       pieces = ast_alloca(count * sizeof(*pieces));
        for (ptr = tmp; *ptr; ptr++) {
                if (*ptr == '/') {
                        *ptr = '\0';
index 94a6212..5c42732 100644 (file)
@@ -165,7 +165,7 @@ static int pbx_load_module(void)
        if (config[0] == '/')
                rfilename = (char *)config;
        else {
-               rfilename = alloca(strlen(config) + strlen(ast_config_AST_CONFIG_DIR) + 2);
+               rfilename = ast_alloca(strlen(config) + strlen(ast_config_AST_CONFIG_DIR) + 2);
                sprintf(rfilename, "%s/%s", ast_config_AST_CONFIG_DIR, config);
        }
        if (access(rfilename,R_OK) != 0) {
index 5243083..25871b1 100644 (file)
@@ -1390,9 +1390,7 @@ static struct dundi_hdr *dundi_decrypt(struct dundi_transaction *trans, unsigned
        unsigned long bytes;
        struct dundi_hdr *h;
        unsigned char *decrypt_space;
-       decrypt_space = alloca(srclen);
-       if (!decrypt_space)
-               return NULL;
+       decrypt_space = ast_alloca(srclen);
        decrypt_memcpy(decrypt_space, src->encdata, srclen, src->iv, &trans->dcx);
        /* Setup header */
        h = (struct dundi_hdr *)dst;
@@ -1418,61 +1416,58 @@ static int dundi_encrypt(struct dundi_transaction *trans, struct dundi_packet *p
        struct dundi_peer *peer;
        unsigned char iv[16];
        len = pack->datalen + pack->datalen / 100 + 42;
-       compress_space = alloca(len);
-       if (compress_space) {
-               memset(compress_space, 0, len);
-               /* We care about everthing save the first 6 bytes of header */
-               bytes = len;
-               res = compress(compress_space, &bytes, pack->data + 6, pack->datalen - 6);
-               if (res != Z_OK) {
-                       ast_debug(1, "Ouch, compression failed!\n");
+       compress_space = ast_alloca(len);
+       memset(compress_space, 0, len);
+       /* We care about everthing save the first 6 bytes of header */
+       bytes = len;
+       res = compress(compress_space, &bytes, pack->data + 6, pack->datalen - 6);
+       if (res != Z_OK) {
+               ast_debug(1, "Ouch, compression failed!\n");
+               return -1;
+       }
+       memset(&ied, 0, sizeof(ied));
+       /* Say who we are */
+       if (!pack->h->iseqno && !pack->h->oseqno) {
+               /* Need the key in the first copy */
+               if (!(peer = find_peer(&trans->them_eid)))
                        return -1;
-               }
-               memset(&ied, 0, sizeof(ied));
-               /* Say who we are */
-               if (!pack->h->iseqno && !pack->h->oseqno) {
-                       /* Need the key in the first copy */
-                       if (!(peer = find_peer(&trans->them_eid)))
-                               return -1;
-                       if (update_key(peer))
-                               return -1;
-                       if (!peer->sentfullkey)
-                               ast_set_flag(trans, FLAG_SENDFULLKEY);
-                       /* Append key data */
-                       dundi_ie_append_eid(&ied, DUNDI_IE_EID, &trans->us_eid);
-                       if (ast_test_flag(trans, FLAG_SENDFULLKEY)) {
-                               dundi_ie_append_raw(&ied, DUNDI_IE_SHAREDKEY, peer->txenckey, 128);
-                               dundi_ie_append_raw(&ied, DUNDI_IE_SIGNATURE, peer->txenckey + 128, 128);
-                       } else {
-                               dundi_ie_append_int(&ied, DUNDI_IE_KEYCRC32, peer->us_keycrc32);
-                       }
-                       /* Setup contexts */
-                       trans->ecx = peer->us_ecx;
-                       trans->dcx = peer->us_dcx;
-
-                       /* We've sent the full key */
-                       peer->sentfullkey = 1;
-               }
-               /* Build initialization vector */
-               build_iv(iv);
-               /* Add the field, rounded up to 16 bytes */
-               dundi_ie_append_encdata(&ied, DUNDI_IE_ENCDATA, iv, NULL, ((bytes + 15) / 16) * 16);
-               /* Copy the data */
-               if ((ied.pos + bytes) >= sizeof(ied.buf)) {
-                       ast_log(LOG_NOTICE, "Final packet too large!\n");
+               if (update_key(peer))
                        return -1;
+               if (!peer->sentfullkey)
+                       ast_set_flag(trans, FLAG_SENDFULLKEY);
+               /* Append key data */
+               dundi_ie_append_eid(&ied, DUNDI_IE_EID, &trans->us_eid);
+               if (ast_test_flag(trans, FLAG_SENDFULLKEY)) {
+                       dundi_ie_append_raw(&ied, DUNDI_IE_SHAREDKEY, peer->txenckey, 128);
+                       dundi_ie_append_raw(&ied, DUNDI_IE_SIGNATURE, peer->txenckey + 128, 128);
+               } else {
+                       dundi_ie_append_int(&ied, DUNDI_IE_KEYCRC32, peer->us_keycrc32);
                }
-               encrypt_memcpy(ied.buf + ied.pos, compress_space, bytes, iv, &trans->ecx);
-               ied.pos += ((bytes + 15) / 16) * 16;
-               /* Reconstruct header */
-               pack->datalen = sizeof(struct dundi_hdr);
-               pack->h->cmdresp = DUNDI_COMMAND_ENCRYPT;
-               pack->h->cmdflags = 0;
-               memcpy(pack->h->ies, ied.buf, ied.pos);
-               pack->datalen += ied.pos;
-               return 0;
+               /* Setup contexts */
+               trans->ecx = peer->us_ecx;
+               trans->dcx = peer->us_dcx;
+
+               /* We've sent the full key */
+               peer->sentfullkey = 1;
+       }
+       /* Build initialization vector */
+       build_iv(iv);
+       /* Add the field, rounded up to 16 bytes */
+       dundi_ie_append_encdata(&ied, DUNDI_IE_ENCDATA, iv, NULL, ((bytes + 15) / 16) * 16);
+       /* Copy the data */
+       if ((ied.pos + bytes) >= sizeof(ied.buf)) {
+               ast_log(LOG_NOTICE, "Final packet too large!\n");
+               return -1;
        }
-       return -1;
+       encrypt_memcpy(ied.buf + ied.pos, compress_space, bytes, iv, &trans->ecx);
+       ied.pos += ((bytes + 15) / 16) * 16;
+       /* Reconstruct header */
+       pack->datalen = sizeof(struct dundi_hdr);
+       pack->h->cmdresp = DUNDI_COMMAND_ENCRYPT;
+       pack->h->cmdflags = 0;
+       memcpy(pack->h->ies, ied.buf, ied.pos);
+       pack->datalen += ied.pos;
+       return 0;
 }
 
 static int check_key(struct dundi_peer *peer, unsigned char *newkey, unsigned char *newsig, uint32_t keycrc32)
@@ -1589,10 +1584,7 @@ static int handle_command_response(struct dundi_transaction *trans, struct dundi
        }
 
        if (datalen) {
-               bufcpy = alloca(datalen);
-               if (!bufcpy) {
-                       goto return_cleanup;
-               }
+               bufcpy = ast_alloca(datalen);
                /* Make a copy for parsing */
                memcpy(bufcpy, hdr->ies, datalen);
                ast_debug(1, "Got canonical message %d (%d), %d bytes data%s\n", cmd, hdr->oseqno, datalen, final ? " (Final)" : "");
@@ -3774,18 +3766,17 @@ static int dundi_precache_internal(const char *context, const char *number, int
                        nummaps++;
        }
        if (nummaps) {
-               maps = alloca(nummaps * sizeof(*maps));
+               maps = ast_alloca(nummaps * sizeof(*maps));
                nummaps = 0;
-               if (maps) {
-                       AST_LIST_TRAVERSE(&mappings, cur, list) {
-                               if (!strcasecmp(cur->dcontext, context))
-                                       maps[nummaps++] = *cur;
-                       }
+               AST_LIST_TRAVERSE(&mappings, cur, list) {
+                       if (!strcasecmp(cur->dcontext, context))
+                               maps[nummaps++] = *cur;
                }
        }
        AST_LIST_UNLOCK(&peers);
-       if (!nummaps || !maps)
+       if (!nummaps) {
                return -1;
+       }
        ttlms = DUNDI_FLUFF_TIME + ttl * DUNDI_TTL_TIME;
        memset(&dr2, 0, sizeof(dr2));
        memset(&dr, 0, sizeof(dr));
index 9288616..1b91827 100644 (file)
@@ -303,7 +303,7 @@ static int lua_get_variable_value(lua_State *L)
 {
        struct ast_channel *chan;
        char *value = NULL, *name;
-       char *workspace = alloca(LUA_BUF_SIZE);
+       char *workspace = ast_alloca(LUA_BUF_SIZE);
        int autoservice;
 
        workspace[0] = '\0';
@@ -561,7 +561,7 @@ static int lua_get_variable(lua_State *L)
        struct ast_channel *chan;
        const char *name = luaL_checkstring(L, 2);
        char *value = NULL;
-       char *workspace = alloca(LUA_BUF_SIZE);
+       char *workspace = ast_alloca(LUA_BUF_SIZE);
        workspace[0] = '\0';
        
        lua_getfield(L, LUA_REGISTRYINDEX, "channel");
@@ -1080,7 +1080,7 @@ static char *lua_read_extensions_file(lua_State *L, long *size)
        FILE *f;
        int error_func;
        char *data;
-       char *path = alloca(strlen(config) + strlen(ast_config_AST_CONFIG_DIR) + 2);
+       char *path = ast_alloca(strlen(config) + strlen(ast_config_AST_CONFIG_DIR) + 2);
        sprintf(path, "%s/%s", ast_config_AST_CONFIG_DIR, config);
 
        if (!(f = fopen(path, "r"))) {
index fb2f413..3808483 100644 (file)
@@ -228,52 +228,50 @@ static struct ast_variable *realtime_common(const char *context, const char *ext
                char exten[AST_MAX_EXTENSION];
        } cache_search = { { .priority = priority, .context = (char *) context }, };
        char *buf = ast_strdupa(data);
-       if (buf) {
-               /* "Realtime" prefix is stripped off in the parent engine.  The
-                * remaining string is: [[context@]table][/opts] */
-               char *opts = strchr(buf, '/');
-               if (opts)
-                       *opts++ = '\0';
-               table = strchr(buf, '@');
-               if (table) {
-                       *table++ = '\0';
-                       ctx = buf;
-               }
-               ctx = S_OR(ctx, context);
-               table = S_OR(table, "extensions");
-               if (!ast_strlen_zero(opts)) {
-                       ast_app_parse_options(switch_opts, &flags, NULL, opts);
-               }
-               ast_copy_string(cache_search.exten, exten, sizeof(cache_search.exten));
-               if (mode == MODE_MATCH && (ce = ao2_find(cache, &cache_search, OBJ_POINTER))) {
-                       var = dup_vars(ce->var);
+       /* "Realtime" prefix is stripped off in the parent engine.  The
+        * remaining string is: [[context@]table][/opts] */
+       char *opts = strchr(buf, '/');
+       if (opts)
+               *opts++ = '\0';
+       table = strchr(buf, '@');
+       if (table) {
+               *table++ = '\0';
+               ctx = buf;
+       }
+       ctx = S_OR(ctx, context);
+       table = S_OR(table, "extensions");
+       if (!ast_strlen_zero(opts)) {
+               ast_app_parse_options(switch_opts, &flags, NULL, opts);
+       }
+       ast_copy_string(cache_search.exten, exten, sizeof(cache_search.exten));
+       if (mode == MODE_MATCH && (ce = ao2_find(cache, &cache_search, OBJ_POINTER))) {
+               var = dup_vars(ce->var);
+               ao2_ref(ce, -1);
+       } else {
+               var = realtime_switch_common(table, ctx, exten, priority, mode, flags);
+               do {
+                       struct ast_variable *new;
+                       /* Only cache matches */
+                       if (mode != MODE_MATCH) {
+                               break;
+                       }
+                       if (!(new = dup_vars(var))) {
+                               break;
+                       }
+                       if (!(ce = ao2_alloc(sizeof(*ce) + strlen(exten) + strlen(context), free_entry))) {
+                               ast_variables_destroy(new);
+                               break;
+                       }
+                       ce->context = ce->exten + strlen(exten) + 1;
+                       strcpy(ce->exten, exten); /* SAFE */
+                       strcpy(ce->context, context); /* SAFE */
+                       ce->priority = priority;
+                       ce->var = new;
+                       ce->when = ast_tvnow();
+                       ao2_link(cache, ce);
+                       pthread_kill(cleanup_thread, SIGURG);
                        ao2_ref(ce, -1);
-               } else {
-                       var = realtime_switch_common(table, ctx, exten, priority, mode, flags);
-                       do {
-                               struct ast_variable *new;
-                               /* Only cache matches */
-                               if (mode != MODE_MATCH) {
-                                       break;
-                               }
-                               if (!(new = dup_vars(var))) {
-                                       break;
-                               }
-                               if (!(ce = ao2_alloc(sizeof(*ce) + strlen(exten) + strlen(context), free_entry))) {
-                                       ast_variables_destroy(new);
-                                       break;
-                               }
-                               ce->context = ce->exten + strlen(exten) + 1;
-                               strcpy(ce->exten, exten); /* SAFE */
-                               strcpy(ce->context, context); /* SAFE */
-                               ce->priority = priority;
-                               ce->var = new;
-                               ce->when = ast_tvnow();
-                               ao2_link(cache, ce);
-                               pthread_kill(cleanup_thread, SIGURG);
-                               ao2_ref(ce, -1);
-                       } while (0);
-               }
+               } while (0);
        }
        return var;
 }
@@ -315,7 +313,7 @@ static int realtime_exec(struct ast_channel *chan, const char *context, const ch
                                if (ast_compat_pbx_realtime) {
                                        char *ptr;
                                        int in = 0;
-                                       tmp = alloca(strlen(v->value) * 2 + 1);
+                                       tmp = ast_alloca(strlen(v->value) * 2 + 1);
                                        for (ptr = tmp; *v->value; v->value++) {
                                                if (*v->value == ',') {
                                                        *ptr++ = '\\';
index e176b95..43bac62 100644 (file)
@@ -486,7 +486,7 @@ static void queue_file(const char *filename, time_t when)
        time_t now = time(NULL);
 
        if (filename[0] != '/') {
-               char *fn = alloca(strlen(qdir) + strlen(filename) + 2);
+               char *fn = ast_alloca(strlen(qdir) + strlen(filename) + 2);
                sprintf(fn, "%s/%s", qdir, filename); /* SAFE */
                filename = fn;
        }
index ff425f5..70bd689 100644 (file)
@@ -2902,7 +2902,7 @@ void ael2_semantic_check(pval *item, int *arg_errs, int *arg_warns, int *arg_not
        if (!item)
                return; /* don't check an empty tree */
 #ifdef AAL_ARGCHECK
-       rfilename = alloca(10 + strlen(ast_config_AST_VAR_DIR));
+       rfilename = ast_alloca(10 + strlen(ast_config_AST_VAR_DIR));
        sprintf(rfilename, "%s/applist", ast_config_AST_VAR_DIR);
        
        apps = argdesc_parse(rfilename, &argapp_errs); /* giveth */
index 328674c..6f7675f 100644 (file)
@@ -1571,10 +1571,11 @@ static enum agi_result launch_ha_netscript(char *agiurl, char *argv[], int *fds)
        unsigned short srvport;
 
        /* format of agiurl is "hagi://host.domain[:port][/script/name]" */
-       if (!(host = ast_strdupa(agiurl + 7))) { /* Remove hagi:// */
+       if (strlen(agiurl) < 7) { /* Remove hagi:// */
                ast_log(LOG_WARNING, "An error occurred parsing the AGI URI: %s", agiurl);
                return AGI_RESULT_FAILURE;
        }
+       host = ast_strdupa(agiurl + 7);
 
        /* Strip off any script name */
        if ((script = strchr(host, '/'))) {
@@ -2500,7 +2501,7 @@ static int handle_exec(struct ast_channel *chan, AGI *agi, int argc, const char
                        ast_set_flag(ast_channel_flags(chan), AST_FLAG_DISABLE_WORKAROUNDS);
                }
                if (ast_compat_res_agi && argc >= 3 && !ast_strlen_zero(argv[2])) {
-                       char *compat = alloca(strlen(argv[2]) * 2 + 1), *cptr;
+                       char *compat = ast_alloca(strlen(argv[2]) * 2 + 1), *cptr;
                        const char *vptr;
                        for (cptr = compat, vptr = argv[2]; *vptr; vptr++) {
                                if (*vptr == ',') {
index 02c76fc..bafa271 100644 (file)
@@ -290,7 +290,7 @@ static struct tables *find_table(const char *database, const char *orig_tablenam
                if (strchr(schemaname, '\\') || strchr(schemaname, '\'')) {
                        char *tmp = schemaname, *ptr;
 
-                       ptr = schemaname = alloca(strlen(tmp) * 2 + 1);
+                       ptr = schemaname = ast_alloca(strlen(tmp) * 2 + 1);
                        for (; *tmp; tmp++) {
                                if (strchr("\\'", *tmp)) {
                                        *ptr++ = *tmp;
@@ -303,7 +303,7 @@ static struct tables *find_table(const char *database, const char *orig_tablenam
                if (strchr(tablename, '\\') || strchr(tablename, '\'')) {
                        char *tmp = tablename, *ptr;
 
-                       ptr = tablename = alloca(strlen(tmp) * 2 + 1);
+                       ptr = tablename = ast_alloca(strlen(tmp) * 2 + 1);
                        for (; *tmp; tmp++) {
                                if (strchr("\\'", *tmp)) {
                                        *ptr++ = *tmp;
@@ -322,7 +322,7 @@ static struct tables *find_table(const char *database, const char *orig_tablenam
                        const char *tmp = orig_tablename;
                        char *ptr;
 
-                       orig_tablename = ptr = alloca(strlen(tmp) * 2 + 1);
+                       orig_tablename = ptr = ast_alloca(strlen(tmp) * 2 + 1);
                        for (; *tmp; tmp++) {
                                if (strchr("\\'", *tmp)) {
                                        *ptr++ = *tmp;
index c5fcdee..86e2a82 100644 (file)
@@ -208,7 +208,7 @@ int ast_websocket_write(struct ast_websocket *session, enum ast_websocket_opcode
                header_size += 8;
        }
 
-       frame = alloca(header_size);
+       frame = ast_alloca(header_size);
        memset(frame, 0, sizeof(*frame));
 
        frame[0] = opcode | 0x80;
index c160266..9cab2f1 100644 (file)
@@ -1585,8 +1585,8 @@ static int aji_start_sasl(struct aji_client *client, enum ikssasltype type, char
 
        iks_insert_attrib(x, "xmlns", IKS_NS_XMPP_SASL);
        len = strlen(username) + strlen(pass) + 3;
-       s = alloca(len);
-       base64 = alloca((len + 2) * 4 / 3);
+       s = ast_alloca(len);
+       base64 = ast_alloca((len + 2) * 4 / 3);
        iks_insert_attrib(x, "mechanism", "PLAIN");
        snprintf(s, len, "%c%s%c%s", 0, username, 0, pass);
 
index 2200513..2aee5c9 100644 (file)
@@ -150,7 +150,7 @@ AST_TEST_DEFINE(single_ll_tests)
                return AST_TEST_FAIL;
        }
 
-       if (!(bogus = alloca(sizeof(*bogus)))) {
+       if (!(bogus = ast_alloca(sizeof(*bogus)))) {
                return AST_TEST_FAIL;
        }
 
@@ -361,9 +361,7 @@ AST_TEST_DEFINE(double_ll_tests)
                return AST_TEST_FAIL;
        }
 
-       if (!(bogus = alloca(sizeof(*bogus)))) {
-               return AST_TEST_FAIL;
-       }
+       bogus = ast_alloca(sizeof(*bogus));
 
        if (AST_DLLIST_REMOVE_VERIFY(&test_list, bogus, dbl_list)) {
                ast_test_status_update(test, "AST_DLLIST_REMOVE_VERIFY should safely return NULL for missing element from empty list\n");
index 8245a16..7e08aef 100644 (file)
@@ -5812,7 +5812,7 @@ static void pbx_substitute_variables_helper_full(struct ast_channel *c, struct v
                        whereweare += (len + 3);
 
                        if (!var)
-                               var = alloca(VAR_BUF_SIZE);
+                               var = ast_alloca(VAR_BUF_SIZE);
 
                        /* Store variable name (and truncate) */
                        ast_copy_string(var, vars, len + 1);
@@ -5820,7 +5820,7 @@ static void pbx_substitute_variables_helper_full(struct ast_channel *c, struct v
                        /* Substitute if necessary */
                        if (needsub) {
                                if (!ltmp)
-                                       ltmp = alloca(VAR_BUF_SIZE);
+                                       ltmp = ast_alloca(VAR_BUF_SIZE);
 
                                memset(ltmp, 0, VAR_BUF_SIZE);
                                pbx_substitute_variables_helper_full(c, headp, var, ltmp, VAR_BUF_SIZE - 1);
@@ -5830,7 +5830,7 @@ static void pbx_substitute_variables_helper_full(struct ast_channel *c, struct v
                        }
 
                        if (!workspace)
-                               workspace = alloca(VAR_BUF_SIZE);
+                               workspace = ast_alloca(VAR_BUF_SIZE);
 
                        workspace[0] = '\0';
 
@@ -5887,7 +5887,7 @@ static void pbx_substitute_variables_helper_full(struct ast_channel *c, struct v
                        whereweare += (len + 3);
 
                        if (!var)
-                               var = alloca(VAR_BUF_SIZE);
+                               var = ast_alloca(VAR_BUF_SIZE);
 
                        /* Store variable name (and truncate) */
                        ast_copy_string(var, vars, len + 1);
@@ -5895,7 +5895,7 @@ static void pbx_substitute_variables_helper_full(struct ast_channel *c, struct v
                        /* Substitute if necessary */
                        if (needsub) {
                                if (!ltmp)
-                                       ltmp = alloca(VAR_BUF_SIZE);
+                                       ltmp = ast_alloca(VAR_BUF_SIZE);
 
                                memset(ltmp, 0, VAR_BUF_SIZE);
                                pbx_substitute_variables_helper_full(c, headp, var, ltmp, VAR_BUF_SIZE - 1);