diff options
author | Kinsey Moore <kmoore@digium.com> | 2012-07-31 20:21:43 +0000 |
---|---|---|
committer | Kinsey Moore <kmoore@digium.com> | 2012-07-31 20:21:43 +0000 |
commit | 9b16c8b0f6c3b6310e303411421bfcb16b26c3c4 (patch) | |
tree | 273c31a834a21bd2239ec6b83cd35c602ea25d26 /main | |
parent | 6c23a60f802e7708389b1a6463a40dc0500512bd (diff) |
Clean up and ensure proper usage of alloca()
This replaces all calls to alloca() with ast_alloca() which calls gcc's
__builtin_alloca() to avoid BSD semantics and removes all NULL checks
on memory allocated via ast_alloca() and ast_strdupa().
(closes issue ASTERISK-20125)
Review: https://reviewboard.asterisk.org/r/2032/
Patch-by: Walter Doekes (wdoekes)
........
Merged revisions 370642 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
Merged revisions 370643 from http://svn.asterisk.org/svn/asterisk/branches/10
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@370655 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main')
-rw-r--r-- | main/app.c | 12 | ||||
-rw-r--r-- | main/asterisk.c | 2 | ||||
-rw-r--r-- | main/astmm.c | 2 | ||||
-rw-r--r-- | main/callerid.c | 4 | ||||
-rw-r--r-- | main/channel.c | 6 | ||||
-rw-r--r-- | main/config.c | 4 | ||||
-rw-r--r-- | main/db.c | 2 | ||||
-rw-r--r-- | main/dsp.c | 8 | ||||
-rw-r--r-- | main/event.c | 10 | ||||
-rw-r--r-- | main/features.c | 20 | ||||
-rw-r--r-- | main/file.c | 14 | ||||
-rw-r--r-- | main/http.c | 8 | ||||
-rw-r--r-- | main/logger.c | 4 | ||||
-rw-r--r-- | main/manager.c | 2 | ||||
-rw-r--r-- | main/pbx.c | 20 | ||||
-rw-r--r-- | main/say.c | 4 | ||||
-rw-r--r-- | main/strcompat.c | 32 | ||||
-rw-r--r-- | main/tcptls.c | 2 | ||||
-rw-r--r-- | main/threadstorage.c | 2 | ||||
-rw-r--r-- | main/utils.c | 8 |
20 files changed, 76 insertions, 90 deletions
diff --git a/main/app.c b/main/app.c index f6a3095d2..c8cb29c90 100644 --- a/main/app.c +++ b/main/app.c @@ -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) { diff --git a/main/asterisk.c b/main/asterisk.c index e06d70a4a..8e6d1a486 100644 --- a/main/asterisk.c +++ b/main/asterisk.c @@ -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)); diff --git a/main/astmm.c b/main/astmm.c index 125eb8c1d..741358205 100644 --- a/main/astmm.c +++ b/main/astmm.c @@ -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; diff --git a/main/callerid.c b/main/callerid.c index 3af60bd3d..d9f74180a 100644 --- a/main/callerid.c +++ b/main/callerid.c @@ -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; diff --git a/main/channel.c b/main/channel.c index f2660e1fd..fdb4f005d 100644 --- a/main/channel.c +++ b/main/channel.c @@ -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); diff --git a/main/config.c b/main/config.c index fee6d9eb7..9abc6020d 100644 --- a/main/config.c +++ b/main/config.c @@ -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); } @@ -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); diff --git a/main/dsp.c b/main/dsp.c index c5da2dfba..33db5055f 100644 --- a/main/dsp.c +++ b/main/dsp.c @@ -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]); } diff --git a/main/event.c b/main/event.c index 7470eaddd..23e20f333 100644 --- a/main/event.c +++ b/main/event.c @@ -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; diff --git a/main/features.c b/main/features.c index dd62c0c7f..5d0f8ec5d 100644 --- a/main/features.c +++ b/main/features.c @@ -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; } diff --git a/main/file.c b/main/file.c index 3f52e0aab..4c25b987a 100644 --- a/main/file.c +++ b/main/file.c @@ -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); diff --git a/main/http.c b/main/http.c index 5bbeca33e..2df8e9c26 100644 --- a/main/http.c +++ b/main/http.c @@ -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); diff --git a/main/logger.c b/main/logger.c index 515e3447f..e85676857 100644 --- a/main/logger.c +++ b/main/logger.c @@ -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; } diff --git a/main/manager.c b/main/manager.c index c94e94ca2..84eb33d16 100644 --- a/main/manager.c +++ b/main/manager.c @@ -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); } diff --git a/main/pbx.c b/main/pbx.c index a1ed1b52d..ef04d6644 100644 --- a/main/pbx.c +++ b/main/pbx.c @@ -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); diff --git a/main/say.c b/main/say.c index 0f20d9536..d8122e3da 100644 --- a/main/say.c +++ b/main/say.c @@ -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); } diff --git a/main/strcompat.c b/main/strcompat.c index 03c304144..dcd84d876 100644 --- a/main/strcompat.c +++ b/main/strcompat.c @@ -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; } diff --git a/main/tcptls.c b/main/tcptls.c index 81972651e..2ad3a10e4 100644 --- a/main/tcptls.c +++ b/main/tcptls.c @@ -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'; diff --git a/main/threadstorage.c b/main/threadstorage.c index 403045bd8..c89d1078d 100644 --- a/main/threadstorage.c +++ b/main/threadstorage.c @@ -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); diff --git a/main/utils.c b/main/utils.c index 395d2d1d2..e52c8190e 100644 --- a/main/utils.c +++ b/main/utils.c @@ -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'; |