Skip to content

Commit 40957f9

Browse files
authored
Enforce the block count limit when decoding (#79)
1 parent eda3e66 commit 40957f9

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

cmake/Findlibfuzzer.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
if(NOT CMAKE_C_COMPILER_ID MATCHES "Clang"
88
OR NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
9-
message(FATAL "Can only fuzz with clang compiler")
9+
message(FATAL_ERROR "Can only fuzz with clang compiler")
1010
endif()
1111

1212
# Options for all compilation units

src/mock_bpa/decode.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,23 +268,28 @@ int bsl_mock_decode_bundle(QCBORDecodeContext *dec, MockBPA_Bundle_t *bundle)
268268

269269
BSL_LOG_DEBUG("decoding primary block...");
270270
int res = bsl_mock_decode_primary(dec, &(bundle->primary_block));
271-
if (res || QCBORDecode_GetError(dec))
271+
if (res || (QCBOR_SUCCESS != QCBORDecode_GetError(dec)))
272272
{
273-
BSL_LOG_ERR("failed in primary block");
273+
BSL_LOG_ERR("failed decoding primary block");
274274
return 2;
275275
}
276276

277277
// iterate until failure of CBOR, not block decoder
278278
while (QCBOR_SUCCESS == QCBORDecode_PeekNext(dec, &decitem))
279279
{
280+
if (bundle->block_count >= MockBPA_BUNDLE_MAXBLOCKS)
281+
{
282+
BSL_LOG_ERR("number of canonical blocks exceeded limit %zd", MockBPA_BUNDLE_MAXBLOCKS);
283+
return 3;
284+
}
280285
BSL_LOG_DEBUG("decoding canonical block (at %zd)...", QCBORDecode_Tell(dec));
281286

282287
MockBPA_CanonicalBlock_t blk = { 0 };
283288

284289
res = bsl_mock_decode_canonical(dec, &blk);
285-
if (res || QCBORDecode_GetError(dec))
290+
if (res || (QCBOR_SUCCESS != QCBORDecode_GetError(dec)))
286291
{
287-
BSL_LOG_ERR("failed in canonical block");
292+
BSL_LOG_ERR("failed decoding canonical block");
288293
BSL_FREE(blk.btsd);
289294
return 3;
290295
}

0 commit comments

Comments
 (0)