Skip to content
This repository was archived by the owner on Apr 9, 2020. It is now read-only.
Open
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
5 changes: 4 additions & 1 deletion include/cn-cbor/cn-cbor.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ typedef enum cn_cbor_error {
CN_CBOR_ERR_OUT_OF_MEMORY,
/** A float was encountered during parse but the library was built without
support for float types. */
CN_CBOR_ERR_FLOAT_NOT_SUPPORTED
CN_CBOR_ERR_FLOAT_NOT_SUPPORTED,
/** An overflow occured while assigning an unsigned or signed integer
*/
CN_CBOR_ERR_OVERFLOW
} cn_cbor_error;

/**
Expand Down
13 changes: 10 additions & 3 deletions src/cn-cbor.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,15 @@ static cn_cbor *decode_item (struct parse_buf *pb CBOR_CONTEXT, cn_cbor* top_par
// process content
switch (mt) {
case MT_UNSIGNED:
cb->v.uint = val; /* to do: Overflow check */
/* with Overflow check */
if (__builtin_add_overflow(val, 0, &cb->v.uint))
CN_CBOR_FAIL(CN_CBOR_ERR_OVERFLOW);
break;
case MT_NEGATIVE:
cb->v.sint = ~val; /* to do: Overflow check */
/* with Overflow check */
if (__builtin_add_overflow(val, 0, &cb->v.sint))
CN_CBOR_FAIL(CN_CBOR_ERR_OVERFLOW);
cb->v.sint = ~cb->v.sint;
break;
case MT_BYTES: case MT_TEXT:
cb->v.str = (char *) pos;
Expand All @@ -171,7 +176,9 @@ static cn_cbor *decode_item (struct parse_buf *pb CBOR_CONTEXT, cn_cbor* top_par
}
break;
case MT_TAG:
cb->v.uint = val;
/* with Overflow check?*/
if (__builtin_add_overflow(val, 0, &cb->v.uint))
CN_CBOR_FAIL(CN_CBOR_ERR_OVERFLOW);
goto push;
case MT_PRIM:
switch (ai) {
Expand Down