From 781f4657b91d6c8fa3dcf3bc9f0daaad5155506e Mon Sep 17 00:00:00 2001 From: Kinsey Moore Date: Fri, 4 May 2012 22:17:38 +0000 Subject: Fix many issues from the NULL_RETURNS Coverity report Most of the changes here are trivial NULL checks. There are a couple optimizations to remove the need to check for NULL and outboundproxy parsing in chan_sip.c was rewritten to avoid use of strtok. Additionally, a bug was found and fixed with the parsing of outboundproxy when "outboundproxy=," was set. (Closes issue ASTERISK-19654) ........ Merged revisions 365398 from http://svn.asterisk.org/svn/asterisk/branches/1.8 ........ Merged revisions 365399 from http://svn.asterisk.org/svn/asterisk/branches/10 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@365400 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- apps/app_chanspy.c | 35 +++++++++++++++++++++-------------- apps/app_followme.c | 4 ++++ apps/app_stack.c | 11 +++++++++-- apps/app_voicemail.c | 4 ++++ 4 files changed, 38 insertions(+), 16 deletions(-) (limited to 'apps') diff --git a/apps/app_chanspy.c b/apps/app_chanspy.c index 23b4ab04e..07cc3d666 100644 --- a/apps/app_chanspy.c +++ b/apps/app_chanspy.c @@ -763,12 +763,10 @@ static int common_exec(struct ast_channel *chan, struct ast_flags *flags, const char *context, const char *mailbox, const char *name_context) { char nameprefix[AST_NAME_STRLEN]; - char peer_name[AST_NAME_STRLEN + 5]; char exitcontext[AST_MAX_CONTEXT] = ""; signed char zero_volume = 0; int waitms; int res; - char *ptr; int num_spyed_upon = 1; struct ast_channel_iterator *iter = NULL; @@ -858,7 +856,6 @@ static int common_exec(struct ast_channel *chan, struct ast_flags *flags, next_channel(iter, autochan, chan), next_autochan = NULL) { int igrp = !mygroup; int ienf = !myenforced; - char *s; if (autochan->chan == prev) { ast_autochan_destroy(autochan); @@ -943,20 +940,30 @@ static int common_exec(struct ast_channel *chan, struct ast_flags *flags, continue; } - strcpy(peer_name, "spy-"); - strncat(peer_name, ast_channel_name(autochan->chan), AST_NAME_STRLEN - 4 - 1); - ptr = strchr(peer_name, '/'); - *ptr++ = '\0'; - ptr = strsep(&ptr, "-"); - - for (s = peer_name; s < ptr; s++) - *s = tolower(*s); - if (!ast_test_flag(flags, OPTION_QUIET)) { + char peer_name[AST_NAME_STRLEN + 5]; + char *ptr, *s; + + strcpy(peer_name, "spy-"); + strncat(peer_name, ast_channel_name(autochan->chan), AST_NAME_STRLEN - 4 - 1); + if ((ptr = strchr(peer_name, '/'))) { + *ptr++ = '\0'; + for (s = peer_name; s < ptr; s++) { + *s = tolower(*s); + } + if ((s = strchr(ptr, '-'))) { + *s = '\0'; + } + } + if (ast_test_flag(flags, OPTION_NAME)) { const char *local_context = S_OR(name_context, "default"); const char *local_mailbox = S_OR(mailbox, ptr); - res = ast_app_sayname(chan, local_mailbox, local_context); + if (local_mailbox) { + res = ast_app_sayname(chan, local_mailbox, local_context); + } else { + res = -1; + } } if (!ast_test_flag(flags, OPTION_NAME) || res < 0) { int num; @@ -974,7 +981,7 @@ static int common_exec(struct ast_channel *chan, struct ast_flags *flags, res = ast_say_character_str(chan, peer_name, "", ast_channel_language(chan)); } } - if ((num = atoi(ptr))) { + if (ptr && (num = atoi(ptr))) { ast_say_digits(chan, num, "", ast_channel_language(chan)); } } diff --git a/apps/app_followme.c b/apps/app_followme.c index 99fb38f43..10d165aca 100644 --- a/apps/app_followme.c +++ b/apps/app_followme.c @@ -904,6 +904,10 @@ static void findmeexec(struct fm_args *tpargs) struct findme_user_listptr *findme_user_list; findme_user_list = ast_calloc(1, sizeof(*findme_user_list)); + if (!findme_user_list) { + ast_log(LOG_WARNING, "Failed to allocate memory for findme_user_list\n"); + return; + } AST_LIST_HEAD_INIT_NOLOCK(findme_user_list); /* We're going to figure out what the longest possible string of digits to collect is */ diff --git a/apps/app_stack.c b/apps/app_stack.c index 355591e74..eca3e8398 100644 --- a/apps/app_stack.c +++ b/apps/app_stack.c @@ -764,8 +764,15 @@ static int handle_gosub(struct ast_channel *chan, AGI *agi, int argc, const char struct ast_pbx *pbx = ast_channel_pbx(chan); struct ast_pbx_args args; struct ast_datastore *stack_store = ast_channel_datastore_find(chan, &stack_info, NULL); - AST_LIST_HEAD(,gosub_stack_frame) *oldlist = stack_store->data; - struct gosub_stack_frame *cur = AST_LIST_FIRST(oldlist); + AST_LIST_HEAD(,gosub_stack_frame) *oldlist; + struct gosub_stack_frame *cur; + if (!stack_store) { + ast_log(LOG_WARNING, "No GoSub stack remaining after AGI GoSub execution.\n"); + ast_free(gosub_args); + return RESULT_FAILURE; + } + oldlist = stack_store->data; + cur = AST_LIST_FIRST(oldlist); cur->is_agi = 1; memset(&args, 0, sizeof(args)); diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c index 0f9cad5d8..54b199a0b 100644 --- a/apps/app_voicemail.c +++ b/apps/app_voicemail.c @@ -11724,6 +11724,10 @@ static void mwi_unsub_event_cb(const struct ast_event *event, void *userdata) if (ast_event_get_ie_uint(event, AST_EVENT_IE_EVENTTYPE) != AST_EVENT_MWI) return; + if (!uniqueid) { + ast_log(LOG_ERROR, "Unable to allocate memory for uniqueid\n"); + return; + } u = ast_event_get_ie_uint(event, AST_EVENT_IE_UNIQUEID); *uniqueid = u; if (ast_taskprocessor_push(mwi_subscription_tps, handle_unsubscribe, uniqueid) < 0) { -- cgit v1.2.3