Coverity Report: Fix issues for error type CHECKED_RETURN for core
authorJonathan Rose <jrose@digium.com>
Thu, 10 May 2012 18:35:14 +0000 (18:35 +0000)
committerJonathan Rose <jrose@digium.com>
Thu, 10 May 2012 18:35:14 +0000 (18:35 +0000)
(issue ASTERISK-19658)
Reported by: Matt Jordan
Review: https://reviewboard.asterisk.org/r/1905/
........

Merged revisions 366094 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 366106 from http://svn.asterisk.org/svn/asterisk/branches/10

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@366126 65c4cc65-6c06-0410-ace0-fbb531ad65f3

14 files changed:
apps/app_queue.c
apps/app_voicemail.c
channels/chan_iax2.c
channels/chan_sip.c
channels/iax2-provision.c
channels/sig_analog.c
funcs/func_devstate.c
funcs/func_lock.c
main/acl.c
main/asterisk.c
main/features.c
main/pbx.c
main/xmldoc.c
res/ael/ael.flex

index e6b9970..7db0819 100644 (file)
@@ -4946,7 +4946,9 @@ static int try_calling(struct queue_ent *qe, const struct ast_flags opts, char *
                                        res2 |= ast_safe_sleep(peer, qe->parent->memberdelay * 1000);
                                }
                                if (!res2 && announce) {
-                                       play_file(peer, announce);
+                                       if (play_file(peer, announce) < 0) {
+                                               ast_log(LOG_ERROR, "play_file failed for '%s' on %s\n", announce, ast_channel_name(peer));
+                                       }
                                }
                                if (!res2 && qe->parent->reportholdtime) {
                                        if (!play_file(peer, qe->parent->sound_reporthold)) {
@@ -4957,11 +4959,15 @@ static int try_calling(struct queue_ent *qe, const struct ast_flags opts, char *
                                                holdtimesecs = abs((now - qe->start) % 60);
                                                if (holdtime > 0) {
                                                        ast_say_number(peer, holdtime, AST_DIGIT_ANY, ast_channel_language(peer), NULL);
-                                                       play_file(peer, qe->parent->sound_minutes);
+                                                       if (play_file(peer, qe->parent->sound_minutes) < 0) {
+                                                               ast_log(LOG_ERROR, "play_file failed for '%s' on %s\n", qe->parent->sound_minutes, ast_channel_name(peer));
+                                                       }
                                                }
                                                if (holdtimesecs > 1) {
                                                        ast_say_number(peer, holdtimesecs, AST_DIGIT_ANY, ast_channel_language(peer), NULL);
-                                                       play_file(peer, qe->parent->sound_seconds);
+                                                       if (play_file(peer, qe->parent->sound_seconds) < 0) {
+                                                               ast_log(LOG_ERROR, "play_file failed for '%s' on %s\n", qe->parent->sound_seconds, ast_channel_name(peer));
+                                                       }
                                                }
                                        }
                                }
index 55aec5d..d4da42b 100644 (file)
@@ -6983,7 +6983,10 @@ static int vm_forwardoptions(struct ast_channel *chan, struct ast_vm_user *vmu,
                        strncat(vms->introfn, "intro", sizeof(vms->introfn));
                        ast_play_and_wait(chan, INTRO);
                        ast_play_and_wait(chan, "beep");
-                       play_record_review(chan, NULL, vms->introfn, vmu->maxsecs, vm_fmts, 1, vmu, (int *) duration, NULL, NULL, record_gain, vms, flag);
+                       cmd = play_record_review(chan, NULL, vms->introfn, vmu->maxsecs, vm_fmts, 1, vmu, (int *) duration, NULL, NULL, record_gain, vms, flag);
+                       if (cmd == -1) {
+                               break;
+                       }
                        cmd = 't';
 #else
 
@@ -9561,7 +9564,10 @@ static int vm_tempgreeting(struct ast_channel *chan, struct ast_vm_user *vmu, st
                        retries = 0;
                RETRIEVE(prefile, -1, vmu->mailbox, vmu->context);
                if (ast_fileexists(prefile, NULL, NULL) <= 0) {
-                       play_record_review(chan, "vm-rec-temp", prefile, maxgreet, fmtc, 0, vmu, &duration, NULL, NULL, record_gain, vms, NULL);
+                       cmd = play_record_review(chan, "vm-rec-temp", prefile, maxgreet, fmtc, 0, vmu, &duration, NULL, NULL, record_gain, vms, NULL);
+                       if (cmd == -1) {
+                               break;
+                       }
                        cmd = 't';      
                } else {
                        switch (cmd) {
@@ -11762,6 +11768,7 @@ static void mwi_sub_event_cb(const struct ast_event *event, void *userdata)
 
 static void start_poll_thread(void)
 {
+       int errcode;
        mwi_sub_sub = ast_event_subscribe(AST_EVENT_SUB, mwi_sub_event_cb, "Voicemail MWI subscription", NULL,
                AST_EVENT_IE_EVENTTYPE, AST_EVENT_IE_PLTYPE_UINT, AST_EVENT_MWI,
                AST_EVENT_IE_END);
@@ -11775,7 +11782,9 @@ static void start_poll_thread(void)
 
        poll_thread_run = 1;
 
-       ast_pthread_create(&poll_thread, NULL, mb_poll_thread, NULL);
+       if ((errcode = ast_pthread_create(&poll_thread, NULL, mb_poll_thread, NULL))) {
+               ast_log(LOG_ERROR, "Could not create thread: %s\n", strerror(errcode));
+       }
 }
 
 static void stop_poll_thread(void)
index baee946..8903041 100644 (file)
@@ -4382,11 +4382,13 @@ static struct iax2_peer *realtime_peer(const char *peername, struct sockaddr_in
                                /* Whoops, we weren't supposed to exist! */
                                peer = peer_unref(peer);
                                break;
-                       } 
+                       }
                } else if (!strcasecmp(tmp->name, "regseconds")) {
                        ast_get_time_t(tmp->value, &regseconds, 0, NULL);
                } else if (!strcasecmp(tmp->name, "ipaddr")) {
-                       ast_sockaddr_parse(&peer->addr, tmp->value, PARSE_PORT_IGNORE);
+                       if (!ast_sockaddr_parse(&peer->addr, tmp->value, PARSE_PORT_IGNORE)) {
+                               ast_log(LOG_WARNING, "Failed to parse sockaddr '%s' for ipaddr of realtime peer '%s'\n", tmp->value, tmp->name);
+                       }
                } else if (!strcasecmp(tmp->name, "port")) {
                        ast_sockaddr_set_port(&peer->addr, atoi(tmp->value));
                } else if (!strcasecmp(tmp->name, "host")) {
@@ -11653,6 +11655,7 @@ static void iax2_process_thread_cleanup(void *data)
        ast_mutex_destroy(&thread->init_lock);
        ast_cond_destroy(&thread->init_cond);
        ast_free(thread);
+       /* Ignore check_return warning from Coverity for ast_atomic_dec_and_test below */
        ast_atomic_dec_and_test(&iaxactivethreadcount);
 }
 
@@ -12234,7 +12237,10 @@ static int start_network_thread(void)
                        AST_LIST_UNLOCK(&idle_list);
                }
        }
-       ast_pthread_create_background(&netthreadid, NULL, network_thread, NULL);
+       if (ast_pthread_create_background(&netthreadid, NULL, network_thread, NULL)) {
+               ast_log(LOG_ERROR, "Failed to create new thread!\n");
+               return -1;
+       }
        ast_verb(2, "%d helper threads started\n", threadcount);
        return 0;
 }
index c7c6a38..de2c80e 100644 (file)
@@ -16384,7 +16384,9 @@ static void check_via(struct sip_pvt *p, struct sip_request *req)
                        p->sa = p->recv;
                }
 
-               ast_sockaddr_resolve_first(&tmp, c, 0);
+               if (ast_sockaddr_resolve_first(&tmp, c, 0)) {
+                       ast_log(LOG_WARNING, "Could not resolve socket address for '%s'\n", c);
+               }
                port = ast_sockaddr_port(&tmp);
                ast_sockaddr_set_port(&p->sa,
                                      port != 0 ? port : STANDARD_SIP_PORT);
@@ -16733,6 +16735,7 @@ static enum check_auth_result check_user_full(struct sip_pvt *p, struct sip_requ
 
        /* Finally, apply the guest policy */
        if (sip_cfg.allowguest) {
+               /* Ignore check_return warning from Coverity for get_rpid below. */
                get_rpid(p, req);
                p->rtptimeout = global_rtptimeout;
                p->rtpholdtimeout = global_rtpholdtimeout;
@@ -18682,7 +18685,10 @@ static int show_chanstats_cb(void *__cur, void *__arg, int flags)
                return 0;       /* don't care, we scan all channels */
        }
 
-       ast_rtp_instance_get_stats(cur->rtp, &stats, AST_RTP_INSTANCE_STAT_ALL);
+       if (ast_rtp_instance_get_stats(cur->rtp, &stats, AST_RTP_INSTANCE_STAT_ALL)) {
+               ast_log(LOG_WARNING, "Could not get RTP stats.\n");
+               return 0;
+       }
 
        if (c && ast_channel_cdr(c) && !ast_tvzero(ast_channel_cdr(c)->start)) {
                duration = (int)(ast_tvdiff_ms(ast_tvnow(), ast_channel_cdr(c)->start) / 1000);
index 03b042b..eaa3b74 100644 (file)
@@ -258,7 +258,11 @@ int iax_provision_version(unsigned int *version, const char *template, int force
        memset(&ied, 0, sizeof(ied));
 
        ast_mutex_lock(&provlock);
-       ast_db_get("iax/provisioning/cache", template, tmp, sizeof(tmp));
+       if (!(ast_db_get("iax/provisioning/cache", template, tmp, sizeof(tmp)))) {
+               ast_log(LOG_ERROR, "ast_db_get failed to retrieve iax/provisioning/cache\n");
+               ast_mutex_unlock(&provlock);
+               return -1;
+       }
        if (sscanf(tmp, "v%30x", version) != 1) {
                if (strcmp(tmp, "u")) {
                        ret = iax_provision_build(&ied, version, template, force);
index 7112cf2..6352335 100644 (file)
@@ -2744,7 +2744,10 @@ static struct ast_frame *__analog_handle_event(struct analog_pvt *p, struct ast_
                                analog_train_echocanceller(p);
                                ast_copy_string(p->dop.dialstr, p->echorest, sizeof(p->dop.dialstr));
                                p->dop.op = ANALOG_DIAL_OP_REPLACE;
-                               analog_dial_digits(p, ANALOG_SUB_REAL, &p->dop);
+                               if (analog_dial_digits(p, ANALOG_SUB_REAL, &p->dop)) {
+                                       int dial_err = errno;
+                                       ast_log(LOG_WARNING, "Dialing failed on channel %d: %s\n", p->channel, strerror(dial_err));
+                               }
                                p->echobreak = 0;
                        } else {
                                analog_set_dialing(p, 0);
index 1b1318a..e1f3438 100644 (file)
@@ -187,6 +187,7 @@ static enum ast_device_state custom_devstate_callback(const char *data)
 {
        char buf[256] = "";
 
+       /* Ignore check_return warning from Coverity fow ast_db_get below */
        ast_db_get(astdb_family, data, buf, sizeof(buf));
 
        return ast_devstate_val(buf);
index 38c3aea..060fcb8 100644 (file)
@@ -486,9 +486,11 @@ static int unload_module(void)
        ast_custom_function_unregister(&trylock_function);
        ast_custom_function_unregister(&unlock_function);
 
-       pthread_cancel(broker_tid);
-       pthread_kill(broker_tid, SIGURG);
-       pthread_join(broker_tid, NULL);
+       if (broker_tid != AST_PTHREADT_NULL) {
+               pthread_cancel(broker_tid);
+               pthread_kill(broker_tid, SIGURG);
+               pthread_join(broker_tid, NULL);
+       }
 
        AST_LIST_UNLOCK(&locklist);
 
@@ -500,7 +502,14 @@ static int load_module(void)
        int res = ast_custom_function_register(&lock_function);
        res |= ast_custom_function_register(&trylock_function);
        res |= ast_custom_function_register(&unlock_function);
-       ast_pthread_create_background(&broker_tid, NULL, lock_broker, NULL);
+
+       if (ast_pthread_create_background(&broker_tid, NULL, lock_broker, NULL)) {
+               ast_log(LOG_ERROR, "Failed to start lock broker thread. Unloading func_lock module.\n");
+               broker_tid = AST_PTHREADT_NULL;
+               unload_module();
+               return AST_MODULE_LOAD_DECLINE;
+       }
+
        return res;
 }
 
index 7616236..5902026 100644 (file)
@@ -533,7 +533,11 @@ int ast_apply_ha(const struct ast_ha *ha, const struct ast_sockaddr *addr)
                        if (ast_sockaddr_is_ipv6(addr)) {
                                if (ast_sockaddr_is_ipv4_mapped(addr)) {
                                        /* IPv4 ACLs apply to IPv4-mapped addresses */
-                                       ast_sockaddr_ipv4_mapped(addr, &mapped_addr);
+                                       if (!ast_sockaddr_ipv4_mapped(addr, &mapped_addr)) {
+                                               ast_log(LOG_ERROR, "%s provided to ast_sockaddr_ipv4_mapped could not be converted. That shouldn't be possible.\n",
+                                                       ast_sockaddr_stringify(addr));
+                                               continue;
+                                       }
                                        addr_to_use = &mapped_addr;
                                } else {
                                        /* An IPv4 ACL does not apply to an IPv6 address */
index d7fda95..972c2fb 100644 (file)
@@ -1468,7 +1468,11 @@ static int ast_makesocket(void)
                ast_log(LOG_WARNING, "Unable to register network verboser?\n");
        }
 
-       ast_pthread_create_background(&lthread, NULL, listener, NULL);
+       if (ast_pthread_create_background(&lthread, NULL, listener, NULL)) {
+               ast_log(LOG_WARNING, "Unable to create listener thread.\n");
+               close(ast_socket);
+               return -1;
+       }
 
        if (!ast_strlen_zero(ast_config_AST_CTL_OWNER)) {
                struct passwd *pw;
@@ -3345,9 +3349,8 @@ static void *canary_thread(void *unused)
        sleep(120);
 
        for (;;) {
-               stat(canary_filename, &canary_stat);
                now = ast_tvnow();
-               if (now.tv_sec > canary_stat.st_mtime + 60) {
+               if (stat(canary_filename, &canary_stat) || now.tv_sec > canary_stat.st_mtime + 60) {
                        ast_log(LOG_WARNING,
                                "The canary is no more.  He has ceased to be!  "
                                "He's expired and gone to meet his maker!  "
index c9ea91a..4ff629f 100644 (file)
@@ -8658,7 +8658,9 @@ int ast_features_init(void)
                return res;
        }
        ast_cli_register_multiple(cli_features, ARRAY_LEN(cli_features));
-       ast_pthread_create(&parking_thread, NULL, do_parking_thread, NULL);
+       if (ast_pthread_create(&parking_thread, NULL, do_parking_thread, NULL)) {
+               return -1;
+       }
        ast_register_application2(app_bridge, bridge_exec, NULL, NULL, NULL);
        res = ast_register_application2(parkedcall, parked_call_exec, NULL, NULL, NULL);
        if (!res)
index e4774f2..f04051c 100644 (file)
@@ -6709,8 +6709,10 @@ static int show_debug_helper(int fd, const char *context, const char *exten, str
 
                dpc->context_existence = 1;
 
-               if (!c->pattern_tree)
+               if (!c->pattern_tree) {
+                       /* Ignore check_return warning from Coverity for ast_exists_extension below */
                        ast_exists_extension(NULL, c->name, "s", 1, ""); /* do this to force the trie to built, if it is not already */
+               }
 
                ast_rdlock_context(c);
 
index 7008134..f3deb5d 100644 (file)
@@ -1715,7 +1715,11 @@ static void xmldoc_parse_parameter(struct ast_xml_node *fixnode, const char *tab
                                ast_xml_free_attr(paramname);
                                printed = 1;
                        }
-                       xmldoc_parse_para(node, internaltabs, "\n", buffer);
+                       if (xmldoc_parse_para(node, internaltabs, "\n", buffer)) {
+                               /* If anything ever goes in below this condition before the continue below,
+                                * we should probably continue immediately. */
+                               continue;
+                       }
                        continue;
                } else if ((xmldoc_parse_specialtags(node, internaltabs, "\n", buffer))) {
                        continue;
index 4d441fb..dab6ac0 100644 (file)
@@ -805,7 +805,9 @@ struct pval *ael2_parse(char *filename, int *errors)
        if (my_file)
                free(my_file);
        my_file = strdup(filename);
-       stat(filename, &stats);
+       if (stat(filename, &stats)) {
+               ast_log(LOG_WARNING, "failed to populate stats from file '%s'\n", filename);
+       }
        buffer = (char*)malloc(stats.st_size+2);
        if (fread(buffer, 1, stats.st_size, fin) != stats.st_size) {
                ast_log(LOG_ERROR, "fread() failed: %s\n", strerror(errno));
@@ -875,7 +877,9 @@ static void setup_filestack(char *fnamebuf2, int fnamebuf_siz, glob_t *globbuf,
                } else {
                        char *buffer;
                        struct stat stats;
-                       stat(fnamebuf2, &stats);
+                       if (stat(fnamebuf2, &stats)) {
+                               ast_log(LOG_WARNING, "Failed to populate stats from file '%s'\n", fnamebuf2);
+                       }
                        buffer = (char*)malloc(stats.st_size+1);
                        if (fread(buffer, 1, stats.st_size, in1) != stats.st_size) {
                                ast_log(LOG_ERROR, "fread() failed: %s\n", strerror(errno));