diff options
author | Andrea Fioraldi <andreafioraldi@gmail.com> | 2020-01-30 22:52:27 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-30 22:52:27 +0100 |
commit | 6e9fce1c2d654c92dbf8e6b8cc21a88d8cba9496 (patch) | |
tree | 9c6d27d58d0606d59725ef46766eb1961e908d31 /libdislocator/libdislocator.so.c | |
parent | f07fc52cd061fadde21a57fd757e316d6254f588 (diff) | |
parent | b050c1158398dd07e25a6cd65234da84e5656fa6 (diff) | |
download | afl++-6e9fce1c2d654c92dbf8e6b8cc21a88d8cba9496.tar.gz |
Merge branch 'master' into CmpLog
Diffstat (limited to 'libdislocator/libdislocator.so.c')
-rw-r--r-- | libdislocator/libdislocator.so.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/libdislocator/libdislocator.so.c b/libdislocator/libdislocator.so.c index 20649470..221a629b 100644 --- a/libdislocator/libdislocator.so.c +++ b/libdislocator/libdislocator.so.c @@ -397,6 +397,29 @@ void* aligned_alloc(size_t align, size_t len) { } +/* specific BSD api mainly checking possible overflow for the size */ + +void* reallocarray(void* ptr, size_t elem_len, size_t elem_cnt) { + + const size_t elem_lim = 1UL << (sizeof(size_t) * 4); + const size_t elem_tot = elem_len * elem_cnt; + void* ret = NULL; + + if ((elem_len >= elem_lim || elem_cnt >= elem_lim) && elem_len > 0 && + elem_cnt > (SIZE_MAX / elem_len)) { + + DEBUGF("reallocarray size overflow (%zu)", elem_tot); + + } else { + + ret = realloc(ptr, elem_tot); + + } + + return ret; + +} + __attribute__((constructor)) void __dislocator_init(void) { u8* tmp = (u8*)getenv("AFL_LD_LIMIT_MB"); |