Merge pull request #4403 from dloidolt/fix_FUZZ_malloc_rand

fuzz: Fix FUZZ_malloc_rand() to return non-NULL for zero-size allocations
This commit is contained in:
Yann Collet 2025-06-09 10:57:59 -07:00 committed by GitHub
commit 88bea95d11
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3 additions and 3 deletions

View file

@ -31,12 +31,11 @@ void* FUZZ_malloc_rand(size_t size, FUZZ_dataProducer_t *producer)
return mem;
} else {
uintptr_t ptr = 0;
/* Add +- 1M 50% of the time */
/* Return junk pointer 50% of the time */
if (FUZZ_dataProducer_uint32Range(producer, 0, 1))
FUZZ_dataProducer_int32Range(producer, -1000000, 1000000);
ptr += FUZZ_dataProducer_int32Range(producer, -1000000, 1000000);
return (void*)ptr;
}
}
int FUZZ_memcmp(void const* lhs, void const* rhs, size_t size)

View file

@ -66,6 +66,7 @@ void* FUZZ_malloc(size_t size);
/**
* malloc except returns random pointer for zero sized data and FUZZ_ASSERT
* that malloc doesn't fail.
* WARNING: Only free the returned pointer if size > 0!
*/
void* FUZZ_malloc_rand(size_t size, FUZZ_dataProducer_t *producer);