Skip to content

Commit 81fbe2e

Browse files
bergzandthiagomacieira
authored andcommitted
Change flag type to uint32_t for parser flags
The argument for the parser flags should have uint32_t as type to prevent overflow on platforms where an int is not 32 bit wide.
1 parent 66f0e78 commit 81fbe2e

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/cbor.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ enum CborParserIteratorFlags
276276
struct CborParser
277277
{
278278
const uint8_t *end;
279-
int flags;
279+
uint32_t flags;
280280
};
281281
typedef struct CborParser CborParser;
282282

@@ -291,7 +291,7 @@ struct CborValue
291291
};
292292
typedef struct CborValue CborValue;
293293

294-
CBOR_API CborError cbor_parser_init(const uint8_t *buffer, size_t size, int flags, CborParser *parser, CborValue *it);
294+
CBOR_API CborError cbor_parser_init(const uint8_t *buffer, size_t size, uint32_t flags, CborParser *parser, CborValue *it);
295295

296296
CBOR_API CborError cbor_value_validate_basic(const CborValue *it);
297297

@@ -556,7 +556,7 @@ enum CborValidationFlags {
556556
CborValidateBasic = 0
557557
};
558558

559-
CBOR_API CborError cbor_value_validate(const CborValue *it, int flags);
559+
CBOR_API CborError cbor_value_validate(const CborValue *it, uint32_t flags);
560560

561561
/* Human-readable (dump) API */
562562

src/cborparser.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ uint64_t _cbor_value_decode_int64_internal(const CborValue *value)
372372
* threads iterating at the same time, but the object can be copied so multiple
373373
* threads can iterate.
374374
*/
375-
CborError cbor_parser_init(const uint8_t *buffer, size_t size, int flags, CborParser *parser, CborValue *it)
375+
CborError cbor_parser_init(const uint8_t *buffer, size_t size, uint32_t flags, CborParser *parser, CborValue *it)
376376
{
377377
memset(parser, 0, sizeof(*parser));
378378
parser->end = buffer + size;

src/cborvalidation.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ static const struct KnownTagData knownTagData[] = {
265265
{ 55799, 0U }
266266
};
267267

268-
static CborError validate_value(CborValue *it, int flags, int recursionLeft);
268+
static CborError validate_value(CborValue *it, uint32_t flags, int recursionLeft);
269269

270270
static inline CborError validate_utf8_string(const void *ptr, size_t n)
271271
{
@@ -279,7 +279,7 @@ static inline CborError validate_utf8_string(const void *ptr, size_t n)
279279
return CborNoError;
280280
}
281281

282-
static inline CborError validate_simple_type(uint8_t simple_type, int flags)
282+
static inline CborError validate_simple_type(uint8_t simple_type, uint32_t flags)
283283
{
284284
/* At current time, all known simple types are those from RFC 7049,
285285
* which are parsed by the parser into different CBOR types.
@@ -290,7 +290,7 @@ static inline CborError validate_simple_type(uint8_t simple_type, int flags)
290290
CborErrorUnknownSimpleType : CborNoError;
291291
}
292292

293-
static inline CborError validate_number(const CborValue *it, CborType type, int flags)
293+
static inline CborError validate_number(const CborValue *it, CborType type, uint32_t flags)
294294
{
295295
CborError err = CborNoError;
296296
const uint8_t *ptr = it->ptr;
@@ -320,7 +320,7 @@ static inline CborError validate_number(const CborValue *it, CborType type, int
320320
return CborNoError;
321321
}
322322

323-
static inline CborError validate_tag(CborValue *it, CborTag tag, int flags, int recursionLeft)
323+
static inline CborError validate_tag(CborValue *it, CborTag tag, uint32_t flags, int recursionLeft)
324324
{
325325
CborType type = cbor_value_get_type(it);
326326
const size_t knownTagCount = sizeof(knownTagData) / sizeof(knownTagData[0]);
@@ -373,7 +373,7 @@ static inline CborError validate_tag(CborValue *it, CborTag tag, int flags, int
373373
}
374374

375375
#ifndef CBOR_NO_FLOATING_POINT
376-
static inline CborError validate_floating_point(CborValue *it, CborType type, int flags)
376+
static inline CborError validate_floating_point(CborValue *it, CborType type, uint32_t flags)
377377
{
378378
CborError err;
379379
double val;
@@ -435,7 +435,7 @@ static inline CborError validate_floating_point(CborValue *it, CborType type, in
435435
}
436436
#endif
437437

438-
static CborError validate_container(CborValue *it, int containerType, int flags, int recursionLeft)
438+
static CborError validate_container(CborValue *it, int containerType, uint32_t flags, int recursionLeft)
439439
{
440440
CborError err;
441441
const uint8_t *previous = NULL;
@@ -509,7 +509,7 @@ static CborError validate_container(CborValue *it, int containerType, int flags,
509509
return CborNoError;
510510
}
511511

512-
static CborError validate_value(CborValue *it, int flags, int recursionLeft)
512+
static CborError validate_value(CborValue *it, uint32_t flags, int recursionLeft)
513513
{
514514
CborError err;
515515
CborType type = cbor_value_get_type(it);
@@ -648,7 +648,7 @@ static CborError validate_value(CborValue *it, int flags, int recursionLeft)
648648
*
649649
* \sa CborValidationFlags, cbor_value_validate_basic(), cbor_value_advance()
650650
*/
651-
CborError cbor_value_validate(const CborValue *it, int flags)
651+
CborError cbor_value_validate(const CborValue *it, uint32_t flags)
652652
{
653653
CborValue value = *it;
654654
CborError err = validate_value(&value, flags, CBOR_PARSER_MAX_RECURSIONS);

0 commit comments

Comments
 (0)