Skip to content

Commit 22af703

Browse files
committed
cbor: avoid passing null to memcpy with len 0 in tinycbor
Found by asan.
1 parent 7c8fd71 commit 22af703

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

main/utils/cbor_rpc.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,13 @@ void add_bytes_to_map(CborEncoder* container, const char* name, const uint8_t* v
673673

674674
CborError cberr = cbor_encode_text_stringz(container, name);
675675
JADE_ASSERT(cberr == CborNoError);
676+
#ifdef CONFIG_LIBJADE
677+
// Prevent passing null to memcpy with len 0 in tinycbor
678+
const uint8_t dummy = 0;
679+
cberr = cbor_encode_byte_string(container, len ? value : &dummy, len);
680+
#else
676681
cberr = cbor_encode_byte_string(container, value, len);
682+
#endif
677683
JADE_ASSERT(cberr == CborNoError);
678684
}
679685

0 commit comments

Comments
 (0)