From 7c13b8f6b99de554f9e7b0d302aa9e3d58905624 Mon Sep 17 00:00:00 2001 From: int_szyk Date: Tue, 24 Sep 2019 10:44:38 +0200 Subject: [PATCH 1/4] CellularUtil prefer_ipv6: check length. Fixes Coverity issue about not checking the length of string before copying it. --- features/cellular/framework/common/CellularUtil.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/cellular/framework/common/CellularUtil.cpp b/features/cellular/framework/common/CellularUtil.cpp index 33c5956899d..5e616b545de 100644 --- a/features/cellular/framework/common/CellularUtil.cpp +++ b/features/cellular/framework/common/CellularUtil.cpp @@ -236,7 +236,7 @@ void prefer_ipv6(char *ip, size_t ip_size, char *ip2, size_t ip2_size) if (temp) { // ipv6 was found in ip2 but not in ip ---> we must swap them. Sadly ip and ip2 might not be pointers // so we can't just swap them, must use copy. - if (strlen(ip) < ip2_size && strlen(ip2) < ip_size && strlen(ip) < 64) { + if (strlen(ip) < ip2_size && strlen(ip2) < ip_size && strlen(ip) < 64 && strlen(ip2) < 64) { char tmp[64]; strncpy(tmp, ip, strlen(ip)); tmp[strlen(ip)] = '\0'; From b0b9553991e83c7c5b0c7ec1b88639a95917e0f5 Mon Sep 17 00:00:00 2001 From: int_szyk Date: Tue, 24 Sep 2019 11:01:00 +0200 Subject: [PATCH 2/4] CellularStack: remove unnecessary assignment. Fixes Coverity issue about unused variable. --- .../targets/RiotMicro/AT/RM1000_AT_CellularStack.cpp | 3 +-- .../framework/targets/UBLOX/AT/UBLOX_AT_CellularStack.cpp | 6 ++---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/features/cellular/framework/targets/RiotMicro/AT/RM1000_AT_CellularStack.cpp b/features/cellular/framework/targets/RiotMicro/AT/RM1000_AT_CellularStack.cpp index dc202aa8bed..0b73dfb3f50 100644 --- a/features/cellular/framework/targets/RiotMicro/AT/RM1000_AT_CellularStack.cpp +++ b/features/cellular/framework/targets/RiotMicro/AT/RM1000_AT_CellularStack.cpp @@ -281,10 +281,9 @@ nsapi_size_or_error_t RM1000_AT_CellularStack::socket_recvfrom_impl(CellularSock } else { if (count == 0) { // Timeout with nothing received - nsapi_error_size = NSAPI_ERROR_WOULD_BLOCK; success = false; } - size = 0; // This simply to cause an exit + break; } } timer.stop(); diff --git a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularStack.cpp b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularStack.cpp index 848fbb5b1da..819eef3df86 100644 --- a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularStack.cpp +++ b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularStack.cpp @@ -302,10 +302,9 @@ nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_recvfrom_impl(CellularSocke } else { if (count == 0) { // Timeout with nothing received - nsapi_error_size = NSAPI_ERROR_WOULD_BLOCK; success = false; } - size = 0; // This simply to cause an exit + break; } } } else if (socket->proto == NSAPI_TCP) { @@ -346,10 +345,9 @@ nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_recvfrom_impl(CellularSocke } else { if (count == 0) { // Timeout with nothing received - nsapi_error_size = NSAPI_ERROR_WOULD_BLOCK; success = false; } - size = 0; // This simply to cause an exit + break; } } } From 76407bc6546989f66627347867f0762918bc5681 Mon Sep 17 00:00:00 2001 From: int_szyk Date: Tue, 24 Sep 2019 11:35:52 +0200 Subject: [PATCH 3/4] sn_coap_builder: remove unnecessary code. Fixes Coverity issue about unused variable. --- features/frameworks/mbed-coap/source/sn_coap_builder.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/features/frameworks/mbed-coap/source/sn_coap_builder.c b/features/frameworks/mbed-coap/source/sn_coap_builder.c index d34edb04788..bd560511576 100644 --- a/features/frameworks/mbed-coap/source/sn_coap_builder.c +++ b/features/frameworks/mbed-coap/source/sn_coap_builder.c @@ -484,15 +484,6 @@ static uint8_t sn_coap_builder_options_calculate_jump_need(const sn_coap_hdr_s * } } - else { - if (src_coap_msg_ptr->uri_path_ptr != 0) { - previous_option_number = (COAP_OPTION_URI_PATH); - } - - if (src_coap_msg_ptr->content_format != COAP_CT_NONE) { - previous_option_number = (COAP_OPTION_CONTENT_FORMAT); - } - } return needed_space; } From a60df639fec0e929fe4efff80c1dfdc9ad83d3cf Mon Sep 17 00:00:00 2001 From: int_szyk Date: Tue, 24 Sep 2019 12:53:53 +0200 Subject: [PATCH 4/4] thread_mle_message_handler: fix null comparison. Fixes Coverity issue about comparing nullptr. --- .../source/6LoWPAN/Thread/thread_mle_message_handler.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/features/nanostack/sal-stack-nanostack/source/6LoWPAN/Thread/thread_mle_message_handler.c b/features/nanostack/sal-stack-nanostack/source/6LoWPAN/Thread/thread_mle_message_handler.c index 68df5ed7190..a8253c5f8eb 100644 --- a/features/nanostack/sal-stack-nanostack/source/6LoWPAN/Thread/thread_mle_message_handler.c +++ b/features/nanostack/sal-stack-nanostack/source/6LoWPAN/Thread/thread_mle_message_handler.c @@ -514,7 +514,7 @@ static void thread_parse_annoucement(protocol_interface_info_entry_t *cur, mle_m channel_page = ptr[0]; channel = common_read_16_bit(&ptr[1]); - if (linkConfiguration->timestamp == timestamp) { + if (linkConfiguration && linkConfiguration->timestamp == timestamp) { // We received same timestamp tr_debug("Same timestamp"); return; @@ -527,7 +527,7 @@ static void thread_parse_annoucement(protocol_interface_info_entry_t *cur, mle_m } - if (linkConfiguration->timestamp > timestamp) { + if (linkConfiguration && linkConfiguration->timestamp > timestamp) { // We received older time stamp we just announce back to originator channel thread_bootstrap_announce_send(cur, linkConfiguration->channel_page, linkConfiguration->rfChannel, linkConfiguration->panId, linkConfiguration->timestamp, channel); return;