From bb9afcb3880c37acff83fadf0c93ce248128f592 Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Fri, 8 Sep 2023 18:17:57 +0100 Subject: [PATCH] [core] Coverity fixes * [core] Coverity 1518099, 1518097, 1518098 (Unchecked return value from library) * [core] Coverity 1468551 Unchecked return value * [core] Coverity 1468293 Unchecked return value * [core] Coverity 1468274 Explicit null dereferenced * [core] Coverity 1395588 Unchecked return value * [core] Coverity 1395515 Logically dead code * [core] Coverity 1364984 Result is not floating-point * [core] Coverity 1395554, 1468440 Dereference before null check * [core] Coverity 1024487 Dereference after null check * [core] Coverity 1024872 Unchecked return value * [core] Coverity 1025822 Unchecked return value * [core] Coverity 1025823 Unchecked return value * [core] Coverity 1087637, 1346467, 1087638 Unchecked return value * [core] Coverity 1107607 Unchecked return value * [core] Coverity 1210777 Unchecked return value * [core] Coverity 1227670 Dereference before null check * [core] Coverity 1024551 Logically dead code * [core] Coverity 1024560 Logically dead code * [core] Coverity 1024664 Operands don't affect result * [core] Coverity 1364957 Dereference after null check * [core] Coverity 1395572 Logically dead code * [core] Coverity 1412459 Unchecked return value * [core] Coverity 1412490 Unchecked return value * [core] Coverity 1395515/2 Logically dead code * [core] Coverity cleanup --- src/cJSON.c | 44 +++++++++++++++++++------------------- src/switch_core_media.c | 43 ++++++++++++++++++++++--------------- src/switch_core_memory.c | 5 ++++- src/switch_core_sqldb.c | 8 ++++--- src/switch_cpp.cpp | 13 +++++------ src/switch_curl.c | 34 ++++++++++++++++++++++++----- src/switch_event.c | 9 +++++--- src/switch_ivr.c | 12 +++++++++-- src/switch_ivr_async.c | 2 +- src/switch_ivr_originate.c | 8 ++----- src/switch_ivr_play_say.c | 10 ++++++--- src/switch_stun.c | 23 ++++++++++++++++---- src/switch_vpx.c | 2 +- src/switch_xml.c | 9 +++----- 14 files changed, 142 insertions(+), 80 deletions(-) diff --git a/src/cJSON.c b/src/cJSON.c index 6d0e4946fd..ae0a2e2007 100644 --- a/src/cJSON.c +++ b/src/cJSON.c @@ -1104,34 +1104,32 @@ static unsigned char *print(const cJSON * const item, cJSON_bool format, const i buffer->length = default_buffer_size; buffer->format = format; buffer->hooks = *hooks; - if (buffer->buffer == NULL) - { + + if (buffer->buffer == NULL) { goto fail; } /* print the value */ - if (!print_value(item, buffer)) - { + if (!print_value(item, buffer)) { goto fail; } + update_offset(buffer); /* check if reallocate is available */ - if (hooks->reallocate != NULL) - { + if (hooks->reallocate != NULL) { printed = (unsigned char*) hooks->reallocate(buffer->buffer, buffer->offset + 1); if (printed == NULL) { goto fail; } + buffer->buffer = NULL; - } - else /* otherwise copy the JSON over to a new buffer */ - { + } else { /* otherwise copy the JSON over to a new buffer */ printed = (unsigned char*) hooks->allocate(buffer->offset + 1); - if (printed == NULL) - { + if (printed == NULL) { goto fail; } + memcpy(printed, buffer->buffer, cjson_min(buffer->length, buffer->offset + 1)); printed[buffer->offset] = '\0'; /* just to be sure */ @@ -1142,16 +1140,10 @@ static unsigned char *print(const cJSON * const item, cJSON_bool format, const i return printed; fail: - if (buffer->buffer != NULL) - { + if (buffer->buffer != NULL) { hooks->deallocate(buffer->buffer); } - if (printed != NULL) - { - hooks->deallocate(printed); - } - return NULL; } @@ -1942,33 +1934,41 @@ static cJSON_bool add_item_to_object(cJSON * const object, const char * const st CJSON_PUBLIC(void) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item) { - add_item_to_object(object, string, item, &global_hooks, false); + cJSON_bool res = add_item_to_object(object, string, item, &global_hooks, false); + (void)res; } /* Add an item to an object with constant string as key */ CJSON_PUBLIC(void) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item) { - add_item_to_object(object, string, item, &global_hooks, true); + cJSON_bool res = add_item_to_object(object, string, item, &global_hooks, true); + (void)res; } CJSON_PUBLIC(void) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) { + cJSON_bool res; + if (array == NULL) { return; } - add_item_to_array(array, create_reference(item, &global_hooks)); + res = add_item_to_array(array, create_reference(item, &global_hooks)); + (void)res; } CJSON_PUBLIC(void) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item) { + cJSON_bool res; + if ((object == NULL) || (string == NULL)) { return; } - add_item_to_object(object, string, create_reference(item, &global_hooks), &global_hooks, false); + res = add_item_to_object(object, string, create_reference(item, &global_hooks), &global_hooks, false); + (void)res; } CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name) diff --git a/src/switch_core_media.c b/src/switch_core_media.c index 252d947035..0c92a2a156 100644 --- a/src/switch_core_media.c +++ b/src/switch_core_media.c @@ -722,13 +722,10 @@ SWITCH_DECLARE(payload_map_t *) switch_core_media_add_payload_map(switch_core_se exists = (type == pmap->type && !strcasecmp(name, pmap->iananame) && pmap->pt == pt && (!pmap->rate || rate == pmap->rate) && (!pmap->ptime || pmap->ptime == ptime)); break; case SWITCH_MEDIA_TYPE_VIDEO: - if (sdp_type == SDP_TYPE_RESPONSE) { - exists = (pmap->sdp_type == SDP_TYPE_REQUEST && type == pmap->type && !strcasecmp(name, pmap->iananame)); - } else { - exists = (type == pmap->type && !strcasecmp(name, pmap->iananame)); - } + exists = (pmap->sdp_type == SDP_TYPE_REQUEST && type == pmap->type && !strcasecmp(name, pmap->iananame)); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "CHECK PMAP %s:%s %d %s:%s %d ... %d\n", - name, sdp_type == SDP_TYPE_REQUEST ? "REQ" : "RES", pt, + name, "RES", pt, pmap->iananame, pmap->sdp_type == SDP_TYPE_REQUEST ? "REQ" : "RES", pmap->pt, exists); @@ -2524,7 +2521,7 @@ static void check_jb_sync(switch_core_session_t *session) } if (!jb_sync_msec && frames) { - jb_sync_msec = (double)(1000 / fps) * frames; + jb_sync_msec = ((double)1000 / fps) * frames; } switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), @@ -4624,9 +4621,10 @@ static void check_stream_changes(switch_core_session_t *session, const char *r_s { switch_core_session_t *other_session = NULL; switch_core_session_message_t *msg; + switch_status_t status = SWITCH_STATUS_SUCCESS; - switch_core_session_get_partner(session, &other_session); - + status = switch_core_session_get_partner(session, &other_session); + (void)status; if (switch_channel_test_flag(session->channel, CF_STREAM_CHANGED)) { switch_channel_clear_flag(session->channel, CF_STREAM_CHANGED); @@ -4662,13 +4660,15 @@ static void check_stream_changes(switch_core_session_t *session, const char *r_s if (switch_channel_test_flag(other_session->channel, CF_AWAITING_STREAM_CHANGE)) { uint8_t proceed = 1; const char *sdp_in, *other_ep; + uint8_t res = 0; if ((other_ep = switch_channel_get_variable(session->channel, "ep_codec_string"))) { switch_channel_set_variable(other_session->channel, "codec_string", other_ep); } sdp_in = switch_channel_get_variable(other_session->channel, SWITCH_R_SDP_VARIABLE); - switch_core_media_negotiate_sdp(other_session, sdp_in, &proceed, SDP_TYPE_REQUEST); + res = switch_core_media_negotiate_sdp(other_session, sdp_in, &proceed, SDP_TYPE_REQUEST); + (void)res; switch_core_media_activate_rtp(other_session); msg = switch_core_session_alloc(other_session, sizeof(*msg)); msg->message_id = SWITCH_MESSAGE_INDICATE_RESPOND; @@ -13587,6 +13587,7 @@ static void switch_core_media_set_r_sdp_codec_string(switch_core_session_t *sess if (zstr(attr->a_name)) { continue; } + if (!strcasecmp(attr->a_name, "ptime")) { dptime = atoi(attr->a_value); break; @@ -13599,22 +13600,27 @@ static void switch_core_media_set_r_sdp_codec_string(switch_core_session_t *sess if ((m->m_type == sdp_media_audio || m->m_type == sdp_media_video) && m->m_port) { for (map = m->m_rtpmaps; map; map = map->rm_next) { int found = 0; + for (attr = m->m_attributes; attr && found < 2; attr = attr->a_next) { if (zstr(attr->a_name)) { continue; } + if (!strcasecmp(attr->a_name, "ptime") && attr->a_value) { ptime = atoi(attr->a_value); found++; } + if (!strcasecmp(attr->a_name, "rtcp-mux")) { if (switch_channel_var_true(channel, "rtcp_mux_auto_detect")) { switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG, "setting rtcp-mux from sdp\n"); switch_channel_set_variable(channel, "rtcp_mux", "true"); } + found++; } } + switch_core_media_add_payload_map(session, m->m_type == sdp_media_audio ? SWITCH_MEDIA_TYPE_AUDIO : SWITCH_MEDIA_TYPE_VIDEO, map->rm_encoding, @@ -13640,11 +13646,13 @@ static void switch_core_media_set_r_sdp_codec_string(switch_core_session_t *sess if (zstr(attr->a_name)) { continue; } + if (!strcasecmp(attr->a_name, "ptime") && attr->a_value) { ptime = atoi(attr->a_value); break; } } + connection = sdp->sdp_connection; if (m->m_connections) { connection = m->m_connections; @@ -13658,7 +13666,7 @@ static void switch_core_media_set_r_sdp_codec_string(switch_core_session_t *sess if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_INBOUND || prefer_sdp) { for (map = m->m_rtpmaps; map; map = map->rm_next) { - if (map->rm_pt > 127 || already_did[map->rm_pt]) { + if (already_did[map->rm_pt]) { continue; } @@ -13679,19 +13687,20 @@ static void switch_core_media_set_r_sdp_codec_string(switch_core_session_t *sess if (match) { add_audio_codec(map, imp, ptime, buf, sizeof(buf)); } - } } } else { for (i = 0; i < num_codecs; i++) { const switch_codec_implementation_t *imp = codecs[i]; + if (imp->codec_type != SWITCH_CODEC_TYPE_AUDIO || imp->ianacode > 127 || already_did[imp->ianacode]) { continue; } + for (map = m->m_rtpmaps; map; map = map->rm_next) { - if (map->rm_pt > 127 || already_did[map->rm_pt]) { + if (already_did[map->rm_pt]) { continue; } @@ -13724,11 +13733,10 @@ static void switch_core_media_set_r_sdp_codec_string(switch_core_session_t *sess break; } - if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_INBOUND || prefer_sdp) { for (map = m->m_rtpmaps; map; map = map->rm_next) { - if (map->rm_pt > 127 || already_did[map->rm_pt]) { + if (already_did[map->rm_pt]) { continue; } @@ -13752,11 +13760,11 @@ static void switch_core_media_set_r_sdp_codec_string(switch_core_session_t *sess } else { switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), ",%s.%s", imp->modname, imp->iananame); } + already_did[imp->ianacode] = 1; } } } - } else { for (i = 0; i < num_codecs; i++) { const switch_codec_implementation_t *imp = codecs[i]; @@ -13772,7 +13780,7 @@ static void switch_core_media_set_r_sdp_codec_string(switch_core_session_t *sess for (map = m->m_rtpmaps; map; map = map->rm_next) { - if (map->rm_pt > 127 || already_did[map->rm_pt]) { + if (already_did[map->rm_pt]) { continue; } @@ -13793,6 +13801,7 @@ static void switch_core_media_set_r_sdp_codec_string(switch_core_session_t *sess } else { switch_snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), ",%s.%s", imp->modname, imp->iananame); } + already_did[imp->ianacode] = 1; } } diff --git a/src/switch_core_memory.c b/src/switch_core_memory.c index 7d3f4adbd7..77be1812c5 100644 --- a/src/switch_core_memory.c +++ b/src/switch_core_memory.c @@ -501,9 +501,12 @@ SWITCH_DECLARE(switch_status_t) switch_core_perform_destroy_memory_pool(switch_m #if APR_POOL_DEBUG fspr_pool_destroy_debug(tmp_pool, func); #else - fspr_pool_destroy(tmp_pool); + if (tmp_pool) { + fspr_pool_destroy(tmp_pool); + } #endif #ifdef USE_MEM_LOCK + switch_mutex_unlock(memory_manager.mem_lock); #endif } diff --git a/src/switch_core_sqldb.c b/src/switch_core_sqldb.c index 5a75aeb573..817a7a7586 100644 --- a/src/switch_core_sqldb.c +++ b/src/switch_core_sqldb.c @@ -2065,6 +2065,7 @@ static uint32_t do_trans(switch_sql_queue_manager_t *qm) switch_status_t status; uint32_t ttl = 0; uint32_t i; + switch_status_t res; if (!zstr(qm->pre_trans_execute)) { switch_cache_db_execute_sql_real(qm->event_db, qm->pre_trans_execute, &errmsg); @@ -2126,7 +2127,8 @@ static uint32_t do_trans(switch_sql_queue_manager_t *qm) for (i = 0; (qm->max_trans == 0 || ttl <= qm->max_trans) && (i < qm->numq); i++) { switch_mutex_lock(qm->mutex); - switch_queue_trypop(qm->sql_queue[i], &pop); + res = switch_queue_trypop(qm->sql_queue[i], &pop); + (void)res; switch_mutex_unlock(qm->mutex); if (pop) break; } @@ -2138,6 +2140,7 @@ static uint32_t do_trans(switch_sql_queue_manager_t *qm) switch_mutex_unlock(qm->mutex); ttl++; } + switch_safe_free(pop); if (status != SWITCH_STATUS_SUCCESS) break; } else { @@ -2153,7 +2156,6 @@ static uint32_t do_trans(switch_sql_queue_manager_t *qm) } } - end: switch(qm->event_db->type) { @@ -2190,11 +2192,11 @@ static uint32_t do_trans(switch_sql_queue_manager_t *qm) } } - switch_mutex_lock(qm->mutex); for (i = 0; i < qm->numq; i++) { qm->written[i] = qm->pre_written[i]; } + switch_mutex_unlock(qm->mutex); return ttl; diff --git a/src/switch_cpp.cpp b/src/switch_cpp.cpp index fe71a6400a..cd234a30e5 100644 --- a/src/switch_cpp.cpp +++ b/src/switch_cpp.cpp @@ -98,6 +98,7 @@ SWITCH_DECLARE(Event *) EventConsumer::pop(int block, int timeout) void *pop = NULL; Event *ret = NULL; switch_event_t *event; + switch_status_t res; if (!ready) { return NULL; @@ -105,14 +106,16 @@ SWITCH_DECLARE(Event *) EventConsumer::pop(int block, int timeout) if (block) { if (timeout > 0) { - switch_queue_pop_timeout(events, &pop, (switch_interval_time_t) timeout * 1000); // millisec rather than microsec + res = switch_queue_pop_timeout(events, &pop, (switch_interval_time_t) timeout * 1000); // millisec rather than microsec } else { - switch_queue_pop(events, &pop); + res = switch_queue_pop(events, &pop); } } else { - switch_queue_trypop(events, &pop); + res = switch_queue_trypop(events, &pop); } + (void)res; + if ((event = (switch_event_t *) pop)) { ret = new Event(event, 1); } @@ -138,9 +141,7 @@ SWITCH_DECLARE(void) EventConsumer::cleanup() node_index = 0; - if (events) { - switch_queue_interrupt_all(events); - } + switch_queue_interrupt_all(events); while(switch_queue_trypop(events, &pop) == SWITCH_STATUS_SUCCESS) { switch_event_t *event = (switch_event_t *) pop; diff --git a/src/switch_curl.c b/src/switch_curl.c index d6cfd6ce19..0a8cb682c3 100644 --- a/src/switch_curl.c +++ b/src/switch_curl.c @@ -64,6 +64,7 @@ SWITCH_DECLARE(switch_status_t) switch_curl_process_mime(switch_event_t *event, curl_mime *mime = NULL; curl_mimepart *part = NULL; uint8_t added = 0; + switch_CURLcode curl_code = CURLE_OK; #else struct curl_httppost *formpost=NULL; struct curl_httppost *lastptr=NULL; @@ -98,9 +99,21 @@ SWITCH_DECLARE(switch_status_t) switch_curl_process_mime(switch_event_t *event, #if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800) part = curl_mime_addpart(mime); - curl_mime_name(part, pname); - curl_mime_filename(part, fname); - curl_mime_filedata(part, hp->value); + if ((curl_code = curl_mime_name(part, pname))) { + free(pname); + goto error; + } + + if ((curl_code = curl_mime_filename(part, fname))) { + free(pname); + goto error; + } + + if ((curl_code = curl_mime_filedata(part, hp->value))) { + free(pname); + goto error; + } + added++; #else curl_formadd(&formpost, @@ -117,8 +130,14 @@ SWITCH_DECLARE(switch_status_t) switch_curl_process_mime(switch_event_t *event, } else { #if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800) part = curl_mime_addpart(mime); - curl_mime_name(part, hp->name); - curl_mime_data(part, hp->value, CURL_ZERO_TERMINATED); + if ((curl_code = curl_mime_name(part, hp->name))) { + goto error; + } + + if ((curl_code = curl_mime_data(part, hp->value, CURL_ZERO_TERMINATED))) { + goto error; + } + added++; #else curl_formadd(&formpost, @@ -131,6 +150,11 @@ SWITCH_DECLARE(switch_status_t) switch_curl_process_mime(switch_event_t *event, } #if defined(LIBCURL_VERSION_NUM) && (LIBCURL_VERSION_NUM >= 0x073800) + error: + if (curl_code) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CURL error occured. Error code: %d Error msg: [%s]\n", curl_code, switch_curl_easy_strerror(curl_code)); + } + if (!added) { curl_mime_free(mime); mime = NULL; diff --git a/src/switch_event.c b/src/switch_event.c index 02a6f81505..8a8c8d6c35 100644 --- a/src/switch_event.c +++ b/src/switch_event.c @@ -553,6 +553,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_shutdown(void) switch_hash_index_t *hi; const void *var; void *val; + switch_status_t res; if (switch_core_test_flag(SCF_MINIMAL)) { return SWITCH_STATUS_SUCCESS; @@ -565,7 +566,8 @@ SWITCH_DECLARE(switch_status_t) switch_event_shutdown(void) unsub_all_switch_event_channel(); if (EVENT_CHANNEL_DISPATCH_QUEUE) { - switch_queue_trypush(EVENT_CHANNEL_DISPATCH_QUEUE, NULL); + res = switch_queue_trypush(EVENT_CHANNEL_DISPATCH_QUEUE, NULL); + (void)res; switch_queue_interrupt_all(EVENT_CHANNEL_DISPATCH_QUEUE); } @@ -573,10 +575,10 @@ SWITCH_DECLARE(switch_status_t) switch_event_shutdown(void) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Stopping dispatch queues\n"); for(x = 0; x < (uint32_t)DISPATCH_THREAD_COUNT; x++) { - switch_queue_trypush(EVENT_DISPATCH_QUEUE, NULL); + res = switch_queue_trypush(EVENT_DISPATCH_QUEUE, NULL); + (void)res; } - switch_queue_interrupt_all(EVENT_DISPATCH_QUEUE); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Stopping dispatch threads\n"); @@ -595,6 +597,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_shutdown(void) if (THREAD_COUNT == last) { x++; } + last = THREAD_COUNT; } diff --git a/src/switch_ivr.c b/src/switch_ivr.c index 77d957fb7c..7bfe0186f6 100644 --- a/src/switch_ivr.c +++ b/src/switch_ivr.c @@ -1788,6 +1788,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_media(const char *uuid, switch_media_ if (switch_channel_test_flag(channel, CF_MEDIA_TRANS)) { switch_core_session_rwunlock(session); + return SWITCH_STATUS_INUSE; } @@ -1798,6 +1799,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_media(const char *uuid, switch_media_ } if (switch_channel_test_flag(channel, CF_PROXY_MODE)) { + switch_status_t res = SWITCH_STATUS_SUCCESS; + status = SWITCH_STATUS_SUCCESS; /* If we had early media in bypass mode before, it is no longer relevant */ @@ -1816,6 +1819,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_media(const char *uuid, switch_media_ if (switch_core_session_receive_message(session, &msg) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Can't re-establsh media on %s\n", switch_channel_get_name(channel)); switch_core_session_rwunlock(session); + return SWITCH_STATUS_GENERR; } @@ -1832,7 +1836,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_media(const char *uuid, switch_media_ switch_channel_wait_for_flag(channel, CF_REQ_MEDIA, SWITCH_FALSE, 10000, NULL); switch_channel_wait_for_flag(channel, CF_MEDIA_ACK, SWITCH_TRUE, 10000, NULL); switch_channel_wait_for_flag(channel, CF_MEDIA_SET, SWITCH_TRUE, 10000, NULL); - switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0); + res = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0); } if ((flags & SMF_REBRIDGE) @@ -1844,10 +1848,13 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_media(const char *uuid, switch_media_ switch_channel_wait_for_flag(other_channel, CF_REQ_MEDIA, SWITCH_FALSE, 10000, NULL); switch_channel_wait_for_flag(other_channel, CF_MEDIA_ACK, SWITCH_TRUE, 10000, NULL); switch_channel_wait_for_flag(other_channel, CF_MEDIA_SET, SWITCH_TRUE, 10000, NULL); - switch_core_session_read_frame(other_session, &read_frame, SWITCH_IO_FLAG_NONE, 0); + res = switch_core_session_read_frame(other_session, &read_frame, SWITCH_IO_FLAG_NONE, 0); switch_channel_clear_state_handler(other_channel, NULL); switch_core_session_rwunlock(other_session); } + + (void)res; + if (other_channel) { switch_channel_clear_state_handler(channel, NULL); } @@ -1862,6 +1869,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_media(const char *uuid, switch_media_ } else { switch_ivr_uuid_bridge(uuid, other_uuid); } + switch_channel_wait_for_flag(channel, CF_BRIDGED, SWITCH_TRUE, 1000, NULL); switch_channel_wait_for_flag(other_channel, CF_BRIDGED, SWITCH_TRUE, 1000, NULL); } diff --git a/src/switch_ivr_async.c b/src/switch_ivr_async.c index 9a33b43340..4075f0adce 100644 --- a/src/switch_ivr_async.c +++ b/src/switch_ivr_async.c @@ -474,7 +474,7 @@ static dm_match_t switch_ivr_dmachine_check_match(switch_ivr_dmachine_t *dmachin if (is_timeout) { if (both_bp) { - r_bp = exact_bp ? exact_bp : both_bp; + r_bp = exact_bp; } } diff --git a/src/switch_ivr_originate.c b/src/switch_ivr_originate.c index a39553e2f9..0b06d6029c 100644 --- a/src/switch_ivr_originate.c +++ b/src/switch_ivr_originate.c @@ -4961,9 +4961,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_enterprise_orig_and_bridge(switch_cor switch_ivr_multi_threaded_bridge(session, peer_session, func, a_key, b_key); } - if (peer_session) { - switch_core_session_rwunlock(peer_session); - } + switch_core_session_rwunlock(peer_session); } return status; @@ -5026,9 +5024,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_orig_and_bridge(switch_core_session_t switch_ivr_multi_threaded_bridge(session, peer_session, func, a_key, b_key); } - if (peer_session) { - switch_core_session_rwunlock(peer_session); - } + switch_core_session_rwunlock(peer_session); } return status; diff --git a/src/switch_ivr_play_say.c b/src/switch_ivr_play_say.c index 33f3a4e51a..b39d42f657 100644 --- a/src/switch_ivr_play_say.c +++ b/src/switch_ivr_play_say.c @@ -3202,6 +3202,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_soft_hold(switch_core_session_t *sess const char *other_uuid, *moh = NULL; int moh_br = 0; switch_input_args_t args = { 0 }; + switch_status_t res; + args.input_callback = hold_on_dtmf; args.buf = (void *) unhold_key; args.buflen = (uint32_t) strlen(unhold_key); @@ -3232,11 +3234,13 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_soft_hold(switch_core_session_t *sess } if (!zstr(moh) && strcasecmp(moh, "silence")) { - switch_ivr_play_file(session, NULL, moh, &args); + res = switch_ivr_play_file(session, NULL, moh, &args); } else { - switch_ivr_collect_digits_callback(session, &args, 0, 0); + res = switch_ivr_collect_digits_callback(session, &args, 0, 0); } + (void)res; + if (moh_br) { switch_channel_stop_broadcast(other_channel); } @@ -3246,10 +3250,10 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_soft_hold(switch_core_session_t *sess return SWITCH_STATUS_SUCCESS; } - } switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Channel %s is not in a bridge\n", switch_channel_get_name(channel)); + return SWITCH_STATUS_FALSE; } diff --git a/src/switch_stun.c b/src/switch_stun.c index b0ff45b3dc..d4a2c96503 100644 --- a/src/switch_stun.c +++ b/src/switch_stun.c @@ -696,8 +696,11 @@ SWITCH_DECLARE(char *) switch_stun_host_lookup(const char *host, switch_memory_p { switch_sockaddr_t *addr = NULL; char buf[30]; + switch_status_t res; + + res = switch_sockaddr_info_get(&addr, host, SWITCH_UNSPEC, 0, 0, pool); + (void)res; - switch_sockaddr_info_get(&addr, host, SWITCH_UNSPEC, 0, 0, pool); return switch_core_strdup(pool, switch_str_nil(switch_get_addr(buf, sizeof(buf), addr))); } @@ -720,6 +723,7 @@ SWITCH_DECLARE(switch_status_t) switch_stun_lookup(char **ip, int funny = 0; int size = sizeof(buf); int xlen = sizeof(switch_stun_packet_header_t); + switch_status_t res; switch_assert(err); @@ -729,25 +733,30 @@ SWITCH_DECLARE(switch_status_t) switch_stun_lookup(char **ip, *err = "Success"; - switch_sockaddr_info_get(&from_addr, NULL, SWITCH_UNSPEC, 0, 0, pool); + res = switch_sockaddr_info_get(&from_addr, NULL, SWITCH_UNSPEC, 0, 0, pool); + (void)res; if (switch_sockaddr_info_get(&local_addr, *ip, SWITCH_UNSPEC, *port, 0, pool) != SWITCH_STATUS_SUCCESS) { *err = "Local Address Error!"; + return SWITCH_STATUS_FALSE; } if (switch_sockaddr_info_get(&remote_addr, stunip, SWITCH_UNSPEC, stunport, 0, pool) != SWITCH_STATUS_SUCCESS) { *err = "Remote Address Error!"; + return SWITCH_STATUS_FALSE; } if (switch_socket_create(&sock, AF_INET, SOCK_DGRAM, 0, pool) != SWITCH_STATUS_SUCCESS) { *err = "Socket Error!"; + return SWITCH_STATUS_FALSE; } if (switch_socket_bind(sock, local_addr) != SWITCH_STATUS_SUCCESS) { *err = "Bind Error!"; + return SWITCH_STATUS_FALSE; } @@ -779,7 +788,6 @@ SWITCH_DECLARE(switch_status_t) switch_stun_lookup(char **ip, *ip = NULL; *port = 0; - for (;;) { bytes = sizeof(buf); if (switch_socket_recvfrom(from_addr, sock, 0, (char *) &buf, &bytes) == SWITCH_STATUS_SUCCESS && bytes > 0) { @@ -790,10 +798,12 @@ SWITCH_DECLARE(switch_status_t) switch_stun_lookup(char **ip, *err = "Timeout"; switch_socket_shutdown(sock, SWITCH_SHUTDOWN_READWRITE); switch_socket_close(sock); + return SWITCH_STATUS_TIMEOUT; } switch_cond_next(); } + switch_socket_close(sock); if (funny) { @@ -803,14 +813,15 @@ SWITCH_DECLARE(switch_status_t) switch_stun_lookup(char **ip, packet = switch_stun_packet_parse(start, size); if (!packet) { *err = "Invalid STUN/ICE packet"; + return SWITCH_STATUS_FALSE; } + end_buf = buf + ((sizeof(buf) > packet->header.length) ? packet->header.length : sizeof(buf)); switch_stun_packet_first_attribute(packet, attr); switch_assert(attr); - do { switch (attr->type) { case SWITCH_STUN_ATTR_MAPPED_ADDRESS: @@ -818,6 +829,7 @@ SWITCH_DECLARE(switch_status_t) switch_stun_lookup(char **ip, switch_stun_ip_t *tmp = (switch_stun_ip_t *) attr->value; tmp->address ^= ntohl(0xabcdabcd); } + switch_stun_packet_attribute_get_mapped_address(attr, rip, sizeof(rip), &rport); break; case SWITCH_STUN_ATTR_XOR_MAPPED_ADDRESS: @@ -831,12 +843,15 @@ SWITCH_DECLARE(switch_status_t) switch_stun_lookup(char **ip, if (!switch_stun_packet_next_attribute(attr, end_buf)) { break; } + xlen += 4 + switch_stun_attribute_padded_length(attr); + } while (xlen <= packet->header.length); if (packet->header.type == SWITCH_STUN_BINDING_RESPONSE) { *ip = switch_core_strdup(pool, rip); *port = rport; + return SWITCH_STATUS_SUCCESS; } else { *err = "Invalid Reply"; diff --git a/src/switch_vpx.c b/src/switch_vpx.c index 751f2b8c5b..e65db6b6c8 100644 --- a/src/switch_vpx.c +++ b/src/switch_vpx.c @@ -1238,7 +1238,7 @@ static switch_status_t switch_vpx_decode(switch_codec_t *codec, switch_frame_t * if (context->last_received_seq && context->last_received_seq + 1 != frame->seq) { switch_log_printf(SWITCH_CHANNEL_LOG, VPX_SWITCH_LOG_LEVEL, "Packet loss detected last=%d got=%d lost=%d\n", context->last_received_seq, frame->seq, frame->seq - context->last_received_seq); - if (is_keyframe && context->vpx_packet_buffer) switch_buffer_zero(context->vpx_packet_buffer); + if (is_keyframe) switch_buffer_zero(context->vpx_packet_buffer); } context->last_received_seq = frame->seq; diff --git a/src/switch_xml.c b/src/switch_xml.c index 8ed7c27658..d54294df92 100644 --- a/src/switch_xml.c +++ b/src/switch_xml.c @@ -1726,6 +1726,7 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_file(const char *file) if ( rename(new_file_tmp,new_file) ) { goto done; } + if ((fd = open(new_file, O_RDONLY, 0)) > -1) { if ((xml = switch_xml_parse_fd(fd))) { if (strcmp(abs, SWITCH_GLOBAL_filenames.conf_name)) { @@ -1733,8 +1734,8 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_file(const char *file) new_file = NULL; } } + close(fd); - fd = -1; } } @@ -1747,10 +1748,6 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_file(const char *file) write_fd = NULL; } - if (fd > -1) { - close(fd); - } - switch_safe_free(new_file_tmp); switch_safe_free(new_file); @@ -2272,7 +2269,7 @@ SWITCH_DECLARE(switch_status_t) switch_xml_locate_user(const char *key, switch_event_destroy(&my_params); } - if (status != SWITCH_STATUS_SUCCESS && root && *root) { + if (status != SWITCH_STATUS_SUCCESS && *root) { switch_xml_free(*root); *root = NULL; *domain = NULL;