From eec1fd737c6829a29c18db22e10ddbcf32e81b88 Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Thu, 13 Apr 2023 14:23:17 +0100 Subject: [PATCH 01/15] [mod_signalwire] Make this module working with libks and signalwire-c in versions 2.0 * [mod_signalwire] Fix load credentials data from json * [mod_signalwire] Fix parsing of configuration response --- .../applications/mod_signalwire/mod_signalwire.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/mod/applications/mod_signalwire/mod_signalwire.c b/src/mod/applications/mod_signalwire/mod_signalwire.c index 5b0be47a91..9846e7e1d2 100644 --- a/src/mod/applications/mod_signalwire/mod_signalwire.c +++ b/src/mod/applications/mod_signalwire/mod_signalwire.c @@ -228,7 +228,7 @@ static ks_status_t load_credentials_from_json(ks_json_t *json) const char *relay_connector_id = NULL; #if SIGNALWIRE_CLIENT_C_VERSION_MAJOR >= 2 - if ((bootstrap = ks_json_get_string(json, "bootstrap")) == NULL) { + if ((bootstrap = ks_json_get_object_string(json, "bootstrap", NULL)) == NULL) { #else if ((bootstrap = ks_json_get_object_cstr(json, "bootstrap")) == NULL) { #endif @@ -238,7 +238,7 @@ static ks_status_t load_credentials_from_json(ks_json_t *json) } #if SIGNALWIRE_CLIENT_C_VERSION_MAJOR >= 2 - if ((relay_connector_id = ks_json_get_string(json, "relay_connector_id")) == NULL) { + if ((relay_connector_id = ks_json_get_object_string(json, "relay_connector_id", NULL)) == NULL) { #else if ((relay_connector_id = ks_json_get_object_cstr(json, "relay_connector_id")) == NULL) { #endif @@ -797,6 +797,7 @@ static ks_status_t load_credentials(void) status = KS_STATUS_FAIL; goto done; } + fclose(fp); json = ks_json_parse(data); @@ -805,6 +806,7 @@ static ks_status_t load_credentials(void) status = KS_STATUS_FAIL; goto done; } + status = load_credentials_from_json(json); ks_json_delete(&json); @@ -981,7 +983,6 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_signalwire_load) #ifdef WIN32 sslLoadWindowsCACertificate(); #endif - // Configuration swclt_config_create(&globals.config); load_config(); @@ -1206,6 +1207,7 @@ static void mod_signalwire_state_configure(void) #if SIGNALWIRE_CLIENT_C_VERSION_MAJOR >= 2 if (!swclt_sess_provisioning_configure(globals.signalwire_session, "freeswitch", local_endpoint, external_endpoint, globals.relay_connector_id, &reply)) { if (reply->type == SWCLT_CMD_TYPE_RESULT) { + ks_json_t *result; #else if (!swclt_sess_provisioning_configure(globals.signalwire_session, "freeswitch", local_endpoint, external_endpoint, globals.relay_connector_id, &cmd)) { SWCLT_CMD_TYPE cmd_type; @@ -1215,7 +1217,8 @@ static void mod_signalwire_state_configure(void) #endif signalwire_provisioning_configure_response_t *configure_res; #if SIGNALWIRE_CLIENT_C_VERSION_MAJOR >= 2 - if (!SIGNALWIRE_PROVISIONING_CONFIGURE_RESPONSE_PARSE(reply->pool, reply->json, &configure_res)) { + result = ks_json_get_object_item(reply->json, "result"); + if (!SIGNALWIRE_PROVISIONING_CONFIGURE_RESPONSE_PARSE(reply->pool, result, &configure_res)) { #else swclt_cmd_result(cmd, &result); result = ks_json_get_object_item(result, "result"); @@ -1223,7 +1226,7 @@ static void mod_signalwire_state_configure(void) #endif ks_json_t *configuration = configure_res->configuration; #if SIGNALWIRE_CLIENT_C_VERSION_MAJOR >= 2 - const char *configuration_profile = ks_json_get_string(configuration, "profile"); + const char *configuration_profile = ks_json_get_object_string(configuration, "profile", NULL); #else const char *configuration_profile = ks_json_get_object_cstr(configuration, "profile"); #endif @@ -1231,6 +1234,7 @@ static void mod_signalwire_state_configure(void) switch_xml_free(globals.signalwire_profile); globals.signalwire_profile = NULL; } + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "\"%s\"\n", configuration_profile); globals.signalwire_profile = switch_xml_parse_str_dynamic((char *)configuration_profile, SWITCH_TRUE); if (!globals.signalwire_profile) { From 7f3a833466a470687dbd9e407c049f7e74704e99 Mon Sep 17 00:00:00 2001 From: Andrey Volk Date: Fri, 14 Apr 2023 14:48:41 +0300 Subject: [PATCH 02/15] [mod_commands] Fix leaking session readlock in uuid_capture_text --- src/mod/applications/mod_commands/mod_commands.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index 4394d9b02f..5b9620a781 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -3225,6 +3225,7 @@ SWITCH_STANDARD_API(uuid_capture_text) } else { if ((tsession = switch_core_session_locate(uuid))) { switch_ivr_capture_text(tsession, switch_true(onoff)); + switch_core_session_rwunlock(tsession); } else { stream->write_function(stream, "-ERR No such channel %s!\n", uuid); } From 70c144309c16eed5b875214ff28e42d412a2a91b Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Thu, 13 Apr 2023 19:46:51 +0100 Subject: [PATCH 03/15] [mod_v8] Coverity CID 1468570 (Resource leak) --- src/mod/languages/mod_v8/src/fsglobal.cpp | 26 ++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/mod/languages/mod_v8/src/fsglobal.cpp b/src/mod/languages/mod_v8/src/fsglobal.cpp index 99a0626f8f..c360955687 100644 --- a/src/mod/languages/mod_v8/src/fsglobal.cpp +++ b/src/mod/languages/mod_v8/src/fsglobal.cpp @@ -169,6 +169,7 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(FetchURLHash) } else { /* The var exists, but is wrong type - exit with error */ info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Second argument is the name of an existing var of the wrong type")); + return; } } else if (info.Length() > 1 && info[1]->IsArray()) { @@ -177,6 +178,7 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(FetchURLHash) } else if (info.Length() > 1) { /* The var exists, but is wrong type - exit with error */ info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Second argument is of the wrong type")); + return; } else { /* Second argument doesn't exist, this is also ok. The hash will be returned as the result */ @@ -185,6 +187,11 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(FetchURLHash) } curl_handle = switch_curl_easy_init(); + if (!curl_handle) { + info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Failed to initiate curl easy session.")); + + return; + } if (!strncasecmp(js_safe_str(*url), "https", 5)) { switch_curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0); @@ -224,14 +231,22 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(FetchURLFile) const char *url = NULL, *filename = NULL; String::Utf8Value str1(info[0]); String::Utf8Value str2(info[1]); + url = js_safe_str(*str1); filename = js_safe_str(*str2); curl_handle = switch_curl_easy_init(); + if (!curl_handle) { + info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Failed to initiate curl easy session.")); + + return; + } + if (!strncasecmp(url, "https", 5)) { switch_curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0); switch_curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0); } + config_data.isolate = info.GetIsolate(); if ((config_data.fileHandle = open(filename, O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR)) > -1) { @@ -245,13 +260,14 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(FetchURLFile) switch_curl_easy_perform(curl_handle); - switch_curl_easy_cleanup(curl_handle); close(config_data.fileHandle); info.GetReturnValue().Set(true); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to open file [%s]\n", filename); info.GetReturnValue().Set(false); } + + switch_curl_easy_cleanup(curl_handle); } else { info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Invalid arguments")); } @@ -270,12 +286,19 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(FetchURL) if (info.Length() >= 1) { const char *url; String::Utf8Value str(info[0]); + url = js_safe_str(*str); if (info.Length() > 1) { buffer_size = info[1]->Int32Value(); } curl_handle = switch_curl_easy_init(); + if (!curl_handle) { + info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Failed to initiate curl easy session.")); + + return; + } + if (!strncasecmp(url, "https", 5)) { switch_curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0); switch_curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0); @@ -289,6 +312,7 @@ JS_GLOBAL_FUNCTION_IMPL_STATIC(FetchURL) if (config_data.buffer == NULL) { info.GetIsolate()->ThrowException(String::NewFromUtf8(info.GetIsolate(), "Failed to allocate data buffer.")); switch_curl_easy_cleanup(curl_handle); + return; } From 85a109617f769d401d9b35df6beb2cfc0f69d3b6 Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Thu, 13 Apr 2023 13:58:08 +0100 Subject: [PATCH 04/15] [mod_java] Coverity CID 1320752 (Resource leak) --- src/mod/languages/mod_java/modjava.c | 179 ++++++++++++++------------- 1 file changed, 90 insertions(+), 89 deletions(-) diff --git a/src/mod/languages/mod_java/modjava.c b/src/mod/languages/mod_java/modjava.c index 899fee2b60..9c38bdb70f 100644 --- a/src/mod/languages/mod_java/modjava.c +++ b/src/mod/languages/mod_java/modjava.c @@ -189,107 +189,108 @@ SWITCH_STANDARD_APP(java_function) static switch_status_t load_config(JavaVMOption **javaOptions, int *optionCount, vm_control_t * vmControl) { - switch_xml_t cfg, xml; - switch_status_t status = SWITCH_STATUS_SUCCESS; + switch_xml_t cfg, xml; + switch_status_t status = SWITCH_STATUS_SUCCESS; char *derr = NULL; - xml = switch_xml_open_cfg("java.conf", &cfg, NULL); - if (xml) - { - switch_xml_t javavm; - switch_xml_t options; - switch_xml_t startup; - switch_xml_t shutdown; + xml = switch_xml_open_cfg("java.conf", &cfg, NULL); + if (xml) { + switch_xml_t javavm; + switch_xml_t options; + switch_xml_t startup; + switch_xml_t shutdown; - javavm = switch_xml_child(cfg, "javavm"); - if (javavm != NULL) - { - const char *path = switch_xml_attr_soft(javavm, "path"); - if (path != NULL) - { + javavm = switch_xml_child(cfg, "javavm"); + if (javavm != NULL) { + const char *path = switch_xml_attr_soft(javavm, "path"); + + if (path != NULL) { javaVMHandle = switch_dso_open(path, 0, &derr); if (derr || !javaVMHandle) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error loading %s\n", path); + switch_safe_free(derr); } - } - else - { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Java VM path specified in java.conf.xml\n"); - status = SWITCH_STATUS_FALSE; - } - } - else - { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Java VM specified in java.conf.xml\n"); - status = SWITCH_STATUS_FALSE; - goto close; - } + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Java VM path specified in java.conf.xml\n"); + status = SWITCH_STATUS_FALSE; + } + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Java VM specified in java.conf.xml\n"); + status = SWITCH_STATUS_FALSE; + goto close; + } + + options = switch_xml_child(cfg, "options"); + if (options != NULL) { + switch_xml_t option; + int i = 0; + + *optionCount = 0; + + for (option = switch_xml_child(options, "option"); option; option = option->next) { + const char *value = switch_xml_attr_soft(option, "value"); + + if (value != NULL) { + ++*optionCount; + } + } + + *optionCount += 1; + *javaOptions = switch_core_alloc(memoryPool, (switch_size_t)(*optionCount * sizeof(JavaVMOption))); + if (*javaOptions == NULL) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Out of memory!\n"); + status = SWITCH_STATUS_FALSE; + goto close; + } + + for (option = switch_xml_child(options, "option"); option; option = option->next) { + const char *value = switch_xml_attr_soft(option, "value"); + + if (value == NULL) { + continue; + } + + (*javaOptions)[i].optionString = switch_core_strdup(memoryPool, value); + if ((*javaOptions)[i].optionString == NULL) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Out of memory!\n"); + status = SWITCH_STATUS_FALSE; + goto close; + } + + ++i; + } - options = switch_xml_child(cfg, "options"); - if (options != NULL) - { - switch_xml_t option; - int i = 0; - *optionCount = 0; - for (option = switch_xml_child(options, "option"); option; option = option->next) - { - const char *value = switch_xml_attr_soft(option, "value"); - if (value != NULL) - ++*optionCount; - } - *optionCount += 1; - *javaOptions = switch_core_alloc(memoryPool, (switch_size_t)(*optionCount * sizeof(JavaVMOption))); - if (*javaOptions == NULL) - { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Out of memory!\n"); - status = SWITCH_STATUS_FALSE; - goto close; - } - for (option = switch_xml_child(options, "option"); option; option = option->next) - { - const char *value = switch_xml_attr_soft(option, "value"); - if (value == NULL) - continue; - (*javaOptions)[i].optionString = switch_core_strdup(memoryPool, value); - if ((*javaOptions)[i].optionString == NULL) - { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Out of memory!\n"); - status = SWITCH_STATUS_FALSE; - goto close; - } - ++i; - } (*javaOptions)[i].optionString = switch_core_sprintf(memoryPool, "-Djava.library.path=%s", SWITCH_GLOBAL_dirs.mod_dir); - } + } - /* - - - */ + /* + + + */ - memset(vmControl, 0, sizeof(struct vm_control)); - startup = switch_xml_child(cfg, "startup"); - if (startup != NULL) { - vmControl->startup.class = switch_xml_attr_soft(startup, "class"); - vmControl->startup.method = switch_xml_attr_soft(startup, "method"); - vmControl->startup.arg = switch_xml_attr_soft(startup, "arg"); - } - shutdown = switch_xml_child(cfg, "shutdown"); - if (shutdown != NULL) { - vmControl->shutdown.class = switch_xml_attr_soft(shutdown, "class"); - vmControl->shutdown.method = switch_xml_attr_soft(shutdown, "method"); - vmControl->shutdown.arg = switch_xml_attr_soft(shutdown, "arg"); - } + memset(vmControl, 0, sizeof(struct vm_control)); + startup = switch_xml_child(cfg, "startup"); + if (startup != NULL) { + vmControl->startup.class = switch_xml_attr_soft(startup, "class"); + vmControl->startup.method = switch_xml_attr_soft(startup, "method"); + vmControl->startup.arg = switch_xml_attr_soft(startup, "arg"); + } - close: - switch_xml_free(xml); - } - else - { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening java.conf.xml\n"); - status = SWITCH_STATUS_FALSE; - } - return status; + shutdown = switch_xml_child(cfg, "shutdown"); + if (shutdown != NULL) { + vmControl->shutdown.class = switch_xml_attr_soft(shutdown, "class"); + vmControl->shutdown.method = switch_xml_attr_soft(shutdown, "method"); + vmControl->shutdown.arg = switch_xml_attr_soft(shutdown, "arg"); + } + + close: + switch_xml_free(xml); + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening java.conf.xml\n"); + status = SWITCH_STATUS_FALSE; + } + + return status; } static switch_status_t create_java_vm(JavaVMOption *options, int optionCount, vm_control_t * vmControl) From 0b05623cef5c3425831a7bbf28580b30a04eda3e Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Thu, 13 Apr 2023 14:54:50 +0100 Subject: [PATCH 05/15] [mod_translate] Coverity CID 1301006 (Resource leak) --- src/mod/applications/mod_translate/mod_translate.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/mod/applications/mod_translate/mod_translate.c b/src/mod/applications/mod_translate/mod_translate.c index efbcd3f14b..34b1ad54fc 100644 --- a/src/mod/applications/mod_translate/mod_translate.c +++ b/src/mod/applications/mod_translate/mod_translate.c @@ -130,6 +130,7 @@ static void translate_number(char *number, char *profile, char **translated, swi hi = switch_core_hash_find_rdlock(globals.translate_profiles, (const char *)profile, globals.profile_hash_rwlock); if (!hi) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "can't find key for profile matching [%s]\n", profile); + return; } @@ -142,6 +143,7 @@ static void translate_number(char *number, char *profile, char **translated, swi switch_regex_safe_free(re); goto end; } + memset(substituted, 0, len); switch_perform_substitution(re, proceed, rule->replace, number, substituted, len, ovector); @@ -153,16 +155,21 @@ static void translate_number(char *number, char *profile, char **translated, swi } else if (event) { subbed = switch_event_expand_headers(event, substituted); } + + if (subbed != substituted) { + switch_safe_free(substituted); + } + if (session) { substituted = switch_core_session_strdup(session, subbed); } else { substituted = switch_core_strdup(pool, subbed); } - if (subbed != substituted) { - switch_safe_free(subbed); - } + + switch_safe_free(subbed); } + switch_regex_safe_free(re); break; } } From bc00add2542b22afd9c86068ad1cdd6684603564 Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Mon, 17 Apr 2023 11:53:26 +0100 Subject: [PATCH 06/15] [mod_kazoo] Coverity fixes (#2043) * [mod_kazoo] Coverity CID 1395503 (Resource leak) * [mod_kazoo] Coverity CID 1468146 (Resource leak) * [mod_kazoo] Coverity CID 1468483 (Resource leak) --- .../mod_kazoo/kazoo_ei_config.c | 19 ++++++++++++----- .../event_handlers/mod_kazoo/kazoo_message.c | 21 +++++++++++++++---- src/mod/event_handlers/mod_kazoo/kazoo_node.c | 10 +++++++++ 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/src/mod/event_handlers/mod_kazoo/kazoo_ei_config.c b/src/mod/event_handlers/mod_kazoo/kazoo_ei_config.c index f1726b677b..3c626c15da 100644 --- a/src/mod/event_handlers/mod_kazoo/kazoo_ei_config.c +++ b/src/mod/event_handlers/mod_kazoo/kazoo_ei_config.c @@ -564,13 +564,16 @@ switch_status_t kazoo_config_fetch_handler(kazoo_config_ptr definitions, kazoo_c switch_memory_pool_t *pool = NULL; char *name = (char *) switch_xml_attr_soft(cfg, "name"); + if (zstr(name)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "missing name in profile\n"); + return SWITCH_STATUS_GENERR; } if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error allocation pool for new profile : %s\n", name); + return SWITCH_STATUS_GENERR; } @@ -582,6 +585,7 @@ switch_status_t kazoo_config_fetch_handler(kazoo_config_ptr definitions, kazoo_c fetch_section = switch_xml_parse_section_string(name); if ((params = switch_xml_child(cfg, "params")) != NULL) { + for (param = switch_xml_child(params, "param"); param; param = param->next) { char *var = (char *) switch_xml_attr_soft(param, "name"); char *val = (char *) switch_xml_attr_soft(param, "value"); @@ -605,7 +609,9 @@ switch_status_t kazoo_config_fetch_handler(kazoo_config_ptr definitions, kazoo_c } if (fetch_section == SWITCH_XML_SECTION_RESULT) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Fetch Profile[%s] invalid fetch-section: %s\n", name, switch_xml_toxml(cfg, SWITCH_FALSE)); + char *tmp = switch_xml_toxml(cfg, SWITCH_FALSE); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Fetch Profile[%s] invalid fetch-section: %s\n", name, tmp); + free(tmp); goto err; } @@ -622,17 +628,20 @@ switch_status_t kazoo_config_fetch_handler(kazoo_config_ptr definitions, kazoo_c } } - if(ptr) + if (ptr) { *ptr = profile; + } switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "fetch handler profile %s successfully configured\n", name); + return SWITCH_STATUS_SUCCESS; err: /* Cleanup */ - if(pool) { - switch_core_destroy_memory_pool(&pool); - } + if(pool) { + switch_core_destroy_memory_pool(&pool); + } + return SWITCH_STATUS_GENERR; } diff --git a/src/mod/event_handlers/mod_kazoo/kazoo_message.c b/src/mod/event_handlers/mod_kazoo/kazoo_message.c index e43d656b4c..43716a8e02 100644 --- a/src/mod/event_handlers/mod_kazoo/kazoo_message.c +++ b/src/mod/event_handlers/mod_kazoo/kazoo_message.c @@ -233,9 +233,11 @@ cJSON * kazoo_event_add_field_to_json(cJSON *dst, switch_event_t *src, kazoo_fie } else if((header = switch_event_get_header_ptr(src, field->name)) != NULL) { if (header->idx) { item = cJSON_CreateArray(); + for(i = 0; i < header->idx; i++) { cJSON_AddItemToArray(item, kazoo_event_json_value(field->out_type, header->array[i])); } + kazoo_cJSON_AddItemToObject(dst, field->as ? field->as : field->name, item); } else if (field->out_type_as_array) { item = cJSON_CreateArray(); @@ -251,13 +253,16 @@ cJSON * kazoo_event_add_field_to_json(cJSON *dst, switch_event_t *src, kazoo_fie expanded = kz_event_expand_headers(src, field->value); if(expanded != NULL && !zstr(expanded)) { item = kazoo_event_add_json_value(dst, field, field->as ? field->as : field->name, expanded); - if(expanded != field->value) { - free(expanded); - } } + + if (expanded != field->value) { + switch_safe_free(expanded); + } + break; case FIELD_FIRST_OF: + for(n = 0; n < field->list.size; n++) { if(*field->list.value[n] == '#') { item = kazoo_event_add_json_value(dst, field, field->as ? field->as : field->name, ++field->list.value[n]); @@ -267,33 +272,41 @@ cJSON * kazoo_event_add_field_to_json(cJSON *dst, switch_event_t *src, kazoo_fie if(header) { if (header->idx) { item = cJSON_CreateArray(); + for(i = 0; i < header->idx; i++) { cJSON_AddItemToArray(item, kazoo_event_json_value(field->out_type, header->array[i])); } + kazoo_cJSON_AddItemToObject(dst, field->as ? field->as : field->name, item); } else { item = kazoo_event_add_json_value(dst, field, field->as ? field->as : field->name, header->value); } + break; } } } + break; case FIELD_PREFIX: + for (header = src->headers; header; header = header->next) { if(!strncmp(header->name, field->name, strlen(field->name))) { if (header->idx) { cJSON *array = cJSON_CreateArray(); + for(i = 0; i < header->idx; i++) { cJSON_AddItemToArray(array, kazoo_event_json_value(field->out_type, header->array[i])); } + kazoo_cJSON_AddItemToObject(dst, field->exclude_prefix ? header->name+strlen(field->name) : header->name, array); } else { kazoo_event_add_json_value(dst, field, field->exclude_prefix ? header->name+strlen(field->name) : header->name, header->value); } } } + break; case FIELD_STATIC: @@ -308,7 +321,7 @@ cJSON * kazoo_event_add_field_to_json(cJSON *dst, switch_event_t *src, kazoo_fie break; } - return item; + return item; } static switch_status_t kazoo_event_add_fields_to_json(kazoo_logging_ptr logging, cJSON *dst, switch_event_t *src, kazoo_field_ptr field) { diff --git a/src/mod/event_handlers/mod_kazoo/kazoo_node.c b/src/mod/event_handlers/mod_kazoo/kazoo_node.c index feb8970a86..f75c327023 100644 --- a/src/mod/event_handlers/mod_kazoo/kazoo_node.c +++ b/src/mod/event_handlers/mod_kazoo/kazoo_node.c @@ -1097,23 +1097,27 @@ static switch_status_t handle_request_fetch_reply(ei_node_t *ei_node, erlang_pid if (ei_decode_atom_safe(buf->buff, &buf->index, section_str) || !(section = switch_xml_parse_section_string(section_str))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Ignoring a fetch reply without a configuration section\n"); + return erlang_response_badarg(rbuf); } if (ei_decode_string_or_binary_limited(buf->buff, &buf->index, sizeof(uuid_str), uuid_str) || zstr_buf(uuid_str)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Ignoring a fetch reply without request UUID\n"); + return erlang_response_badarg(rbuf); } if (ei_decode_string_or_binary(buf->buff, &buf->index, &xml_str)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Ignoring a fetch reply without XML : %s \n", uuid_str); + return erlang_response_badarg(rbuf); } if (zstr(xml_str)) { switch_safe_free(xml_str); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Ignoring an empty fetch reply : %s\n", uuid_str); + return erlang_response_badarg(rbuf); } @@ -1138,13 +1142,19 @@ static switch_status_t handle_request_fetch_reply(ei_node_t *ei_node, erlang_pid break; default: switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Received fetch reply %s for an unknown configuration section: %s : %s\n", uuid_str, section_str, xml_str); + switch_safe_free(xml_str); + return erlang_response_badarg(rbuf); } if (result == SWITCH_STATUS_SUCCESS) { + switch_safe_free(xml_str); + return erlang_response_ok(rbuf); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Received fetch reply %s is unknown or has expired : %s\n", uuid_str, xml_str); + switch_safe_free(xml_str); + return erlang_response_baduuid(rbuf); } } From 0c2edc4f56a64ddab1a94a91981517df20d83139 Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Fri, 14 Apr 2023 11:28:01 +0100 Subject: [PATCH 07/15] [mod_radius_cdr] Coverity CID 1395529 (Resource leak) --- .../mod_radius_cdr/mod_radius_cdr.c | 33 ++++++++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/mod/event_handlers/mod_radius_cdr/mod_radius_cdr.c b/src/mod/event_handlers/mod_radius_cdr/mod_radius_cdr.c index 490a7911f1..153ec6252d 100644 --- a/src/mod/event_handlers/mod_radius_cdr/mod_radius_cdr.c +++ b/src/mod/event_handlers/mod_radius_cdr/mod_radius_cdr.c @@ -166,8 +166,10 @@ static switch_status_t my_on_routing(switch_core_session_t *session) if (channel) { const char *disable_flag = switch_channel_get_variable(channel, "disable_radius_start"); + if (switch_true(disable_flag)) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "[mod_radius_cdr] Not Sending RADIUS Start\n"); + return SWITCH_STATUS_SUCCESS; } } @@ -250,6 +252,7 @@ static switch_status_t my_on_routing(switch_core_session_t *session) goto end; } } + if (profile->caller_id_number) { if (rc_avpair_add(rad_config, &send, PW_FS_SRC, (void *) profile->caller_id_number, -1, PW_FS_PEC) == NULL) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-Src: %s\n", profile->caller_id_number); @@ -257,6 +260,7 @@ static switch_status_t my_on_routing(switch_core_session_t *session) goto end; } } + if (profile->caller_id_name) { if (rc_avpair_add(rad_config, &send, PW_FS_CLID, (void *) profile->caller_id_name, -1, PW_FS_PEC) == NULL) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-CLID: %s\n", profile->caller_id_name); @@ -264,6 +268,7 @@ static switch_status_t my_on_routing(switch_core_session_t *session) goto end; } } + if (profile->destination_number) { if (rc_avpair_add(rad_config, &send, PW_FS_DST, (void *) profile->destination_number, -1, PW_FS_PEC) == NULL) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-Dst: %s\n", profile->destination_number); @@ -271,6 +276,7 @@ static switch_status_t my_on_routing(switch_core_session_t *session) goto end; } } + if (profile->dialplan) { if (rc_avpair_add(rad_config, &send, PW_FS_DIALPLAN, (void *) profile->dialplan, -1, PW_FS_PEC) == NULL) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-Dialplan: %s\n", profile->dialplan); @@ -278,6 +284,7 @@ static switch_status_t my_on_routing(switch_core_session_t *session) goto end; } } + if (profile->network_addr) { inet_pton(AF_INET, (void *) profile->network_addr, &framed_addr); framed_addr = htonl(framed_addr); @@ -287,6 +294,7 @@ static switch_status_t my_on_routing(switch_core_session_t *session) goto end; } } + if (profile->rdnis) { if (rc_avpair_add(rad_config, &send, PW_FS_RDNIS, (void *) profile->rdnis, -1, PW_FS_PEC) == NULL) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-RDNIS: %s\n", profile->rdnis); @@ -294,6 +302,7 @@ static switch_status_t my_on_routing(switch_core_session_t *session) goto end; } } + if (profile->context) { if (rc_avpair_add(rad_config, &send, PW_FS_CONTEXT, (void *) profile->context, -1, PW_FS_PEC) == NULL) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-Context: %s\n", profile->context); @@ -301,6 +310,7 @@ static switch_status_t my_on_routing(switch_core_session_t *session) goto end; } } + if (profile->ani) { if (rc_avpair_add(rad_config, &send, PW_FS_ANI, (void *) profile->ani, -1, PW_FS_PEC) == NULL) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-ANI: %s\n", profile->ani); @@ -308,6 +318,7 @@ static switch_status_t my_on_routing(switch_core_session_t *session) goto end; } } + if (profile->aniii) { if (rc_avpair_add(rad_config, &send, PW_FS_ANIII, (void *) profile->aniii, -1, PW_FS_PEC) == NULL) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-ANIII: %s\n", profile->aniii); @@ -315,6 +326,7 @@ static switch_status_t my_on_routing(switch_core_session_t *session) goto end; } } + if (profile->source) { if (rc_avpair_add(rad_config, &send, PW_FS_SOURCE, (void *) profile->source, -1, PW_FS_PEC) == NULL) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "failed adding Freeswitch-Source: %s\n", profile->source); @@ -322,6 +334,7 @@ static switch_status_t my_on_routing(switch_core_session_t *session) goto end; } } + if (callstartdate > 0) { switch_time_exp_tz(&tm, callstartdate, requested_tm.tm_gmtoff); switch_snprintf(buffer, sizeof(buffer), "%04u-%02u-%02uT%02u:%02u:%02u.%06u%+03d%02d", @@ -380,25 +393,33 @@ static switch_status_t my_on_routing(switch_core_session_t *session) } if (radius_avpair) { + char *radius_avpair_data_tmp = NULL; + radius_avpair_data = strdup(radius_avpair + (strncmp(radius_avpair, "ARRAY::", 7) ? 0 : 7)); + radius_avpair_data_tmp = radius_avpair_data; + do { - delim = strstr(radius_avpair_data, "|:"); + delim = strstr(radius_avpair_data_tmp, "|:"); if (delim) { *delim = '\0'; } - if (rc_avpair_add(rad_config, &send, PW_FS_AVPAIR, (void *) radius_avpair_data, -1, PW_FS_PEC) == NULL) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-AVPair: %s\n", radius_avpair_data); + if (rc_avpair_add(rad_config, &send, PW_FS_AVPAIR, (void *)radius_avpair_data_tmp, -1, PW_FS_PEC) == NULL) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "failed adding Freeswitch-AVPair: %s\n", radius_avpair_data_tmp); rc_destroy(rad_config); + switch_safe_free(radius_avpair_data); goto end; } - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "added Freeswitch-AVPair: %s\n", radius_avpair_data); + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "added Freeswitch-AVPair: %s\n", radius_avpair_data_tmp); if (delim) { - radius_avpair_data = delim + 2; + radius_avpair_data_tmp = delim + 2; } } while (delim); + + switch_safe_free(radius_avpair_data); } } else { @@ -413,11 +434,13 @@ static switch_status_t my_on_routing(switch_core_session_t *session) switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "[mod_radius_cdr] RADIUS Accounting Failed\n"); retval = SWITCH_STATUS_TERM; } + rc_avpair_free(send); rc_destroy(rad_config); end: switch_xml_free(cdr); switch_thread_rwlock_unlock(globals.rwlock); + return (retval); } From 98c0482844a51a99197906983c0b7942b7993130 Mon Sep 17 00:00:00 2001 From: Dragos Oancea Date: Mon, 10 Apr 2023 15:29:47 +0300 Subject: [PATCH 08/15] [mod_opusfile] coverity CID 1468424 (Missing break in switch) --- src/mod/formats/mod_opusfile/mod_opusfile.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mod/formats/mod_opusfile/mod_opusfile.c b/src/mod/formats/mod_opusfile/mod_opusfile.c index 1560142263..a065108f5c 100644 --- a/src/mod/formats/mod_opusfile/mod_opusfile.c +++ b/src/mod/formats/mod_opusfile/mod_opusfile.c @@ -654,6 +654,7 @@ static switch_status_t switch_opusstream_stream_decode(opus_stream_context_t *co } switch_goto_status(SWITCH_STATUS_SUCCESS, end); } + break; case OP_EREAD: /*An underlying read operation failed. This may signal a truncation attack from an source.*/ case OP_EFAULT: /* An internal memory allocation failed. */ From 01e960cd90c32b59b695421388d2522a0178b28e Mon Sep 17 00:00:00 2001 From: Dragos Oancea Date: Mon, 10 Apr 2023 17:48:33 +0300 Subject: [PATCH 09/15] [mod_erlang_event] coverity CID 1500239 (Uninitialized scalar variable) --- src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c b/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c index d15f748eb7..bd7bf8e26c 100644 --- a/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c +++ b/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c @@ -1998,7 +1998,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_erlang_event_runtime) struct ei_cnode_s ec; ErlConnect conn; int clientfd; - switch_os_socket_t epmdfd; + switch_os_socket_t epmdfd = SWITCH_SOCK_INVALID; switch_socket_t *epmd_sock = NULL; if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) { From aab9839678e506ee50c76421acce5f76f5962d97 Mon Sep 17 00:00:00 2001 From: Dragos Oancea Date: Mon, 10 Apr 2023 18:22:45 +0300 Subject: [PATCH 10/15] [mod_sofia] coverity CID 1468496 (Unchecked return value) --- src/mod/endpoints/mod_sofia/sip-dig.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/mod/endpoints/mod_sofia/sip-dig.c b/src/mod/endpoints/mod_sofia/sip-dig.c index e89f5aef44..c9a6f5b463 100644 --- a/src/mod/endpoints/mod_sofia/sip-dig.c +++ b/src/mod/endpoints/mod_sofia/sip-dig.c @@ -815,8 +815,12 @@ sres_record_t ** dig_addr_simple(struct dig *dig, uint16_t type) { sres_record_t **answers = NULL; + int error; - sres_blocking_query(dig->sres, type, host, 0, &answers); + error = sres_blocking_query(dig->sres, type, host, 0, &answers); + if (error < 0) { + return NULL; + } return answers; } From 075724845e1c9795ccb6625912b4f81e87401a1e Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Fri, 14 Apr 2023 10:25:40 +0100 Subject: [PATCH 11/15] [mod_rayo] Coverity CID 1395579 (Resource leak) --- src/mod/event_handlers/mod_rayo/mod_rayo.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/mod/event_handlers/mod_rayo/mod_rayo.c b/src/mod/event_handlers/mod_rayo/mod_rayo.c index 6ed46489a7..228e89b323 100644 --- a/src/mod/event_handlers/mod_rayo/mod_rayo.c +++ b/src/mod/event_handlers/mod_rayo/mod_rayo.c @@ -4765,7 +4765,7 @@ static void send_console_command(struct rayo_client *client, const char *to, con iks *command = NULL; iksparser *p = iks_dom_new(&command); - if (iks_parse(p, command_str, 0, 1) == IKS_OK && command) { + if (p && iks_parse(p, command_str, 0, 1) == IKS_OK && command) { char *str; iks *iq = NULL; @@ -4784,9 +4784,11 @@ static void send_console_command(struct rayo_client *client, const char *to, con if (!iks_find_attrib(iq, "type")) { iks_insert_attrib(iq, "type", "set"); } + if (!iks_find_attrib(iq, "id")) { iks_insert_attrib_printf(iq, "id", "console-%i", RAYO_SEQ_NEXT(client)); } + iks_insert_attrib(iq, "from", RAYO_JID(client)); /* send command */ @@ -4794,10 +4796,13 @@ static void send_console_command(struct rayo_client *client, const char *to, con switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\nSEND: to %s, %s\n", to, str); rayo_client_command_recv(client, iq); iks_delete(command); + iks_parser_delete(p); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "bad request xml\n"); + if (p) { + iks_parser_delete(p); + } } - iks_parser_delete(p); } /** From 6eefc674fe1bf75122dc511ea4a8fb0367167210 Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Mon, 17 Apr 2023 19:49:42 +0100 Subject: [PATCH 12/15] [mod_avmd] Coverity fixes * [mod_avmd] Coverity CID 1395501 (Dereference null return value) * [mod_avmd] Coverity CID 1395478 (Resource leak) --- .../applications/mod_avmd/avmd_fast_acosf.c | 20 +++++++++++-------- src/mod/applications/mod_avmd/mod_avmd.c | 18 +++-------------- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/src/mod/applications/mod_avmd/avmd_fast_acosf.c b/src/mod/applications/mod_avmd/avmd_fast_acosf.c index 572c6a84f9..59b581b98d 100644 --- a/src/mod/applications/mod_avmd/avmd_fast_acosf.c +++ b/src/mod/applications/mod_avmd/avmd_fast_acosf.c @@ -86,7 +86,6 @@ typedef union { static uint32_t index_from_float(float f); static float float_from_index(uint32_t d); static float *acos_table = NULL; -static int acos_fd = -1; #ifdef FAST_ACOSF_TESTING @@ -112,6 +111,10 @@ extern int compute_table(void) acos_table_file = fopen(ACOS_TABLE_FILENAME, "w"); + if (!acos_table_file) { + return -3; + } + for (i = 0; i < ACOS_TABLE_LENGTH; i++) { f = acosf(float_from_index(i)); res = fwrite(&f, sizeof(f), 1, acos_table_file); @@ -124,10 +127,12 @@ extern int compute_table(void) if (res != 0) { return -2; } + return 0; fail: fclose(acos_table_file); + return -1; } @@ -144,8 +149,9 @@ extern int init_fast_acosf(void) * or some other error occured */ errsv = errno; strerror_r(errsv, err, 150); - if (errsv != ENOENT) return -1; - else { + if (errsv != ENOENT) { + return -1; + } else { switch_log_printf( SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, @@ -166,10 +172,10 @@ extern int init_fast_acosf(void) acos_fp = fopen(ACOS_TABLE_FILENAME, "r"); if (acos_fp == NULL) return -3; /* can't fail */ - acos_fd = fileno(acos_fp); acos_table = (float *) mmap( NULL, /* kernel chooses the address at which to create the mapping */ - ACOS_TABLE_LENGTH * sizeof(float), PROT_READ, MAP_SHARED, acos_fd, 0); + ACOS_TABLE_LENGTH * sizeof(float), PROT_READ, MAP_SHARED, fileno(acos_fp), 0); + fclose(acos_fp); if (acos_table == MAP_FAILED) return -4; return 0; @@ -178,9 +184,7 @@ extern int init_fast_acosf(void) extern int destroy_fast_acosf(void) { if (munmap(acos_table, ACOS_TABLE_LENGTH) == -1) return -1; - if (acos_fd != -1) { - if (close(acos_fd) == -1) return -2; - } + /* disable use of fast arc cosine file */ acos_table = NULL; diff --git a/src/mod/applications/mod_avmd/mod_avmd.c b/src/mod/applications/mod_avmd/mod_avmd.c index dde3dfbf93..6c59256eda 100644 --- a/src/mod/applications/mod_avmd/mod_avmd.c +++ b/src/mod/applications/mod_avmd/mod_avmd.c @@ -1622,9 +1622,6 @@ SWITCH_STANDARD_APP(avmd_start_function) { SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_avmd_shutdown) { size_t session_n; -#ifndef WIN32 - int res; -#endif switch_mutex_lock(avmd_globals.mutex); @@ -1638,18 +1635,8 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_avmd_shutdown) { #ifndef WIN32 if (avmd_globals.settings.fast_math == 1) { - res = destroy_fast_acosf(); - if (res != 0) { - switch (res) { - case -1: - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed unmap arc cosine table\n"); - break; - case -2: - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed closing arc cosine table\n"); - break; - default: - break; - } + if (destroy_fast_acosf()) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed unmap arc cosine table\n"); } } #endif @@ -1658,6 +1645,7 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_avmd_shutdown) { switch_mutex_unlock(avmd_globals.mutex); switch_mutex_destroy(avmd_globals.mutex); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Advanced voicemail detection disabled\n"); + return SWITCH_STATUS_SUCCESS; } From e1d966ed0a362c9c001071c69e8afb8599ad50e6 Mon Sep 17 00:00:00 2001 From: Dragos Oancea Date: Mon, 10 Apr 2023 17:05:49 +0300 Subject: [PATCH 13/15] [mod_dptools] coverity CID 1468646 (Unsigned compared against 0) --- src/mod/applications/mod_dptools/mod_dptools.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mod/applications/mod_dptools/mod_dptools.c b/src/mod/applications/mod_dptools/mod_dptools.c index f38509016b..e91ec53d47 100644 --- a/src/mod/applications/mod_dptools/mod_dptools.c +++ b/src/mod/applications/mod_dptools/mod_dptools.c @@ -4584,7 +4584,7 @@ SWITCH_STANDARD_APP(wait_for_silence_function) timeout_ms = switch_atoui(argv[3]); } - if (thresh > 0 && silence_hits > 0 && listen_hits >= 0) { + if (thresh > 0 && silence_hits > 0) { switch_ivr_wait_for_silence(session, thresh, silence_hits, listen_hits, timeout_ms, argv[4]); return; } From 5597fe30983a580bc009eb9e769e185d3c9035b6 Mon Sep 17 00:00:00 2001 From: Dragos Oancea Date: Mon, 10 Apr 2023 18:15:42 +0300 Subject: [PATCH 14/15] [mod_avmd] coverity CID 1395555 (Dereference before null check) --- src/mod/applications/mod_avmd/mod_avmd.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/mod/applications/mod_avmd/mod_avmd.c b/src/mod/applications/mod_avmd/mod_avmd.c index 6c59256eda..e5076c1500 100644 --- a/src/mod/applications/mod_avmd/mod_avmd.c +++ b/src/mod/applications/mod_avmd/mod_avmd.c @@ -1138,6 +1138,13 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_avmd_load) { switch_application_interface_t *app_interface; switch_api_interface_t *api_interface; + + if (pool == NULL) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No memory pool assigned!\n"); + + return SWITCH_STATUS_TERM; + } + /* connect my internal structure to the blank pointer passed to me */ *module_interface = switch_loadable_module_create_module_interface(pool, modname); @@ -1147,10 +1154,6 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_avmd_load) { } memset(&avmd_globals, 0, sizeof(avmd_globals)); - if (pool == NULL) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No memory pool assigned!\n"); - return SWITCH_STATUS_TERM; - } switch_mutex_init(&avmd_globals.mutex, SWITCH_MUTEX_NESTED, pool); avmd_globals.pool = pool; From b5cb26dc479860c62fa9d6e064f893779d27fe21 Mon Sep 17 00:00:00 2001 From: Dragos Oancea Date: Tue, 18 Apr 2023 19:30:22 +0300 Subject: [PATCH 15/15] [Core] Coverity fixes * [core] coverity CID 1024482 (Dereference after null check) * [core] coverity CID 1468368 (Logically dead code) * [core] coverity CID 1468459 (Logically dead code) * [core] coverity CID 1232742 (Dereference before null check) --- src/switch_core.c | 2 +- src/switch_packetizer.c | 2 -- src/switch_rtp.c | 3 +-- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/switch_core.c b/src/switch_core.c index cf2343482a..4e2b70778a 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -147,7 +147,7 @@ static void check_ip(void) } else if (strcmp(hostname, runtime.hostname)) { if (switch_event_create(&event, SWITCH_EVENT_TRAP) == SWITCH_STATUS_SUCCESS) { switch_event_add_header(event, SWITCH_STACK_BOTTOM, "condition", "hostname-change"); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "old-hostname", hostname ? hostname : "nil"); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "old-hostname", hostname); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "new-hostname", runtime.hostname); switch_event_fire(&event); } diff --git a/src/switch_packetizer.c b/src/switch_packetizer.c index 05688f8a86..626e85ba8e 100644 --- a/src/switch_packetizer.c +++ b/src/switch_packetizer.c @@ -160,8 +160,6 @@ SWITCH_DECLARE(switch_status_t) switch_packetizer_feed_extradata(switch_packetiz p += 5; left -= 5; - if (left < 0) return SWITCH_STATUS_FALSE; - //sps n_sps = *p & 0x1f; p += 1; diff --git a/src/switch_rtp.c b/src/switch_rtp.c index ad9f8eef1c..614d79bf78 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -1353,7 +1353,6 @@ SWITCH_DECLARE(void) switch_srtp_err_to_txt(srtp_err_status_t stat, char **msg) else if (stat == srtp_err_status_read_fail) *msg="couldn't read data"; else if (stat == srtp_err_status_write_fail) *msg="couldn't write data"; else if (stat == srtp_err_status_parse_err) *msg="error parsing data"; - else if (stat == srtp_err_status_write_fail) *msg="couldn't read data"; else if (stat == srtp_err_status_encode_err) *msg="error encoding data"; else if (stat == srtp_err_status_semaphore_err) *msg="error while using semaphores"; else if (stat == srtp_err_status_pfkey_err) *msg="error while using pfkey "; @@ -4947,7 +4946,7 @@ SWITCH_DECLARE(void) switch_rtp_kill_socket(switch_rtp_t *rtp_session) } if (rtp_session->flags[SWITCH_RTP_FLAG_ENABLE_RTCP]) { - if (rtp_session->rtcp_sock_input && rtp_session->rtcp_sock_input != rtp_session->sock_input) { + if (rtp_session->sock_input && rtp_session->rtcp_sock_input && rtp_session->rtcp_sock_input != rtp_session->sock_input) { ping_socket(rtp_session); switch_socket_shutdown(rtp_session->rtcp_sock_input, SWITCH_SHUTDOWN_READWRITE); }