From 9772c5b443dfefdf2fe833d449e9dc671b543e83 Mon Sep 17 00:00:00 2001 From: David Korczynski Date: Tue, 26 Sep 2023 05:57:33 +0100 Subject: [PATCH] tests: fuzzers: fix fstore div-by-zero Signed-off-by: David Korczynski --- tests/internal/fuzzers/fstore_fuzzer.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/internal/fuzzers/fstore_fuzzer.c b/tests/internal/fuzzers/fstore_fuzzer.c index dd7a6cf8b96..92ecf5d7a2d 100644 --- a/tests/internal/fuzzers/fstore_fuzzer.c +++ b/tests/internal/fuzzers/fstore_fuzzer.c @@ -45,6 +45,20 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) struct flb_fstore_stream *st; struct flb_fstore_file *fsf; + /* Set flb_malloc_mod to be fuzzer-data dependent */ + if (size < 4) { + return 0; + } + flb_malloc_p = 0; + flb_malloc_mod = *(int*)data; + data += 4; + size -= 4; + + /* Avoid division by zero for modulo operations */ + if (flb_malloc_mod == 0) { + flb_malloc_mod = 1; + } + cio_utils_recursive_delete(FSF_STORE_PATH); fs = flb_fstore_create(FSF_STORE_PATH, FLB_FSTORE_FS); st = flb_fstore_stream_create(fs, "abc");