Skip to content

Commit 30fa5b0

Browse files
author
Dominik Loidolt
committed
fuzz: Fix FUZZ_malloc_rand() to return non-NULL for zero-size allocations
The FUZZ_malloc_rand() function was incorrectly always returning NULL for zero-size allocations. The random offset generated by FUZZ_dataProducer_int32Range() was not being added to the pointer variable, causing the function to always return (void *)0.
1 parent bd89405 commit 30fa5b0

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

tests/fuzz/fuzz_helpers.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ void* FUZZ_malloc_rand(size_t size, FUZZ_dataProducer_t *producer)
3131
return mem;
3232
} else {
3333
uintptr_t ptr = 0;
34-
/* Add +- 1M 50% of the time */
34+
/* Return junk pointer 50% of the time */
3535
if (FUZZ_dataProducer_uint32Range(producer, 0, 1))
36-
FUZZ_dataProducer_int32Range(producer, -1000000, 1000000);
36+
ptr += FUZZ_dataProducer_int32Range(producer, -1000000, 1000000);
3737
return (void*)ptr;
3838
}
3939

0 commit comments

Comments
 (0)