Skip to content

Commit

Permalink
Parser: fix reading it->extra on big endian when bytesNeeded == 1
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Shachnev <[email protected]>
  • Loading branch information
mitya57 authored and thiagomacieira committed Sep 3, 2021
1 parent 8adc3cf commit d393c16
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/cborparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,13 @@ static CborError preparse_value(CborValue *it)
it->extra = 0;

/* read up to 16 bits into it->extra */
if (bytesNeeded <= 2) {
if (bytesNeeded == 1) {
uint8_t extra;
read_bytes_unchecked(it, &extra, 1, bytesNeeded);
it->extra = extra;
} else if (bytesNeeded == 2) {
read_bytes_unchecked(it, &it->extra, 1, bytesNeeded);
if (bytesNeeded == 2)
it->extra = cbor_ntohs(it->extra);
it->extra = cbor_ntohs(it->extra);
} else {
cbor_static_assert(CborIteratorFlag_IntegerValueTooLarge == (Value32Bit & 3));
cbor_static_assert((CborIteratorFlag_IntegerValueIs64Bit |
Expand Down

0 comments on commit d393c16

Please sign in to comment.