From d393c16f3eb30d0c47e6f9d92db62272f0ec4dc7 Mon Sep 17 00:00:00 2001 From: Dmitry Shachnev Date: Thu, 11 Apr 2019 16:13:51 +0300 Subject: [PATCH] Parser: fix reading it->extra on big endian when bytesNeeded == 1 Signed-off-by: Dmitry Shachnev --- src/cborparser.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/cborparser.c b/src/cborparser.c index c6a1b762..74d91a30 100644 --- a/src/cborparser.c +++ b/src/cborparser.c @@ -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 |