Skip to content
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
3 changes: 2 additions & 1 deletion src/oscore/oscore_cbor.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ oscore_cbor_put_bytes(uint8_t **buffer,
assert(*buf_size >= bytes_len);
(*buf_size) -= bytes_len;
*pt = (*pt | 0x40);
memcpy(*buffer, bytes, bytes_len);
if (bytes_len)
memcpy(*buffer, bytes, bytes_len);
(*buffer) += bytes_len;
return nb + bytes_len;
}
Expand Down
12 changes: 5 additions & 7 deletions tests/oss-fuzz/oscore_decrypt_target.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,18 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
if (session) {
/* Calculate OSCORE option length based on RFC 8613 Section 6.1 */
partial_iv_len = data[0] & 0x7;
if (1UL + partial_iv_len > size)
if (1UL + partial_iv_len >= size)
goto cleanup;

kid_context_len = data[0] & 0x10 ? 1 + data[1 + partial_iv_len] : 0;
/* 1s are byte 0 and kid length to be added */
if (1UL + partial_iv_len + kid_context_len + 1 > size)
goto cleanup;

/* Build option with KID forced to one byte to match recipient_id in oscore_conf_str */
kid_len = 1;
/* Include byte 0 in the length */
opt_len = 1 + partial_iv_len + kid_context_len + kid_len;
/* Max allowed option size is 256 */
if (opt_len >= sizeof(oscore_option) || opt_len > size)
goto cleanup;
memcpy(oscore_option, data, opt_len - 1);
oscore_option[opt_len - 1] = 0x01;

Expand Down Expand Up @@ -83,9 +84,6 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
cleanup:
coap_session_release(session);
}
} else {
/* coap_context_oscore_server failed, oscore_conf not consumed */
coap_delete_oscore_conf(oscore_conf);
}
} else if (oscore_conf) {
/* ctx creation failed, need to free oscore_conf */
Expand Down