]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
various files - fix some alerts raised by lgtm code analysis
authorKevin Harwell <kharwell@digium.com>
Wed, 23 Oct 2019 21:34:27 +0000 (16:34 -0500)
committerKevin Harwell <kharwell@digium.com>
Tue, 12 Nov 2019 00:11:27 +0000 (18:11 -0600)
This patch fixes several issues reported by the lgtm code analysis tool:

https://lgtm.com/projects/g/asterisk/asterisk

Not all reported issues were addressed in this patch. This patch mostly fixes
confirmed reported errors, potential problematic code points, and a few other
"low hanging" warnings or recommendations found in core supported modules.
These include, but are not limited to the following:

* innapropriate stack allocation in loops
* buffer overflows
* variable declaration "hiding" another variable declaration
* comparisons results that are always the same
* ambiguously signed bit-field members
* missing header guards

Change-Id: Id4a881686605d26c94ab5409bc70fcc21efacc25

45 files changed:
apps/app_cdr.c
apps/app_dictate.c
apps/app_followme.c
apps/app_minivm.c
apps/app_playback.c
apps/app_readexten.c
apps/app_voicemail.c
channels/chan_dahdi.c
channels/chan_dahdi.h
channels/chan_motif.c
codecs/ex_alaw.h
codecs/ex_g722.h
codecs/ex_ulaw.h
formats/format_g726.c
formats/msgsm.h
include/asterisk/ari.h
include/asterisk/calendar.h
include/asterisk/channel_internal.h
include/asterisk/config_options.h
include/asterisk/max_forwards.h
include/asterisk/mixmonitor.h
include/asterisk/parking.h
include/asterisk/res_pjsip_presence_xml.h
include/asterisk/slin.h
main/app.c
main/asterisk.c
main/event.c
main/file.c
main/indications.c
main/manager.c
main/pbx_variables.c
main/stasis.c
main/stasis_cache.c
res/ari/config.c
res/parking/parking_bridge_features.c
res/parking/res_parking.h
res/res_config_curl.c
res/res_phoneprov.c
res/res_pjsip/config_system.c
res/res_pjsip/config_transport.c
res/res_pjsip_endpoint_identifier_ip.c
res/res_pjsip_registrar.c
res/res_rtp_asterisk.c
res/stasis/command.c
res/stasis/control.c

index 93510f8a1588459dcd1a7621a1b66993ab8e9202..b3b98a3d1e6d639c13799e484f2c927330bb91f1 100644 (file)
@@ -121,13 +121,13 @@ struct app_cdr_message_payload {
        /*! The name of the channel to be manipulated */
        const char *channel_name;
        /*! Disable the CDR for this channel */
-       int disable:1;
+       unsigned int disable:1;
        /*! Re-enable the CDR for this channel */
-       int reenable:1;
+       unsigned int reenable:1;
        /*! Reset the CDR */
-       int reset:1;
+       unsigned int reset:1;
        /*! If reseting the CDR, keep the variables */
-       int keep_variables:1;
+       unsigned int keep_variables:1;
 };
 
 static void appcdr_callback(void *data, struct stasis_subscription *sub, struct stasis_message *message)
index f79ba82fe8e09c2f8cbfe2d49594ba309996ca81..1569a4b9ee1d7bddd0097d1ad8ef8fca8c766a42 100644 (file)
@@ -151,7 +151,8 @@ 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 = ast_alloca(len);
+                       ast_free(path);
+                       path = ast_malloc(len);
                        memset(path, 0, len);
                        maxlen = len;
                } else {
@@ -336,6 +337,7 @@ static int dictate_exec(struct ast_channel *chan, const char *data)
                        ast_frfree(f);
                }
        }
+       ast_free(path);
        if (oldr) {
                ast_set_read_format(chan, oldr);
                ao2_ref(oldr, -1);
index dfba0e0addc388776a5f7c99b45c3b43cb2633ba..21b9a19e708aa34c1e5b718ae7e21ea796900e04 100644 (file)
@@ -402,7 +402,6 @@ static int reload_followme(int reload)
        char *cat = NULL, *tmp;
        struct ast_variable *var;
        struct number *cur, *nm;
-       char *numberstr;
        int timeout;
        int numorder;
        const char *takecallstr;
@@ -523,9 +522,12 @@ static int reload_followme(int reload)
                while (var) {
                        if (!strcasecmp(var->name, "number")) {
                                int idx = 0;
+                               char copy[strlen(var->value) + 1];
+                               char *numberstr;
 
                                /* Add a new number */
-                               numberstr = ast_strdupa(var->value);
+                               strcpy(copy, var->value); /* safe */
+                               numberstr = copy;
                                if ((tmp = strchr(numberstr, ','))) {
                                        *tmp++ = '\0';
                                        timeout = atoi(tmp);
@@ -745,10 +747,6 @@ static struct ast_channel *wait_for_winner(struct findme_user_listptr *findme_us
                }
 
                tmpto = to;
-               if (to < 0) {
-                       to = 1000;
-                       tmpto = 1000;
-               }
                towas = to;
                winner = ast_waitfor_n(watchers, pos, &to);
                tmpto -= to;
index dae033f7c554edf4bc8f20eda2cb928255fae917..36a5fcfb87efbb3924dd26e38704e9e20ff70194 100644 (file)
@@ -2654,9 +2654,10 @@ static int create_vmaccount(char *name, struct ast_variable *var, int realtime)
                        ast_copy_string(vmu->fullname, var->value, sizeof(vmu->fullname));
                } else if (!strcasecmp(var->name, "setvar")) {
                        char *varval;
-                       char *varname = ast_strdupa(var->value);
+                       char varname[strlen(var->value) + 1];
                        struct ast_variable *tmpvar;
 
+                       strcpy(varname, var->value); /* safe */
                        if ((varval = strchr(varname, '='))) {
                                *varval = '\0';
                                varval++;
index 65a75ac6e84ddbbd6922c89288a678e0e4837ca2..e67242127209b53261b5b40c9aaad2daf896ee8f 100644 (file)
@@ -175,7 +175,10 @@ static int s_streamwait3(const say_args_t *a, const char *fn)
 static int do_say(say_args_t *a, const char *s, const char *options, int depth)
 {
        struct ast_variable *v;
-       char *lang, *x, *rule = NULL;
+       char *lang;
+       char *x;
+       char *rule = NULL;
+       char *rule_head = NULL;
        int ret = 0;
        struct varshead head = { .first = NULL, .last = NULL };
        struct ast_var_t *n;
@@ -197,7 +200,7 @@ static int do_say(say_args_t *a, const char *s, const char *options, int depth)
        for (;;) {
                for (v = ast_variable_browse(say_cfg, lang); v ; v = v->next) {
                        if (ast_extension_match(v->name, s)) {
-                               rule = ast_strdupa(v->value);
+                               rule_head = rule = ast_strdup(v->value);
                                break;
                        }
                }
@@ -222,6 +225,7 @@ static int do_say(say_args_t *a, const char *s, const char *options, int depth)
        n = ast_var_assign("SAY", s);
        if (!n) {
                ast_log(LOG_ERROR, "Memory allocation error in do_say\n");
+               ast_free(rule_head);
                return -1;
        }
        AST_LIST_INSERT_HEAD(&head, n, entries);
@@ -283,6 +287,7 @@ static int do_say(say_args_t *a, const char *s, const char *options, int depth)
                }
        }
        ast_var_delete(n);
+       ast_free(rule_head);
        return ret;
 }
 
index a809f92ed0a0bac46807cfa28ae6fcb023533401..20dc8eb056f17edd247f9fa093d69cf8c04216b0 100644 (file)
@@ -172,8 +172,7 @@ static int readexten_exec(struct ast_channel *chan, const char *data)
        if (timeout <= 0)
                timeout = ast_channel_pbx(chan) ? ast_channel_pbx(chan)->rtimeoutms : 10000;
 
-       if (digit_timeout <= 0)
-               digit_timeout = ast_channel_pbx(chan) ? ast_channel_pbx(chan)->dtimeoutms : 5000;
+       digit_timeout = ast_channel_pbx(chan) ? ast_channel_pbx(chan)->dtimeoutms : 5000;
 
        if (ast_test_flag(&flags, OPT_INDICATION) && !ast_strlen_zero(arglist.filename)) {
                ts = ast_get_indication_tone(ast_channel_zone(chan), arglist.filename);
index fa5aa5a5f9dfd2042753c7ad8f2342d77a6e8e00..83f1bde682bd86979e50583c544b3cb1ef3003a1 100644 (file)
@@ -1848,7 +1848,7 @@ static void vm_change_password(struct ast_vm_user *vmu, const char *newpassword)
        struct ast_config   *cfg = NULL;
        struct ast_variable *var = NULL;
        struct ast_category *cat = NULL;
-       char *category = NULL, *value = NULL, *new = NULL;
+       char *category = NULL;
        const char *tmp = NULL;
        struct ast_flags config_flags = { CONFIG_FLAG_WITHCOMMENTS };
        char secretfn[PATH_MAX] = "";
@@ -1875,24 +1875,28 @@ static void vm_change_password(struct ast_vm_user *vmu, const char *newpassword)
                if ((cfg = ast_config_load(VOICEMAIL_CONFIG, config_flags)) && valid_config(cfg)) {
                        while ((category = ast_category_browse(cfg, category))) {
                                if (!strcasecmp(category, vmu->context)) {
+                                       char *value = NULL;
+                                       char *new = NULL;
                                        if (!(tmp = ast_variable_retrieve(cfg, category, vmu->mailbox))) {
                                                ast_log(AST_LOG_WARNING, "We could not find the mailbox.\n");
                                                break;
                                        }
                                        value = strstr(tmp, ",");
                                        if (!value) {
-                                               new = ast_alloca(strlen(newpassword)+1);
+                                               new = ast_malloc(strlen(newpassword) + 1);
                                                sprintf(new, "%s", newpassword);
                                        } else {
-                                               new = ast_alloca((strlen(value) + strlen(newpassword) + 1));
+                                               new = ast_malloc((strlen(value) + strlen(newpassword) + 1));
                                                sprintf(new, "%s%s", newpassword, value);
                                        }
                                        if (!(cat = ast_category_get(cfg, category, NULL))) {
                                                ast_log(AST_LOG_WARNING, "Failed to get category structure.\n");
+                                               ast_free(new);
                                                break;
                                        }
                                        ast_variable_update(cat, vmu->mailbox, new, NULL, 0);
                                        found = 1;
+                                       ast_free(new);
                                }
                        }
                        /* save the results */
@@ -1916,13 +1920,14 @@ static void vm_change_password(struct ast_vm_user *vmu, const char *newpassword)
                        for (category = ast_category_browse(cfg, NULL); category; category = ast_category_browse(cfg, category)) {
                                ast_debug(4, "users.conf: %s\n", category);
                                if (!strcasecmp(category, vmu->mailbox)) {
+                                       char new[strlen(newpassword) + 1];
                                        if (!ast_variable_retrieve(cfg, category, "vmsecret")) {
                                                ast_debug(3, "looks like we need to make vmsecret!\n");
                                                var = ast_variable_new("vmsecret", newpassword, "");
                                        } else {
                                                var = NULL;
                                        }
-                                       new = ast_alloca(strlen(newpassword) + 1);
+
                                        sprintf(new, "%s", newpassword);
                                        if (!(cat = ast_category_get(cfg, category, NULL))) {
                                                ast_debug(4, "failed to get category!\n");
@@ -2245,7 +2250,6 @@ static int imap_retrieve_greeting(const char *dir, const int msgnum, struct ast_
        struct vm_state *vms_p;
        char *file, *filename;
        char dest[PATH_MAX];
-       char *attachment;
        int i;
        BODY *body;
        int ret = 0;
@@ -2298,21 +2302,26 @@ static int imap_retrieve_greeting(const char *dir, const int msgnum, struct ast_
                mail_fetchstructure(vms_p->mailstream, i + 1, &body);
                /* We have the body, now we extract the file name of the first attachment. */
                if (body->nested.part && body->nested.part->next && body->nested.part->next->body.parameter->value) {
-                       attachment = ast_strdupa(body->nested.part->next->body.parameter->value);
+                       char *attachment = body->nested.part->next->body.parameter->value;
+                       char copy[strlen(attachment) + 1];
+
+                       strcpy(copy, attachment); /* safe */
+                       attachment = copy;
+
+                       filename = strsep(&attachment, ".");
+                       if (!strcmp(filename, file)) {
+                               ast_copy_string(vms_p->fn, dir, sizeof(vms_p->fn));
+                               vms_p->msgArray[vms_p->curmsg] = i + 1;
+                               create_dirpath(dest, sizeof(dest), vmu->context, vms_p->username, "");
+                               save_body(body, vms_p, "2", attachment, 0);
+                               ret = 0;
+                               break;
+                       }
                } else {
                        ast_log(AST_LOG_ERROR, "There is no file attached to this IMAP message.\n");
                        ret = -1;
                        break;
                }
-               filename = strsep(&attachment, ".");
-               if (!strcmp(filename, file)) {
-                       ast_copy_string(vms_p->fn, dir, sizeof(vms_p->fn));
-                       vms_p->msgArray[vms_p->curmsg] = i + 1;
-                       create_dirpath(dest, sizeof(dest), vmu->context, vms_p->username, "");
-                       save_body(body, vms_p, "2", attachment, 0);
-                       ret = 0;
-                       break;
-               }
        }
 
        if (curr_mbox != -1) {
@@ -8174,10 +8183,12 @@ static void queue_mwi_event(const char *channel_id, const char *box, int urgent,
 
                aliases = ao2_find(mailbox_alias_mappings, box, OBJ_SEARCH_KEY | OBJ_MULTIPLE);
                while ((mapping = ao2_iterator_next(aliases))) {
+                       char alias[strlen(mapping->alias) + 1];
+                       strcpy(alias, mapping->alias); /* safe */
                        mailbox = NULL;
                        context = NULL;
                        ast_debug(3, "Found alias mapping: %s -> %s\n", mapping->alias, box);
-                       separate_mailbox(ast_strdupa(mapping->alias), &mailbox, &context);
+                       separate_mailbox(alias, &mailbox, &context);
                        ast_publish_mwi_state_channel(mailbox, context, new + urgent, old, channel_id);
                        ao2_ref(mapping, -1);
                }
@@ -8397,12 +8408,12 @@ static int forward_message(struct ast_channel *chan, char *context, struct vm_st
                        directory_app = pbx_findapp("Directory");
                        if (directory_app) {
                                char vmcontext[256];
-                               char *old_context;
-                               char *old_exten;
+                               char old_context[strlen(ast_channel_context(chan)) + 1];
+                               char old_exten[strlen(ast_channel_exten(chan)) + 1];
                                int old_priority;
                                /* make backup copies */
-                               old_context = ast_strdupa(ast_channel_context(chan));
-                               old_exten = ast_strdupa(ast_channel_exten(chan));
+                               strcpy(old_context, ast_channel_context(chan)); /* safe */
+                               strcpy(old_exten, ast_channel_exten(chan)); /* safe */
                                old_priority = ast_channel_priority(chan);
 
                                /* call the Directory, changes the channel */
@@ -9075,7 +9086,6 @@ static int imap_remove_file(char *dir, int msgnum)
 static int imap_delete_old_greeting (char *dir, struct vm_state *vms)
 {
        char *file, *filename;
-       char *attachment;
        char arg[11];
        int i;
        BODY* body;
@@ -9104,17 +9114,22 @@ static int imap_delete_old_greeting (char *dir, struct vm_state *vms)
                mail_fetchstructure(vms->mailstream, i + 1, &body);
                /* We have the body, now we extract the file name of the first attachment. */
                if (body->nested.part->next && body->nested.part->next->body.parameter->value) {
-                       attachment = ast_strdupa(body->nested.part->next->body.parameter->value);
+                       char *attachment = body->nested.part->next->body.parameter->value;
+                       char copy[strlen(attachment) + 1];
+
+                       strcpy(copy, attachment); /* safe */
+                       attachment = copy;
+
+                       filename = strsep(&attachment, ".");
+                       if (!strcmp(filename, file)) {
+                               snprintf(arg, sizeof(arg), "%d", i + 1);
+                               mail_setflag(vms->mailstream, arg, "\\DELETED");
+                       }
                } else {
                        ast_log(AST_LOG_ERROR, "There is no file attached to this IMAP message.\n");
                        ast_mutex_unlock(&vms->lock);
                        return -1;
                }
-               filename = strsep(&attachment, ".");
-               if (!strcmp(filename, file)) {
-                       snprintf(arg, sizeof(arg), "%d", i + 1);
-                       mail_setflag(vms->mailstream, arg, "\\DELETED");
-               }
        }
        mail_expunge(vms->mailstream);
 
@@ -13820,26 +13835,30 @@ static void load_zonemessages(struct ast_config *cfg)
 
        var = ast_variable_browse(cfg, "zonemessages");
        while (var) {
-               struct vm_zone *z;
-               char *msg_format, *tzone;
-
-               z = ast_malloc(sizeof(*z));
-               if (!z) {
-                       return;
-               }
+               if (var->value) {
+                       struct vm_zone *z;
+                       char *msg_format, *tzone;
+                       char storage[strlen(var->value) + 1];
+
+                       z = ast_malloc(sizeof(*z));
+                       if (!z) {
+                               return;
+                       }
 
-               msg_format = ast_strdupa(var->value);
-               tzone = strsep(&msg_format, "|,");
-               if (msg_format) {
-                       ast_copy_string(z->name, var->name, sizeof(z->name));
-                       ast_copy_string(z->timezone, tzone, sizeof(z->timezone));
-                       ast_copy_string(z->msg_format, msg_format, sizeof(z->msg_format));
-                       AST_LIST_LOCK(&zones);
-                       AST_LIST_INSERT_HEAD(&zones, z, list);
-                       AST_LIST_UNLOCK(&zones);
-               } else {
-                       ast_log(AST_LOG_WARNING, "Invalid timezone definition at line %d\n", var->lineno);
-                       ast_free(z);
+                       strcpy(storage, var->value); /* safe */
+                       msg_format = storage;
+                       tzone = strsep(&msg_format, "|,");
+                       if (msg_format) {
+                               ast_copy_string(z->name, var->name, sizeof(z->name));
+                               ast_copy_string(z->timezone, tzone, sizeof(z->timezone));
+                               ast_copy_string(z->msg_format, msg_format, sizeof(z->msg_format));
+                               AST_LIST_LOCK(&zones);
+                               AST_LIST_INSERT_HEAD(&zones, z, list);
+                               AST_LIST_UNLOCK(&zones);
+                       } else {
+                               ast_log(AST_LOG_WARNING, "Invalid timezone definition at line %d\n", var->lineno);
+                               ast_free(z);
+                       }
                }
                var = var->next;
        }
index 46c71db0c66945b4d20e7cdefe30623bbf66d2ea..8a5e4b23cc5466977433f053dfc4d3a0e05219de 100644 (file)
@@ -4449,7 +4449,7 @@ static char *alarm2str(int alm)
 static const char *event2str(int event)
 {
        static char buf[256];
-       if ((event < (ARRAY_LEN(events))) && (event > -1))
+       if ((event > -1) && (event < (ARRAY_LEN(events))) )
                return events[event];
        sprintf(buf, "Event %d", event); /* safe */
        return buf;
@@ -15277,7 +15277,7 @@ static void mfcr2_show_links_of(struct ast_cli_args *a, struct r2links *list_hea
                        inside_range = 0;
                        len = 0;
                        /* Prepare nice string in channel_list[] */
-                       for (i = 0; i < mfcr2->numchans; i++) {
+                       for (i = 0; i < mfcr2->numchans && len < sizeof(channel_list) - 1; i++) {
                                struct dahdi_pvt *p = mfcr2->pvts[i];
                                if (!p) {
                                        continue;
@@ -18263,13 +18263,17 @@ static int process_dahdi(struct dahdi_chan_conf *confp, const char *cat, struct
                } else if (!strcasecmp(v->name, "namedpickupgroup")) {
                        confp->chan.named_pickupgroups = ast_get_namedgroups(v->value);
                } else if (!strcasecmp(v->name, "setvar")) {
-                       char *varname = ast_strdupa(v->value), *varval = NULL;
-                       struct ast_variable *tmpvar;
-                       if (varname && (varval = strchr(varname, '='))) {
-                               *varval++ = '\0';
-                               if ((tmpvar = ast_variable_new(varname, varval, ""))) {
-                                       tmpvar->next = confp->chan.vars;
-                                       confp->chan.vars = tmpvar;
+                       if (v->value) {
+                               char *varval = NULL;
+                               struct ast_variable *tmpvar;
+                               char varname[strlen(v->value) + 1];
+                               strcpy(varname, v->value); /* safe */
+                               if ((varval = strchr(varname, '='))) {
+                                       *varval++ = '\0';
+                                       if ((tmpvar = ast_variable_new(varname, varval, ""))) {
+                                               tmpvar->next = confp->chan.vars;
+                                               confp->chan.vars = tmpvar;
+                                       }
                                }
                        }
                } else if (!strcasecmp(v->name, "immediate")) {
@@ -19213,9 +19217,12 @@ static int process_dahdi(struct dahdi_chan_conf *confp, const char *cat, struct
                        } else if (!strcasecmp(v->name, "mfcr2_logging")) {
                                openr2_log_level_t tmplevel;
                                char *clevel;
-                               char *logval = ast_strdupa(v->value);
+                               char *logval;
+                               char copy[strlen(v->value) + 1];
+                               strcpy(copy, v->value); /* safe */
+                               logval = copy;
                                while (logval) {
-                                       clevel = strsep(&logval,",");
+                                       clevel = strsep(&logval,",");
                                        if (-1 == (tmplevel = openr2_log_get_level(clevel))) {
                                                ast_log(LOG_WARNING, "Ignoring invalid logging level: '%s' at line %d.\n", clevel, v->lineno);
                                                continue;
index 6fcdb192917ad8a074945c7b206a3d0d6f1cc32b..fab6be493e70b668ddae6b4bf3ae96968a7b4896 100644 (file)
@@ -677,15 +677,15 @@ struct dahdi_pvt {
        openr2_calling_party_category_t mfcr2_category;
        int mfcr2_dnis_index;
        int mfcr2_ani_index;
-       int mfcr2call:1;
-       int mfcr2_answer_pending:1;
-       int mfcr2_charge_calls:1;
-       int mfcr2_allow_collect_calls:1;
-       int mfcr2_forced_release:1;
-       int mfcr2_dnis_matched:1;
-       int mfcr2_call_accepted:1;
-       int mfcr2_accept_on_offer:1;
-       int mfcr2_progress_sent:1;
+       unsigned int mfcr2call:1;
+       unsigned int mfcr2_answer_pending:1;
+       unsigned int mfcr2_charge_calls:1;
+       unsigned int mfcr2_allow_collect_calls:1;
+       unsigned int mfcr2_forced_release:1;
+       unsigned int mfcr2_dnis_matched:1;
+       unsigned int mfcr2_call_accepted:1;
+       unsigned int mfcr2_accept_on_offer:1;
+       unsigned int mfcr2_progress_sent:1;
 #endif /* defined(HAVE_OPENR2) */
        /*! \brief DTMF digit in progress.  0 when no digit in progress. */
        char begindigit;
index 97a56d5b30381bea6c00c2c531de79af315747c1..57e4631e3c62a6f764eb1d0e511adb0b66af5d32 100644 (file)
@@ -2092,15 +2092,16 @@ static int jingle_interpret_description(struct jingle_session *session, iks *des
 
        /* Iterate the codecs updating the relevant RTP instance as we go */
        for (codec = iks_child(description); codec; codec = iks_next(codec)) {
-               char *id = iks_find_attrib(codec, "id"), *name = iks_find_attrib(codec, "name");
+               char *id = iks_find_attrib(codec, "id");
+               char *attr_name = iks_find_attrib(codec, "name");
                char *clockrate = iks_find_attrib(codec, "clockrate");
                int rtp_id, rtp_clockrate;
 
-               if (!ast_strlen_zero(id) && !ast_strlen_zero(name) && (sscanf(id, "%30d", &rtp_id) == 1)) {
+               if (!ast_strlen_zero(id) && !ast_strlen_zero(attr_name) && (sscanf(id, "%30d", &rtp_id) == 1)) {
                        if (!ast_strlen_zero(clockrate) && (sscanf(clockrate, "%30d", &rtp_clockrate) == 1)) {
-                               ast_rtp_codecs_payloads_set_rtpmap_type_rate(&codecs, NULL, rtp_id, media, name, 0, rtp_clockrate);
+                               ast_rtp_codecs_payloads_set_rtpmap_type_rate(&codecs, NULL, rtp_id, media, attr_name, 0, rtp_clockrate);
                        } else {
-                               ast_rtp_codecs_payloads_set_rtpmap_type(&codecs, NULL, rtp_id, media, name, 0);
+                               ast_rtp_codecs_payloads_set_rtpmap_type(&codecs, NULL, rtp_id, media, attr_name, 0);
                        }
                }
        }
index e8629be5e5010be01a2c74509fe06258b9ad7410..6eeeab20fa144ca961cddc7c451bcfadb24facbc 100644 (file)
@@ -7,6 +7,9 @@
  *
  */
 
+#ifndef ASTERISK_EX_ALAW_H
+#define ASTERISK_EX_ALAW_H
+
 static uint8_t ex_alaw[] = {
        0x00, 0x03, 0x06, 0x09, 0x0c, 0x0f, 0x12, 0x15,
        0x10, 0x18, 0x1b, 0x1e, 0x21, 0x24, 0x27, 0x2a,
@@ -34,3 +37,5 @@ static struct ast_frame *alaw_sample(void)
        f.subclass.format = ast_format_alaw;
        return &f;
 }
+
+#endif /* ASTERISK_EX_ALAW_H */
index 390cc7b5cb76b9d03b2d8c31c9a8cf9590311dd7..43f1f189fb637bbd834a40ad0f08d77f5fa78f7a 100644 (file)
@@ -7,6 +7,9 @@
  *
  */
 
+#ifndef ASTERISK_EX_G722_H
+#define ASTERISK_EX_G722_H
+
 static uint8_t ex_g722[] = {
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -46,3 +49,5 @@ static struct ast_frame *g722_sample(void)
 
        return &f;
 }
+
+#endif /* ASTERISK_EX_G722_H */
index d18a08e9c7540024b5698652571ca4b02eca3225..07bd100d90e8a9ec48da59c9e7efe465827449ef 100644 (file)
@@ -7,6 +7,9 @@
  *
  */
 
+#ifndef ASTERISK_EX_ULAW_H
+#define ASTERISK_EX_ULAW_H
+
 static uint8_t ex_ulaw[] = {
        0x00, 0x03, 0x06, 0x09, 0x0c, 0x0f, 0x12, 0x15,
        0x10, 0x18, 0x1b, 0x1e, 0x21, 0x24, 0x27, 0x2a,
@@ -36,3 +39,5 @@ static struct ast_frame *ulaw_sample(void)
 
        return &f;
 }
+
+#endif /* ASTERISK_EX_ULAW_H */
index 0f31db9b87bdefa6d4a93e36f31b4c96421a6842..9a9e59aa6d09074db4a71b0dea8c000e79c01c2b 100644 (file)
@@ -201,7 +201,7 @@ static off_t g726_tell(struct ast_filestream *fs)
        return ftello(fs->f) << 1;
 }
 
-static struct ast_format_def f[] = {
+static struct ast_format_def f_def[] = {
        {
                .name = "g726-40",
                .exts = "g726-40",
@@ -261,9 +261,9 @@ static int unload_module(void)
 {
        int i;
 
-       for (i = 0; f[i].desc_size ; i++) {
-               if (ast_format_def_unregister(f[i].name))
-                       ast_log(LOG_WARNING, "Failed to unregister format %s.\n", f[i].name);
+       for (i = 0; f_def[i].desc_size ; i++) {
+               if (ast_format_def_unregister(f_def[i].name))
+                       ast_log(LOG_WARNING, "Failed to unregister format %s.\n", f_def[i].name);
        }
        return(0);
 }
@@ -272,10 +272,10 @@ static int load_module(void)
 {
        int i;
 
-       for (i = 0; f[i].desc_size ; i++) {
-               f[i].format = ast_format_g726;
-               if (ast_format_def_register(&f[i])) {   /* errors are fatal */
-                       ast_log(LOG_WARNING, "Failed to register format %s.\n", f[i].name);
+       for (i = 0; f_def[i].desc_size ; i++) {
+               f_def[i].format = ast_format_g726;
+               if (ast_format_def_register(&f_def[i])) {       /* errors are fatal */
+                       ast_log(LOG_WARNING, "Failed to register format %s.\n", f_def[i].name);
                        unload_module();
                        return AST_MODULE_LOAD_DECLINE;
                }
index bb46a3a61000362482a288a96305d6ed48722729..179d6e89644fe47128c6e27f0441a13de61cd9af 100644 (file)
@@ -1,4 +1,6 @@
 /* Conversion routines derived from code by guido@sienanet.it */
+#ifndef ASTERISK_MSGSM_H
+#define ASTERISK_MSGSM_H
 
 #define GSM_MAGIC 0xD
 
@@ -687,3 +689,5 @@ static inline void conv65( wav_byte * c, gsm_byte * d){
                         writeGSM_33(d+33);
 
 }
+
+#endif /* ASTERISK_MSGSM_H */
index f83df0469d3955a10a40226f5c6c7381914ac4c6..051df51fa2e227ba518300195fbaa809c1092d1a 100644 (file)
@@ -99,7 +99,7 @@ struct ast_ari_response {
        /*! Corresponding text for the response code */
        const char *response_text; /* Shouldn't http.c handle this? */
        /*! Flag to indicate that no further response is needed */
-       int no_response:1;
+       unsigned int no_response:1;
 };
 
 /*!
index 26722937cf40f3de440bc6082d8684e471c112bf..d759e7cc8c3ccac449c9a1a1d8a926c415e1f5ff 100644 (file)
@@ -132,8 +132,8 @@ struct ast_calendar {
        int timeframe;       /*!< Span (in mins) of calendar data to pull with each request */
        pthread_t thread;    /*!< The thread that the calendar is loaded/updated in */
        ast_cond_t unload;
-       int unloading:1;
-       int pending_deletion:1; /*!< No longer used */
+       unsigned int unloading:1;
+       unsigned int pending_deletion:1; /*!< No longer used */
        struct ao2_container *events;  /*!< The events that are known at this time */
 };
 
index 2316e2f24c9e128860ecf15071e07b895abafaee..8cca3bdfd0f9736c0e757abd2386e8e757038bc7 100644 (file)
@@ -18,6 +18,9 @@
  * \brief Internal channel functions for channel.c to use
  */
 
+#ifndef ASTERISK_CHANNEL_INTERNAL_H
+#define ASTERISK_CHANNEL_INTERNAL_H
+
 #define ast_channel_internal_alloc(destructor, assignedid, requestor) __ast_channel_internal_alloc(destructor, assignedid, requestor, __FILE__, __LINE__, __PRETTY_FUNCTION__)
 struct ast_channel *__ast_channel_internal_alloc(void (*destructor)(void *obj), const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *file, int line, const char *function);
 void ast_channel_internal_finalize(struct ast_channel *chan);
@@ -27,3 +30,5 @@ int ast_channel_internal_setup_topics(struct ast_channel *chan);
 
 void ast_channel_internal_errno_set(enum ast_channel_error error);
 enum ast_channel_error ast_channel_internal_errno(void);
+
+#endif /* ASTERISK_CHANNEL_INTERNAL_H */
index 420eb97dd5bdf5c61ae0431277855cecc266345d..44299369d1635ca909b0510619a8c7036a431862 100644 (file)
@@ -168,7 +168,7 @@ struct aco_file {
 
 struct aco_info {
        const char *module; /*!< The name of the module whose config is being processed */
-       int hidden:1;                /*!< If enabled, this config item is hidden from users */
+       unsigned int hidden:1;                /*!< If enabled, this config item is hidden from users */
        aco_pre_apply_config pre_apply_config; /*!< A callback called after processing, but before changes are applied */
        aco_post_apply_config post_apply_config;/*!< A callback called after changes are applied */
        aco_snapshot_alloc snapshot_alloc;     /*!< Allocate an object to hold all global configs and item containers */
index 3130b4b64dc100aafc8823603c26958ef47f565f..5d0c0d880c7aba4a629e8dad6a37497e73e254c9 100644 (file)
@@ -17,6 +17,7 @@
  */
 
 #ifndef MAX_FORWARDS_H
+#define MAX_FORWARDS_H
 
 struct ast_channel;
 
index 892cd2a780933fa92e110e17caada033b47965a6..3cf4f1ce0a8e0f276c35c69495839120ded0b357 100644 (file)
@@ -23,6 +23,9 @@
  * \author Jonathan Rose <jrose@digium.com>
  */
 
+#ifndef ASTERISK_MIX_MONITOR_H
+#define ASTERISK_MIX_MONITOR_H
+
 /*!
  * \brief Start a mixmonitor on a channel.
  * \since 12.0.0
@@ -103,3 +106,5 @@ int ast_start_mixmonitor(struct ast_channel *chan, const char *filename, const c
  * \retval non-zero on failure
  */
 int ast_stop_mixmonitor(struct ast_channel *chan, const char *mixmon_id);
+
+#endif /* ASTERISK_MIX_MONITOR_H */
index afe12c914061952a4138ac17576ee330a490383f..1df4372be74e64cab22cc7b52d07d25fd9ebb04c 100644 (file)
@@ -23,6 +23,9 @@
  * \author Jonathan Rose <jrose@digium.com>
  */
 
+#ifndef ASTERISK_PARKING_H
+#define ASTERISK_PARKING_H
+
 #include "asterisk/stringfields.h"
 #include "asterisk/bridge.h"
 
@@ -294,3 +297,5 @@ int ast_parking_unregister_bridge_features(const char *module_name);
  * \retval 1 if there is a parking provider regsistered
  */
 int ast_parking_provider_registered(void);
+
+#endif /* ASTERISK_PARKING_H */
index 55b79ad6e83733b4de0cc6c1da33331782ad1cf0..60235ca94f5c848ed0d53365835005fdca41d6ca 100644 (file)
@@ -30,6 +30,9 @@
  * This constant is useful to check against when trying to determine
  * if printing XML succeeded or failed.
  */
+#ifndef ASTERISK_PJSIP_PRESENCE_XML_H
+#define ASTERISK_PJSIP_PRESENCE_XML_H
+
 #define AST_PJSIP_XML_PROLOG_LEN 39
 
 /*!
@@ -115,3 +118,5 @@ pj_xml_node *ast_sip_presence_xml_create_node(pj_pool_t *pool,
 void ast_sip_presence_xml_find_node_attr(pj_pool_t* pool,
                pj_xml_node *parent, const char *node_name, const char *attr_name,
                pj_xml_node **node, pj_xml_attr **attr);
+
+#endif /* ASTERISK_PJSIP_PRESENCE_XML_H */
index 976637473e1c7d1a00200c971c587ae04cdeabdc..5d290cd9966648203164a1f1059b8f3301196f71 100644 (file)
@@ -22,6 +22,9 @@
  * Samples were truncated at 160 and 320 bytes.
  */
 
+#ifndef ASTERISK_SLIN_H
+#define ASTERISK_SLIN_H
+
 static uint16_t ex_slin8[] = {
        0x0002, 0xfffc, 0x0000, 0xfffe, 0x0000, 0xfffa, 0x002a, 0x007a,
        0x003a, 0xffbe, 0xff76, 0xff84, 0x0016, 0x007e, 0x0096, 0x00d2,
@@ -91,3 +94,5 @@ static inline struct ast_frame *slin16_sample(void)
 
        return &f;
 }
+
+#endif /* ASTERISK_SLIN_H */
index 5fb81ba60a2bcef6dfbb4b72bcbe08f0a926a32b..4cd59344aab8358d3146aebd703fd262ad1e71b9 100644 (file)
@@ -1506,7 +1506,7 @@ static int __ast_play_and_record(struct ast_channel *chan, const char *playfile,
        char comment[256];
        int x, fmtcnt = 1, res = -1, outmsg = 0;
        struct ast_filestream *others[AST_MAX_FORMATS];
-       char *sfmt[AST_MAX_FORMATS];
+       const char *sfmt[AST_MAX_FORMATS];
        char *stringp = NULL;
        time_t start, end;
        struct ast_dsp *sildet = NULL;   /* silence detector dsp */
@@ -1581,7 +1581,12 @@ static int __ast_play_and_record(struct ast_channel *chan, const char *playfile,
                        ast_log(LOG_WARNING, "Please increase AST_MAX_FORMATS in file.h\n");
                        break;
                }
-               sfmt[fmtcnt++] = ast_strdupa(fmt);
+               /*
+                * Storage for 'fmt' is on the stack and held by 'fmts', which is maintained for
+                * the rest of this function. So okay to not duplicate 'fmt' here, but only keep
+                * a pointer to it.
+                */
+               sfmt[fmtcnt++] = fmt;
        }
 
        end = start = time(NULL);  /* pre-initialize end to be same as start in case we never get into loop */
index 30b84e6d9923d85620f2c5cb5be6d9a499d85e94..8af55883f3636caf081770329f17e58bbc9fd1a0 100644 (file)
@@ -3647,11 +3647,12 @@ static void main_atexit(void)
 int main(int argc, char *argv[])
 {
        int c;
-       char * xarg = NULL;
        int x;
        int isroot = 1, rundir_exists = 0;
-       const char *runuser = NULL, *rungroup = NULL;
-       char *remotesock = NULL;
+       RAII_VAR(char *, runuser, NULL, ast_free);
+       RAII_VAR(char *, rungroup, NULL, ast_free);
+       RAII_VAR(char *, xarg, NULL, ast_free);
+       RAII_VAR(char *, remotesock, NULL, ast_free);
        struct rlimit l;
 
        /* Remember original args for restart */
@@ -3715,7 +3716,7 @@ int main(int argc, char *argv[])
                        break;
 #endif
                case 'G':
-                       rungroup = ast_strdupa(optarg);
+                       rungroup = ast_strdup(optarg);
                        break;
                case 'g':
                        ast_set_flag(&ast_options, AST_OPT_FLAG_DUMP_CORE);
@@ -3760,7 +3761,7 @@ int main(int argc, char *argv[])
                        ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK | AST_OPT_FLAG_REMOTE);
                        break;
                case 's':
-                       remotesock = ast_strdupa(optarg);
+                       remotesock = ast_strdup(optarg);
                        break;
                case 'T':
                        ast_set_flag(&ast_options, AST_OPT_FLAG_TIMESTAMP);
@@ -3769,7 +3770,7 @@ int main(int argc, char *argv[])
                        ast_set_flag(&ast_options, AST_OPT_FLAG_CACHE_RECORD_FILES);
                        break;
                case 'U':
-                       runuser = ast_strdupa(optarg);
+                       runuser = ast_strdup(optarg);
                        break;
                case 'V':
                        show_version();
@@ -3787,7 +3788,7 @@ int main(int argc, char *argv[])
                        ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK | AST_OPT_FLAG_REMOTE);
 
                        ast_set_flag(&ast_options, AST_OPT_FLAG_EXEC | AST_OPT_FLAG_NO_COLOR);
-                       xarg = ast_strdupa(optarg);
+                       xarg = ast_strdup(optarg);
                        break;
                case '?':
                        exit(1);
@@ -3872,9 +3873,9 @@ int main(int argc, char *argv[])
 #endif /* !defined(CONFIGURE_RAN_AS_ROOT) */
 
        if ((!rungroup) && !ast_strlen_zero(ast_config_AST_RUN_GROUP))
-               rungroup = ast_config_AST_RUN_GROUP;
+               rungroup = ast_strdup(ast_config_AST_RUN_GROUP);
        if ((!runuser) && !ast_strlen_zero(ast_config_AST_RUN_USER))
-               runuser = ast_config_AST_RUN_USER;
+               runuser = ast_strdup(ast_config_AST_RUN_USER);
 
        /* Must install this signal handler up here to ensure that if the canary
         * fails to execute that it doesn't kill the Asterisk process.
index 019dfcac030e6efda3f39acb08c7e643da453772..ef43b79e33f068a07ca666a9901e51837b77873b 100644 (file)
@@ -421,7 +421,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 = ast_alloca(sizeof(*ie_value));
+               struct ast_event_ie_val *ie_value = ast_malloc(sizeof(*ie_value));
                int insert = 0;
 
                memset(ie_value, 0, sizeof(*ie_value));
@@ -445,7 +445,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 = ast_alloca(datalen);
+                       ie_value->payload.raw = ast_malloc(datalen);
                        memcpy(ie_value->payload.raw, data, datalen);
                        ie_value->raw_datalen = datalen;
                        insert = 1;
@@ -493,7 +493,7 @@ struct ast_event *ast_event_new(enum ast_event_type type, ...)
 
                /* realloc inside one of the append functions failed */
                if (!event) {
-                       return NULL;
+                       goto cleanup;
                }
        }
 
@@ -503,6 +503,17 @@ struct ast_event *ast_event_new(enum ast_event_type type, ...)
                ast_event_append_eid(&event);
        }
 
+cleanup:
+       AST_LIST_TRAVERSE_SAFE_BEGIN(&ie_vals, ie_val, entry) {
+               AST_LIST_REMOVE_CURRENT(entry);
+
+               if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_RAW) {
+                       ast_free(ie_val->payload.raw);
+               }
+               ast_free(ie_val);
+       }
+       AST_LIST_TRAVERSE_SAFE_END;
+
        return event;
 }
 
index bb1db3ee647ab977a282d81d37ed76478841a699..75100072970b033f89ecd6839e0f7b11eb31df64 100644 (file)
@@ -516,7 +516,9 @@ static int filehelper(const char *filename, const void *arg2, const char *fmt, c
        AST_RWLIST_RDLOCK(&formats);
        /* Check for a specific format */
        AST_RWLIST_TRAVERSE(&formats, f, list) {
-               char *stringp, *ext = NULL;
+               char *ext = NULL;
+               char storage[strlen(f->exts) + 1];
+               char *stringp;
 
                if (fmt && !exts_compare(f->exts, fmt))
                        continue;
@@ -525,7 +527,8 @@ static int filehelper(const char *filename, const void *arg2, const char *fmt, c
                 * The file must exist, and for OPEN, must match
                 * one of the formats supported by the channel.
                 */
-               stringp = ast_strdupa(f->exts); /* this is in the stack so does not need to be freed */
+               strcpy(storage, f->exts); /* safe - this is in the stack so does not need to be freed */
+               stringp = storage;
                while ( (ext = strsep(&stringp, "|")) ) {
                        struct stat st;
                        char *fn = build_filename(filename, ext);
@@ -1402,13 +1405,13 @@ struct ast_filestream *ast_writefile(const char *filename, const char *type, con
                          We touch orig_fn just as a place-holder so other things (like vmail) see the file is there.
                          What we are really doing is writing to record_cache_dir until we are done then we will mv the file into place.
                        */
-                       orig_fn = ast_strdupa(fn);
+                       orig_fn = ast_strdup(fn);
                        for (c = fn; *c; c++)
                                if (*c == '/')
                                        *c = '_';
 
                        size = strlen(fn) + strlen(record_cache_dir) + 2;
-                       buf = ast_alloca(size);
+                       buf = ast_malloc(size);
                        strcpy(buf, record_cache_dir);
                        strcat(buf, "/");
                        strcat(buf, fn);
@@ -1439,14 +1442,18 @@ struct ast_filestream *ast_writefile(const char *filename, const char *type, con
                                if (orig_fn) {
                                        unlink(fn);
                                        unlink(orig_fn);
+                                       ast_free(orig_fn);
                                }
                                if (fs) {
                                        ast_closestream(fs);
                                        fs = NULL;
                                }
-                               if (!buf) {
-                                       ast_free(fn);
-                               }
+                               /*
+                                * 'fn' was has either been allocated from build_filename, or that was freed
+                                * and now 'fn' points to memory allocated for 'buf'. Either way the memory
+                                * now needs to be released.
+                                */
+                               ast_free(fn);
                                continue;
                        }
                        fs->trans = NULL;
@@ -1454,8 +1461,14 @@ struct ast_filestream *ast_writefile(const char *filename, const char *type, con
                        fs->flags = flags;
                        fs->mode = mode;
                        if (orig_fn) {
-                               fs->realfilename = ast_strdup(orig_fn);
-                               fs->filename = ast_strdup(fn);
+                               fs->realfilename = orig_fn;
+                               fs->filename = fn;
+                               /*
+                                * The above now manages the memory allocated for 'orig_fn' and 'fn', so
+                                * set them to NULL, so they don't get released at the end of the loop.
+                                */
+                               orig_fn = NULL;
+                               fn = NULL;
                        } else {
                                fs->realfilename = NULL;
                                fs->filename = ast_strdup(filename);
@@ -1468,9 +1481,9 @@ struct ast_filestream *ast_writefile(const char *filename, const char *type, con
                        if (orig_fn)
                                unlink(orig_fn);
                }
-               /* if buf != NULL then fn is already free and pointing to it */
-               if (!buf)
-                       ast_free(fn);
+               /* Free 'fn', or if 'fn' points to 'buf' then free 'buf' */
+               ast_free(fn);
+               ast_free(orig_fn);
        }
 
        AST_RWLIST_UNLOCK(&formats);
index 622f98db228e156ffb9d9461ce3cc5eb3261b81f..b264841b59a0edb88c5ec0d9b1e7ddada89c5a5c 100644 (file)
@@ -920,11 +920,11 @@ static void store_tone_zone_ring_cadence(struct ast_tone_zone *zone, const char
        ast_copy_string(buf, val, sizeof(buf));
 
        while ((ring = strsep(&c, ","))) {
-               int *tmp, val;
+               int *tmp, value;
 
                ring = ast_strip(ring);
 
-               if (!isdigit(ring[0]) || (val = atoi(ring)) == -1) {
+               if (!isdigit(ring[0]) || (value = atoi(ring)) == -1) {
                        ast_log(LOG_WARNING, "Invalid ringcadence given '%s'.\n", ring);
                        continue;
                }
@@ -934,7 +934,7 @@ static void store_tone_zone_ring_cadence(struct ast_tone_zone *zone, const char
                }
 
                zone->ringcadence = tmp;
-               tmp[zone->nrringcadence] = val;
+               tmp[zone->nrringcadence] = value;
                zone->nrringcadence++;
        }
 }
index 1df6765b081a2f8401a573fdcb8fd77a63eff33e..fc602bc32f8c2c6a9da196d70074294643d7c486 100644 (file)
@@ -1615,7 +1615,7 @@ struct mansession {
        FILE *f;
        int fd;
        enum mansession_message_parsing parsing;
-       int write_error:1;
+       unsigned int write_error:1;
        struct manager_custom_hook *hook;
        ast_mutex_t lock;
 };
@@ -3808,8 +3808,8 @@ static enum error_type handle_updates(struct mansession *s, const struct message
                int allowdups = 0;
                int istemplate = 0;
                int ignoreerror = 0;
-               char *inherit = NULL;
-               char *catfilter = NULL;
+               RAII_VAR(char *, inherit, NULL, ast_free);
+               RAII_VAR(char *, catfilter, NULL, ast_free);
                char *token;
                int foundvar = 0;
                int foundcat = 0;
@@ -3847,7 +3847,9 @@ static enum error_type handle_updates(struct mansession *s, const struct message
                snprintf(hdr, sizeof(hdr), "Options-%06d", x);
                options = astman_get_header(m, hdr);
                if (!ast_strlen_zero(options)) {
-                       dupoptions = ast_strdupa(options);
+                       char copy[strlen(options) + 1];
+                       strcpy(copy, options); /* safe */
+                       dupoptions = copy;
                        while ((token = ast_strsep(&dupoptions, ',', AST_STRSEP_STRIP))) {
                                if (!strcasecmp("allowdups", token)) {
                                        allowdups = 1;
@@ -3865,7 +3867,7 @@ static enum error_type handle_updates(struct mansession *s, const struct message
                                        char *c = ast_strsep(&token, '=', AST_STRSEP_STRIP);
                                        c = ast_strsep(&token, '=', AST_STRSEP_STRIP);
                                        if (c) {
-                                               inherit = ast_strdupa(c);
+                                               inherit = ast_strdup(c);
                                        }
                                        continue;
                                }
@@ -3873,7 +3875,7 @@ static enum error_type handle_updates(struct mansession *s, const struct message
                                        char *c = ast_strsep(&token, '=', AST_STRSEP_STRIP);
                                        c = ast_strsep(&token, '=', AST_STRSEP_STRIP);
                                        if (c) {
-                                               catfilter = ast_strdupa(c);
+                                               catfilter = ast_strdup(c);
                                        }
                                        continue;
                                }
index f09540b694876cd7122694c14f5e8eb198ce316c..88c4ec1a204073068ea6754eb07b142bc81204ef 100644 (file)
@@ -632,9 +632,8 @@ void pbx_substitute_variables_helper_full(struct ast_channel *c, struct varshead
        /* Substitutes variables into cp2, based on string cp1, cp2 NO LONGER NEEDS TO BE ZEROED OUT!!!!  */
        const char *whereweare;
        const char *orig_cp2 = cp2;
-       char *workspace = NULL;
-       char *ltmp = NULL;
-       char *var = NULL;
+       char ltmp[VAR_BUF_SIZE];
+       char var[VAR_BUF_SIZE];
 
        *cp2 = 0; /* just in case nothing ends up there */
        whereweare = cp1;
@@ -692,6 +691,7 @@ void pbx_substitute_variables_helper_full(struct ast_channel *c, struct varshead
                        int offset2;
                        int isfunction;
                        char *cp4;
+                       char workspace[VAR_BUF_SIZE] = "";
 
                        /* We have a variable.  Find the start and end, and determine
                           if we are going to have to recursively call ourselves on the
@@ -727,28 +727,17 @@ void pbx_substitute_variables_helper_full(struct ast_channel *c, struct varshead
                        /* Skip totally over variable string */
                        whereweare = vare;
 
-                       if (!var)
-                               var = ast_alloca(VAR_BUF_SIZE);
-
                        /* Store variable name expression to lookup (and truncate). */
                        ast_copy_string(var, vars, len + 1);
 
                        /* Substitute if necessary */
                        if (needsub) {
-                               if (!ltmp) {
-                                       ltmp = ast_alloca(VAR_BUF_SIZE);
-                               }
                                pbx_substitute_variables_helper_full(c, headp, var, ltmp, VAR_BUF_SIZE - 1, NULL);
                                vars = ltmp;
                        } else {
                                vars = var;
                        }
 
-                       if (!workspace)
-                               workspace = ast_alloca(VAR_BUF_SIZE);
-
-                       workspace[0] = '\0';
-
                        parse_variable_name(vars, &offset, &offset2, &isfunction);
                        if (isfunction) {
                                /* Evaluate function */
@@ -822,17 +811,11 @@ void pbx_substitute_variables_helper_full(struct ast_channel *c, struct varshead
                        /* Skip totally over expression */
                        whereweare = vare;
 
-                       if (!var)
-                               var = ast_alloca(VAR_BUF_SIZE);
-
                        /* Store expression to evaluate (and truncate). */
                        ast_copy_string(var, vars, len + 1);
 
                        /* Substitute if necessary */
                        if (needsub) {
-                               if (!ltmp) {
-                                       ltmp = ast_alloca(VAR_BUF_SIZE);
-                               }
                                pbx_substitute_variables_helper_full(c, headp, var, ltmp, VAR_BUF_SIZE - 1, NULL);
                                vars = ltmp;
                        } else {
index 8cbfe72477b39a0ced7f3c33e5c3e7bbe7cf251d..e570748f3899fefee1debd608c69489b32f0df16 100644 (file)
@@ -305,7 +305,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$");
 #define TOPIC_POOL_BUCKETS 57
 
 /*! Thread pool for topics that don't want a dedicated taskprocessor */
-static struct ast_threadpool *pool;
+static struct ast_threadpool *threadpool;
 
 STASIS_MESSAGE_TYPE_DEFN(stasis_subscription_change_type);
 
@@ -756,7 +756,7 @@ struct stasis_subscription *internal_stasis_subscribe(
                 * pool should be used.
                 */
                if (use_thread_pool) {
-                       sub->mailbox = ast_threadpool_serializer(tps_name, pool);
+                       sub->mailbox = ast_threadpool_serializer(tps_name, threadpool);
                } else {
                        sub->mailbox = ast_taskprocessor_get(tps_name, TPS_REF_DEFAULT);
                }
@@ -2728,8 +2728,8 @@ static void stasis_cleanup(void)
        ao2_global_obj_release(subscription_statistics);
        ao2_global_obj_release(topic_statistics);
 #endif
-       ast_threadpool_shutdown(pool);
-       pool = NULL;
+       ast_threadpool_shutdown(threadpool);
+       threadpool = NULL;
        STASIS_MESSAGE_TYPE_CLEANUP(stasis_subscription_change_type);
        STASIS_MESSAGE_TYPE_CLEANUP(ast_multi_user_event_type);
        aco_info_destroy(&cfg_info);
@@ -2806,9 +2806,9 @@ int stasis_init(void)
        threadpool_opts.auto_increment = 1;
        threadpool_opts.max_size = cfg->threadpool_options->max_size;
        threadpool_opts.idle_timeout = cfg->threadpool_options->idle_timeout_sec;
-       pool = ast_threadpool_create("stasis", NULL, &threadpool_opts);
+       threadpool = ast_threadpool_create("stasis", NULL, &threadpool_opts);
        ao2_ref(cfg, -1);
-       if (!pool) {
+       if (!threadpool) {
                ast_log(LOG_ERROR, "Failed to create 'stasis-core' threadpool\n");
 
                return -1;
index 0f2d443042e72cec99b72955c4fc57ec8e91a974..0718f9714bc1c3b0db77034bbb986a5c385667a1 100644 (file)
@@ -865,13 +865,13 @@ static void caching_topic_exec(void *data, struct stasis_subscription *sub,
                 * continue to grow unabated.
                 */
                if (strcmp(change->description, "Unsubscribe") == 0) {
-                       struct stasis_cache_entry *sub;
+                       struct stasis_cache_entry *cached_sub;
 
                        ao2_wrlock(caching_topic->cache->entries);
-                       sub = cache_find(caching_topic->cache->entries, stasis_subscription_change_type(), change->uniqueid);
-                       if (sub) {
-                               ao2_cleanup(cache_remove(caching_topic->cache->entries, sub, stasis_message_eid(message)));
-                               ao2_cleanup(sub);
+                       cached_sub = cache_find(caching_topic->cache->entries, stasis_subscription_change_type(), change->uniqueid);
+                       if (cached_sub) {
+                               ao2_cleanup(cache_remove(caching_topic->cache->entries, cached_sub, stasis_message_eid(message)));
+                               ao2_cleanup(cached_sub);
                        }
                        ao2_unlock(caching_topic->cache->entries);
                        ao2_cleanup(caching_topic_needs_unref);
index 275f41d96398e962b82ce347b6d59ceb4a6ec867..713656b2ce3bbc84874840c7e036c103478f4500 100644 (file)
@@ -165,7 +165,7 @@ static struct aco_type user_option = {
        .item_offset = offsetof(struct ast_ari_conf, users),
 };
 
-static struct aco_type *user[] = ACO_TYPES(&user_option);
+static struct aco_type *global_user[] = ACO_TYPES(&user_option);
 
 static void conf_general_dtor(void *obj)
 {
@@ -343,16 +343,16 @@ int ast_ari_config_init(void)
                FLDSET(struct ast_ari_conf_general, write_timeout), 1, INT_MAX);
 
        /* ARI type=user category options */
-       aco_option_register(&cfg_info, "type", ACO_EXACT, user, NULL,
+       aco_option_register(&cfg_info, "type", ACO_EXACT, global_user, NULL,
                OPT_NOOP_T, 0, 0);
-       aco_option_register(&cfg_info, "read_only", ACO_EXACT, user,
+       aco_option_register(&cfg_info, "read_only", ACO_EXACT, global_user,
                "no", OPT_BOOL_T, 1,
                FLDSET(struct ast_ari_conf_user, read_only));
-       aco_option_register(&cfg_info, "password", ACO_EXACT, user,
+       aco_option_register(&cfg_info, "password", ACO_EXACT, global_user,
                "", OPT_CHAR_ARRAY_T, 0,
                FLDSET(struct ast_ari_conf_user, password), ARI_PASSWORD_LEN);
        aco_option_register_custom(&cfg_info, "password_format", ACO_EXACT,
-               user, "plain",  password_format_handler, 0);
+               global_user, "plain",  password_format_handler, 0);
 
        return process_config(0);
 }
index cf5cc721db0470ea776907906b27f9575496cdb2..5a013ea6d310d7725b30a00a9fcec8f0347fdbf1 100644 (file)
@@ -51,7 +51,7 @@ struct parked_subscription_datastore {
 struct parked_subscription_data {
        struct transfer_channel_data *transfer_data;
        char *parkee_uuid;
-       int hangup_after:1;
+       unsigned int hangup_after:1;
        char parker_uuid[0];
 };
 
index 6fbde092181f7a32419843222cb65e32ab0e40d0..d4ffc55daca5f4d32e82a381319991285cdbe2bb 100644 (file)
@@ -23,6 +23,9 @@
  * \author Jonathan Rose <jrose@digium.com>
  */
 
+#ifndef ASTERISK_RES_PARKING_H
+#define ASTERISK_RES_PARKING_H
+
 #include "asterisk/pbx.h"
 #include "asterisk/bridge.h"
 #include "asterisk/parking.h"
@@ -570,3 +573,5 @@ struct ast_module_info;
  * \retval res_parking's ast_module
  */
 const struct ast_module_info *parking_get_module_info(void);
+
+#endif /* ASTERISK_RES_PARKING_H */
index 61b62452d6eb0f550b753747eed385bfbe6224af..fc7e894dd1537e6562c35c0156d983f4f38fed0b 100644 (file)
@@ -158,7 +158,7 @@ static struct ast_config *realtime_multi_curl(const char *url, const char *unuse
        for (field = fields; field; field = field->next) {
                if (start) {
                        char *op;
-                       initfield = ast_strdupa(field->name);
+                       initfield = ast_strdup(field->name);
                        if ((op = strchr(initfield, ' ')))
                                *op = '\0';
                }
@@ -174,6 +174,7 @@ static struct ast_config *realtime_multi_curl(const char *url, const char *unuse
        ast_str_substitute_variables(&buffer, 0, NULL, ast_str_buffer(query));
 
        if (!(cfg = ast_config_new())) {
+               ast_free(initfield);
                return NULL;
        }
 
@@ -208,6 +209,8 @@ static struct ast_config *realtime_multi_curl(const char *url, const char *unuse
                ast_category_append(cfg, cat);
        }
 
+       ast_free(initfield);
+
        return cfg;
 }
 
index 7091b9be00fbd7162c0b82c10e01d4b2edf9eed2..13bac4dea5ae80fb91c7ebd857c078178cfb2f4f 100644 (file)
@@ -608,13 +608,14 @@ static void build_profile(const char *name, struct ast_variable *v)
                if (!strcasecmp(v->name, "mime_type")) {
                        ast_string_field_set(profile, default_mime_type, v->value);
                } else if (!strcasecmp(v->name, "setvar")) {
-                       char *value_copy = ast_strdupa(v->value);
+                       char value_copy[strlen(v->value) + 1];
 
                        AST_DECLARE_APP_ARGS(args,
                                AST_APP_ARG(varname);
                                AST_APP_ARG(varval);
                        );
 
+                       strcpy(value_copy, v->value); /* safe */
                        AST_NONSTANDARD_APP_ARGS(args, value_copy, '=');
                        do {
                                if (ast_strlen_zero(args.varname) || ast_strlen_zero(args.varval))
@@ -630,7 +631,7 @@ static void build_profile(const char *name, struct ast_variable *v)
                } else {
                        struct phoneprov_file *pp_file;
                        char *file_extension;
-                       char *value_copy = ast_strdupa(v->value);
+                       char value_copy[strlen(v->value) + 1];
 
                        AST_DECLARE_APP_ARGS(args,
                                AST_APP_ARG(filename);
@@ -645,6 +646,7 @@ static void build_profile(const char *name, struct ast_variable *v)
                        if ((file_extension = strrchr(pp_file->format, '.')))
                                file_extension++;
 
+                       strcpy(value_copy, v->value); /* safe */
                        AST_STANDARD_APP_ARGS(args, value_copy);
 
                        /* Mime type order of preference
index 52f66a5264b96703a1113483aef0fb9990388672..716a6da61bec6d46d8b0a21a0dab42bf4064f400 100644 (file)
@@ -83,7 +83,7 @@ static void *system_alloc(const char *name)
        return system;
 }
 
-static int system_apply(const struct ast_sorcery *system_sorcery, void *obj)
+static int system_apply(const struct ast_sorcery *sorcery, void *obj)
 {
        struct system_config *system = obj;
        int min_timerb;
index fed56f9dfa4ed7d4f74f7bf633c15acb95ed2dfd..e4fc9ed18c8c72554683bacaed4505da3749c308 100644 (file)
@@ -1158,10 +1158,19 @@ static int transport_localnet_handler(const struct aco_option *opt, struct ast_v
        return error;
 }
 
+static void localnet_to_vl_append(struct ast_variable **head, struct ast_ha *ha)
+{
+       char str[MAX_OBJECT_FIELD];
+       const char *addr = ast_strdupa(ast_sockaddr_stringify_addr(&ha->addr));
+       snprintf(str, MAX_OBJECT_FIELD, "%s%s/%s", ha->sense == AST_SENSE_ALLOW ? "!" : "",
+                        addr, ast_sockaddr_stringify_addr(&ha->netmask));
+
+       ast_variable_list_append(head, ast_variable_new("local_net", str, ""));
+}
+
 static int localnet_to_vl(const void *obj, struct ast_variable **fields)
 {
        const struct ast_sip_transport *transport = obj;
-       char str[MAX_OBJECT_FIELD];
        struct ast_variable *head = NULL;
        struct ast_ha *ha;
        RAII_VAR(struct ast_sip_transport_state *, state, find_state_by_transport(transport), ao2_cleanup);
@@ -1171,11 +1180,7 @@ static int localnet_to_vl(const void *obj, struct ast_variable **fields)
        }
 
        for (ha = state->localnet; ha; ha = ha->next) {
-               const char *addr = ast_strdupa(ast_sockaddr_stringify_addr(&ha->addr));
-               snprintf(str, MAX_OBJECT_FIELD, "%s%s/%s", ha->sense == AST_SENSE_ALLOW ? "!" : "",
-                       addr, ast_sockaddr_stringify_addr(&ha->netmask));
-
-               ast_variable_list_append(&head, ast_variable_new("local_net", str, ""));
+               localnet_to_vl_append(&head, ha);
        }
 
        if (head) {
index e79715b34dcdf4004de83bc71479266b71193927..ac4057b941ddcb62d5fa87eb208d4d06548b8b16 100644 (file)
@@ -551,20 +551,24 @@ static int match_to_str(const void *obj, const intptr_t *args, char **buf)
        return 0;
 }
 
-static int match_to_var_list(const void *obj, struct ast_variable **fields)
+static void match_to_var_list_append(struct ast_variable **head, struct ast_ha *ha)
 {
        char str[MAX_OBJECT_FIELD];
+       const char *addr = ast_strdupa(ast_sockaddr_stringify_addr(&ha->addr));
+       snprintf(str, MAX_OBJECT_FIELD, "%s%s/%s", ha->sense == AST_SENSE_ALLOW ? "!" : "",
+                        addr, ast_sockaddr_stringify_addr(&ha->netmask));
+
+       ast_variable_list_append(head, ast_variable_new("match", str, ""));
+}
+
+static int match_to_var_list(const void *obj, struct ast_variable **fields)
+{
        const struct ip_identify_match *identify = obj;
        struct ast_variable *head = NULL;
        struct ast_ha *ha = identify->matches;
 
        for (; ha; ha = ha->next) {
-               const char *addr = ast_strdupa(ast_sockaddr_stringify_addr(&ha->addr));
-               snprintf(str, MAX_OBJECT_FIELD, "%s%s/%s", ha->sense == AST_SENSE_ALLOW ? "!" : "",
-                       addr, ast_sockaddr_stringify_addr(&ha->netmask));
-
-               ast_variable_list_append(&head, ast_variable_new("match", str, ""));
-
+               match_to_var_list_append(&head, ha);
        }
 
        if (head) {
index 9024bdb212fa98d5f6e97a209e8ea2eed2eb382a..5963066191ad744b1da1c74ed07138594bcb7693 100644 (file)
@@ -1029,9 +1029,9 @@ static struct ast_sip_aor *find_registrar_aor(struct pjsip_rx_data *rdata, struc
                case AST_SIP_ENDPOINT_IDENTIFY_BY_USERNAME:
                        uri = pjsip_uri_get_uri(rdata->msg_info.to->uri);
 
-                       domain_name = ast_alloca(uri->host.slen + 1);
+                       domain_name = ast_malloc(uri->host.slen + 1);
                        ast_copy_pj_str(domain_name, &uri->host, uri->host.slen + 1);
-                       username = ast_alloca(uri->user.slen + 1);
+                       username = ast_malloc(uri->user.slen + 1);
                        ast_copy_pj_str(username, &uri->user, uri->user.slen + 1);
 
                        /*
@@ -1049,9 +1049,9 @@ static struct ast_sip_aor *find_registrar_aor(struct pjsip_rx_data *rdata, struc
                        while ((header = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_AUTHORIZATION,
                                header ? header->next : NULL))) {
                                if (header && !pj_stricmp2(&header->scheme, "digest")) {
-                                       username = ast_alloca(header->credential.digest.username.slen + 1);
+                                       username = ast_malloc(header->credential.digest.username.slen + 1);
                                        ast_copy_pj_str(username, &header->credential.digest.username, header->credential.digest.username.slen + 1);
-                                       domain_name = ast_alloca(header->credential.digest.realm.slen + 1);
+                                       domain_name = ast_malloc(header->credential.digest.realm.slen + 1);
                                        ast_copy_pj_str(domain_name, &header->credential.digest.realm, header->credential.digest.realm.slen + 1);
 
                                        aor_name = find_aor_name(username, domain_name, endpoint->aors);
@@ -1069,6 +1069,9 @@ static struct ast_sip_aor *find_registrar_aor(struct pjsip_rx_data *rdata, struc
                if (aor_name) {
                        break;
                }
+
+               ast_free(domain_name);
+               ast_free(username);
        }
 
        if (ast_strlen_zero(aor_name) || !(aor = ast_sip_location_retrieve_aor(aor_name))) {
@@ -1079,6 +1082,8 @@ static struct ast_sip_aor *find_registrar_aor(struct pjsip_rx_data *rdata, struc
                        username ?: "", ast_sorcery_object_get_id(endpoint));
        }
        ast_free(aor_name);
+       ast_free(domain_name);
+       ast_free(username);
        return aor;
 }
 
index cb68abeac9c73022112cf1bd9e840305333a93e6..7aa97b80ed79134fe3844c156329fe54c0f911a7 100644 (file)
@@ -2674,11 +2674,11 @@ static int __rtp_recvfrom(struct ast_rtp_instance *instance, void *buf, size_t s
                ao2_ref(ice, -1);
                ao2_lock(instance);
                if (status != PJ_SUCCESS) {
-                       char buf[100];
+                       char err_buf[100];
 
-                       pj_strerror(status, buf, sizeof(buf));
+                       pj_strerror(status, err_buf, sizeof(err_buf));
                        ast_log(LOG_WARNING, "PJ ICE Rx error status code: %d '%s'.\n",
-                               (int)status, buf);
+                               (int)status, err_buf);
                        return -1;
                }
                if (!rtp->passthrough) {
index 024f02b6a6899fca3e946943440ffe646035b9c8..7dda999a0e636fc9d471ae25b23f5a811413bd3b 100644 (file)
@@ -39,7 +39,7 @@ struct stasis_app_command {
        void *data;
        command_data_destructor_fn data_destructor;
        int retval;
-       int is_done:1;
+       unsigned int is_done:1;
 };
 
 static void command_dtor(void *obj)
index 4e2490d8b739816479a52ee4c08166e959f90866..dedf943118c63464e6b5d5f9df28df9207081779 100644 (file)
@@ -90,7 +90,7 @@ struct stasis_app_control {
        /*!
         * When set, /c app_stasis should exit and continue in the dialplan.
         */
-       int is_done:1;
+       unsigned int is_done:1;
 };
 
 static void control_dtor(void *obj)