Skip to content

Commit

Permalink
OSCORE Option: Check for off by one for kid
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdeep1 committed Jan 14, 2023
1 parent 7623e0f commit 7fab8aa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/coap_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,8 @@ coap_show_pdu(coap_log_t level, const coap_pdu_t *pdu) {
}
if (opt_val[0] & 0x10) {
/* kid context */
if (ofs >= opt_len)
goto no_more;
cnt = opt_val[ofs];
if (cnt > opt_len - ofs - 1)
goto no_more;
Expand All @@ -756,9 +758,9 @@ coap_show_pdu(coap_log_t level, const coap_pdu_t *pdu) {
}
if (opt_val[0] & 0x08) {
/* kid */
cnt = opt_len - ofs;
if (cnt > opt_len - ofs)
if (ofs >= opt_len)
goto no_more;
cnt = opt_len - ofs;
buf_len = strlen((char *)buf);
snprintf((char *)&buf[buf_len], sizeof(buf)-buf_len, "%skid=0x",
buf_len ? "," : "");
Expand Down
2 changes: 2 additions & 0 deletions src/oscore/oscore.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ oscore_decode_option_value(const uint8_t *opt_value,
if ((opt_value[0] & 0x10) != 0) {
coap_bin_const_t kid_context;

if (offset >= option_len)
return 0;
kid_context.length = opt_value[offset];
offset++;
if (offset + kid_context.length > option_len) {
Expand Down

0 comments on commit 7fab8aa

Please sign in to comment.