Skip to content

mbed-coap error fixes merge to mbed OS #3976

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions features/FEATURE_COMMON_PAL/mbed-coap/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Change Log

## [v4.0.3](https://github.com/ARMmbed/mbed-coap/releases/tag/v4.0.3)

-[Full Changelog](https://github.com/ARMmbed/mbed-coap/compare/v4.0.2...v4.0.3)

**New feature**

- CoAP Protocol Confirmable resend fix and minor memory optimization (IOTMAC-328)

**Closed issues:**

- IOTCLT-1439 - stuck in while loop

## [v4.0.0](https://github.com/ARMmbed/mbed-coap/releases/tag/v4.0.2)

**New feature**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ extern int8_t sn_coap_protocol_destroy(struct coap_s *handle);
* In failure cases:\n
* -1 = Failure in CoAP header structure\n
* -2 = Failure in given pointer (= NULL)\n
* -3 = Failure in Reset message\ŋ
* -3 = Failure in Reset message\n
* -4 = Failure in Resending message store\n
* If there is not enough memory (or User given limit exceeded) for storing
* resending messages, situation is ignored.
*/
Expand Down
2 changes: 1 addition & 1 deletion features/FEATURE_COMMON_PAL/mbed-coap/module.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mbed-coap",
"version": "4.0.2",
"version": "4.0.3",
"description": "COAP library",
"keywords": [
"coap",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ typedef struct sn_nsdl_transmit_ {

uint16_t packet_len;
uint8_t *packet_ptr;
uint8_t *uri_path_ptr;
uint8_t uri_path_len;
} sn_nsdl_transmit_s;

/* * * * * * * * * * * * * * * * * * * * * * */
Expand Down
30 changes: 10 additions & 20 deletions features/FEATURE_COMMON_PAL/mbed-coap/source/sn_coap_builder.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,21 +174,16 @@ uint16_t sn_coap_builder_calc_needed_packet_data_size_2(sn_coap_hdr_s *src_coap_
returned_byte_count += src_coap_msg_ptr->token_len;
}
/* URI PATH - Repeatable option. Length of one option is 0-255 */
/* Do not add uri-path for notification message.
* Uri-path is needed for cancelling observation with RESET message */
if (!src_coap_msg_ptr->options_list_ptr ||
(src_coap_msg_ptr->options_list_ptr &&
COAP_OBSERVE_NONE == src_coap_msg_ptr->options_list_ptr->observe)) {
if (src_coap_msg_ptr->uri_path_ptr != NULL) {
repeatable_option_size = sn_coap_builder_options_calc_option_size(src_coap_msg_ptr->uri_path_len,
src_coap_msg_ptr->uri_path_ptr, COAP_OPTION_URI_PATH);
if (repeatable_option_size) {
returned_byte_count += repeatable_option_size;
} else {
return 0;
}
if (src_coap_msg_ptr->uri_path_ptr != NULL) {
repeatable_option_size = sn_coap_builder_options_calc_option_size(src_coap_msg_ptr->uri_path_len,
src_coap_msg_ptr->uri_path_ptr, COAP_OPTION_URI_PATH);
if (repeatable_option_size) {
returned_byte_count += repeatable_option_size;
} else {
return 0;
}
}

uint16_t tempInt = 0;
/* CONTENT FORMAT - An integer option, up to 2 bytes */
if (src_coap_msg_ptr->content_format != COAP_CT_NONE) {
Expand Down Expand Up @@ -574,13 +569,8 @@ static int8_t sn_coap_builder_options_build(uint8_t **dst_packet_data_pptr, sn_c
&src_coap_msg_ptr->options_list_ptr->location_path_len, COAP_OPTION_LOCATION_PATH, &previous_option_number);
}
/* * * * Build Uri-Path option * * * */
/* Do not add uri-path for notification message.
* Uri-path is needed for cancelling observation with RESET message */
if (!src_coap_msg_ptr->options_list_ptr ||
(src_coap_msg_ptr->options_list_ptr &&
COAP_OBSERVE_NONE == src_coap_msg_ptr->options_list_ptr->observe))
sn_coap_builder_options_build_add_multiple_option(dst_packet_data_pptr, &src_coap_msg_ptr->uri_path_ptr,
&src_coap_msg_ptr->uri_path_len, COAP_OPTION_URI_PATH, &previous_option_number);
sn_coap_builder_options_build_add_multiple_option(dst_packet_data_pptr, &src_coap_msg_ptr->uri_path_ptr,
&src_coap_msg_ptr->uri_path_len, COAP_OPTION_URI_PATH, &previous_option_number);

/* * * * Build Content-Type option * * * */
if (src_coap_msg_ptr->content_format != COAP_CT_NONE) {
Expand Down
26 changes: 18 additions & 8 deletions features/FEATURE_COMMON_PAL/mbed-coap/source/sn_coap_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#include "mbed-coap/sn_coap_protocol.h"
#include "sn_coap_header_internal.h"
#include "sn_coap_protocol_internal.h"

/* * * * * * * * * * * * * * * * * * * * */
/* * * * LOCAL FUNCTION PROTOTYPES * * * */
/* * * * * * * * * * * * * * * * * * * * */
Expand Down Expand Up @@ -315,6 +314,7 @@ static int8_t sn_coap_parser_options_parse(struct coap_s *handle, uint8_t **pack
(*packet_data_pptr) += 2;
}

message_left = packet_len - (*packet_data_pptr - packet_data_start_ptr);

/* * * Parse option itself * * */
/* Some options are handled independently in own functions */
Expand Down Expand Up @@ -655,7 +655,7 @@ static int16_t sn_coap_parser_options_count_needed_memory_multiple_option(uint8_
uint16_t i = 1;

/* Loop all Uri-Query options */
while (i < packet_left_len) {
while (i <= packet_left_len) {
if (option == COAP_OPTION_LOCATION_PATH && option_number_len > 255) {
return -1;
}
Expand All @@ -677,14 +677,13 @@ static int16_t sn_coap_parser_options_count_needed_memory_multiple_option(uint8_

i += option_number_len;
ret_value += option_number_len + 1; /* + 1 is for separator */
if(ret_value >= packet_left_len)
break;

if(ret_value >= packet_left_len)
break;

if( i == packet_left_len )
if( i == packet_left_len ) {
break;
}
else if( i > packet_left_len ) {
return -1;
}

if ((*(packet_data_ptr + i) >> COAP_OPTIONS_OPTION_NUMBER_SHIFT) != 0) {
return (ret_value - 1); /* -1 because last Part path does not include separator */
Expand All @@ -693,9 +692,19 @@ static int16_t sn_coap_parser_options_count_needed_memory_multiple_option(uint8_
option_number_len = (*(packet_data_ptr + i) & 0x0F);

if (option_number_len == 13) {

if(i + 1 >= packet_left_len) {
return -1;
}

i++;
option_number_len = *(packet_data_ptr + i) + 13;
} else if (option_number_len == 14) {

if(i + 2 >= packet_left_len) {
return -1;
}

option_number_len = *(packet_data_ptr + i + 2);
option_number_len += (*(packet_data_ptr + i + 1) << 8) + 269;
i += 2;
Expand Down Expand Up @@ -750,3 +759,4 @@ static int8_t sn_coap_parser_payload_parse(uint16_t packet_data_len, uint8_t *pa
}
return 0;
}

Loading