summaryrefslogtreecommitdiff
path: root/pbx
diff options
context:
space:
mode:
authorKinsey Moore <kmoore@digium.com>2012-07-31 20:21:43 +0000
committerKinsey Moore <kmoore@digium.com>2012-07-31 20:21:43 +0000
commit9b16c8b0f6c3b6310e303411421bfcb16b26c3c4 (patch)
tree273c31a834a21bd2239ec6b83cd35c602ea25d26 /pbx
parent6c23a60f802e7708389b1a6463a40dc0500512bd (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 'pbx')
-rw-r--r--pbx/pbx_ael.c2
-rw-r--r--pbx/pbx_dundi.c121
-rw-r--r--pbx/pbx_lua.c6
-rw-r--r--pbx/pbx_realtime.c90
-rw-r--r--pbx/pbx_spool.c2
5 files changed, 105 insertions, 116 deletions
diff --git a/pbx/pbx_ael.c b/pbx/pbx_ael.c
index 94a6212fa..5c42732bf 100644
--- a/pbx/pbx_ael.c
+++ b/pbx/pbx_ael.c
@@ -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) {
diff --git a/pbx/pbx_dundi.c b/pbx/pbx_dundi.c
index 52430838a..25871b1fb 100644
--- a/pbx/pbx_dundi.c
+++ b/pbx/pbx_dundi.c
@@ -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));
diff --git a/pbx/pbx_lua.c b/pbx/pbx_lua.c
index 928861698..1b9182794 100644
--- a/pbx/pbx_lua.c
+++ b/pbx/pbx_lua.c
@@ -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"))) {
diff --git a/pbx/pbx_realtime.c b/pbx/pbx_realtime.c
index fb2f41320..3808483ad 100644
--- a/pbx/pbx_realtime.c
+++ b/pbx/pbx_realtime.c
@@ -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++ = '\\';
diff --git a/pbx/pbx_spool.c b/pbx/pbx_spool.c
index e176b95c4..43bac620e 100644
--- a/pbx/pbx_spool.c
+++ b/pbx/pbx_spool.c
@@ -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;
}