Skip to content

Commit de798c4

Browse files
authored
Merge pull request #12147 from ristohuhtala/mbed-coap-builder-uint-overflow
mbed-coap uint16 overflow fix
2 parents b79da0c + 1d22013 commit de798c4

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

features/frameworks/mbed-coap/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Change Log
22

3+
## [v5.1.3](https://github.com/ARMmbed/mbed-coap/releases/tag/v5.1.3)
4+
5+
- Fix potential integer overflow when calculating CoAP data packet size: IOTCLT-3748 CVE-2019-17211 - mbed-coap integer overflow
6+
- Fix buffer overflow when parsing CoAP message: IOTCLT-3749 CVE-2019-17212 - mbed-coap Buffer overflow
7+
8+
-[Full Changelog](https://github.com/ARMmbed/mbed-coap/compare/v5.1.2...v5.1.3)
9+
10+
311
## [v5.1.2](https://github.com/ARMmbed/mbed-coap/releases/tag/v5.1.2)
412

513
- Compiler warning cleanups.

features/frameworks/mbed-coap/source/sn_coap_builder.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ uint16_t sn_coap_builder_calc_needed_packet_data_size(const sn_coap_hdr_s *src_c
155155
uint16_t sn_coap_builder_calc_needed_packet_data_size_2(const sn_coap_hdr_s *src_coap_msg_ptr, uint16_t blockwise_payload_size)
156156
{
157157
(void)blockwise_payload_size;
158-
uint16_t returned_byte_count = 0;
158+
uint_fast32_t returned_byte_count = 0;
159159

160160
if (!src_coap_msg_ptr) {
161161
return 0;
@@ -176,7 +176,6 @@ uint16_t sn_coap_builder_calc_needed_packet_data_size_2(const sn_coap_hdr_s *src
176176
tr_error("sn_coap_builder_calc_needed_packet_data_size_2 - token too large!");
177177
return 0;
178178
}
179-
180179
returned_byte_count += src_coap_msg_ptr->token_len;
181180
}
182181
/* URI PATH - Repeatable option. Length of one option is 0-255 */
@@ -198,7 +197,6 @@ uint16_t sn_coap_builder_calc_needed_packet_data_size_2(const sn_coap_hdr_s *src
198197
tr_error("sn_coap_builder_calc_needed_packet_data_size_2 - content format too large!");
199198
return 0;
200199
}
201-
202200
returned_byte_count += sn_coap_builder_options_build_add_uint_option(NULL, src_coap_msg_ptr->content_format, COAP_OPTION_CONTENT_FORMAT, &tempInt);
203201
}
204202
/* If options list pointer exists */
@@ -212,7 +210,6 @@ uint16_t sn_coap_builder_calc_needed_packet_data_size_2(const sn_coap_hdr_s *src
212210
tr_error("sn_coap_builder_calc_needed_packet_data_size_2 - accept too large!");
213211
return 0;
214212
}
215-
216213
returned_byte_count += sn_coap_builder_options_build_add_uint_option(NULL, src_options_list_ptr->accept, COAP_OPTION_ACCEPT, &tempInt);
217214
}
218215
/* MAX AGE - An integer option, omitted for default. Up to 4 bytes */
@@ -266,7 +263,6 @@ uint16_t sn_coap_builder_calc_needed_packet_data_size_2(const sn_coap_hdr_s *src
266263
tr_error("sn_coap_builder_calc_needed_packet_data_size_2 - uri host too large!");
267264
return 0;
268265
}
269-
270266
returned_byte_count += src_options_list_ptr->uri_host_len;
271267
}
272268
/* LOCATION PATH - Repeatable option. Length of this option is 0-255 bytes*/
@@ -359,8 +355,13 @@ uint16_t sn_coap_builder_calc_needed_packet_data_size_2(const sn_coap_hdr_s *src
359355
}
360356
returned_byte_count += sn_coap_builder_options_calculate_jump_need(src_coap_msg_ptr);
361357
}
362-
return returned_byte_count;
358+
if (returned_byte_count > UINT16_MAX) {
359+
tr_error("sn_coap_builder_calc_needed_packet_data_size_2 - packet data size would overflow!");
360+
return 0;
361+
}
362+
return (uint16_t)returned_byte_count;
363363
}
364+
364365
/**
365366
* \fn static uint8_t sn_coap_builder_options_calculate_jump_need(sn_coap_hdr_s *src_coap_msg_ptr)
366367
*

0 commit comments

Comments
 (0)