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 */
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");
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';
}
}
initfield = ast_strdupa(newparam);
- if (initfield && (op = strchr(initfield, ' '))) {
+ if ((op = strchr(initfield, ' '))) {
*op = '\0';
}
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 {
* 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;
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') {
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...");
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';
return -1;
}
- if (!(localdata = ast_strdupa(data)))
- return -1;
+ localdata = ast_strdupa(data);
AST_STANDARD_APP_ARGS(args, localdata);
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);
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]))
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])) {
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) {
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) {
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, ""))) {
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) {
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';
*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++;
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';
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;
}
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);
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);
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);
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);
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);
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 */
}
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))) {
} 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");
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
*/
int cmd;
char *buf;
- buf = alloca(strlen(box) + 2);
+ buf = ast_alloca(strlen(box) + 2);
strcpy(buf, box);
strcat(buf, "s");
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);
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;
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;
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;
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));
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);
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);
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;
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;
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);
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);
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));
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;
}
}
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)
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;
{
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)
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;
/* 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;
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) {
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, ""))) {
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;
}
}
/* 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);
}
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,
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,
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;
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);
}
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) {
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);
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));
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));
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) {
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));
/* 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);
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);
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);
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);
}
}
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);
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);
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. */
}
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) {
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);
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);
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~");
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);
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);
/*! \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.
*/
#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; \
#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
}
if (blen > 2) {
- breaks = alloca(blen + 1);
+ breaks = ast_alloca(blen + 1);
breaks[0] = '\0';
if (stop) {
strcat(breaks, stop);
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);
char *s;
int res;
- s = alloca(strlen(path) + 10);
+ s = ast_alloca(strlen(path) + 10);
snprintf(s, strlen(path) + 9, "%s/%s", path, ".lock");
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) {
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) {
}
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));
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;
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;
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;
}
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;
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);
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);
}
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);
}
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);
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]);
}
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]);
}
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));
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;
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) {
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));
{
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;
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);
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 {
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);
}
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 {
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"));
}
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;
}
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;
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)) {
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;
}
*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);
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;
return NULL;
}
- if (!(buf = alloca(content_length))) {
- return NULL;
- }
+ buf = ast_alloca(content_length);
if (!fgets(buf, content_length, ser->f)) {
return NULL;
}
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);
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;
}
{
char *buf;
- buf = alloca(2 * strlen(str) + 1);
+ buf = ast_alloca(2 * strlen(str) + 1);
json_escape(buf, str);
astman_append(s, "%s", buf);
}
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);
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;
}
if (!workspace)
- workspace = alloca(VAR_BUF_SIZE);
+ workspace = ast_alloca(VAR_BUF_SIZE);
workspace[0] = '\0';
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);
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;
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 */
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);
} 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);
}
} 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);
}
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);
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;
}
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';
}
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);
#endif
if (!attr) {
- attr = alloca(sizeof(*attr));
+ attr = ast_alloca(sizeof(*attr));
pthread_attr_init(attr);
}
int res;
if (!attr) {
- attr = alloca(sizeof(*attr));
+ attr = ast_alloca(sizeof(*attr));
pthread_attr_init(attr);
attr_destroy = 1;
}
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++) {
}
/* 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';
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) {
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;
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)
}
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)" : "");
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));
{
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';
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");
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"))) {
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;
}
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++ = '\\';
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;
}
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 */
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, '/'))) {
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 == ',') {
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;
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;
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;
header_size += 8;
}
- frame = alloca(header_size);
+ frame = ast_alloca(header_size);
memset(frame, 0, sizeof(*frame));
frame[0] = opcode | 0x80;
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);
return AST_TEST_FAIL;
}
- if (!(bogus = alloca(sizeof(*bogus)))) {
+ if (!(bogus = ast_alloca(sizeof(*bogus)))) {
return AST_TEST_FAIL;
}
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");
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);
/* 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);
}
if (!workspace)
- workspace = alloca(VAR_BUF_SIZE);
+ workspace = ast_alloca(VAR_BUF_SIZE);
workspace[0] = '\0';
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);
/* 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);