Skip to content

Commit

Permalink
tests: fuzzers: fix fstore div-by-zero
Browse files Browse the repository at this point in the history
Signed-off-by: David Korczynski <[email protected]>
  • Loading branch information
DavidKorczynski committed Sep 26, 2023
1 parent adf20cc commit 9772c5b
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/internal/fuzzers/fstore_fuzzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 9772c5b

Please sign in to comment.