Skip to content

Commit 462a1bd

Browse files
committed
cbor: guard against integer overflow when checking buffer size
Found by afl. Signed-off-by: Josef 'Jeff' Sipek <[email protected]>
1 parent ee407a7 commit 462a1bd

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

fmt_cbor.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -607,8 +607,11 @@ int cbor_unpack_cstr_len(struct buffer *buffer, char **str, size_t *len)
607607
if (ret)
608608
return ret;
609609

610-
/* can't handle strings longer than what fits in memory */
611-
if (parsed_len > SIZE_MAX)
610+
/*
611+
* We can't handle strings longer than what fits in memory (the +1
612+
* is for nul termination).
613+
*/
614+
if (parsed_len >= SIZE_MAX)
612615
return -EOVERFLOW;
613616

614617
out = malloc(parsed_len + 1);

0 commit comments

Comments
 (0)