diff options
author | Dominik Maier <domenukk@gmail.com> | 2020-01-27 13:30:11 +0100 |
---|---|---|
committer | Dominik Maier <domenukk@gmail.com> | 2020-01-27 13:30:11 +0100 |
commit | 9bf8f794968483055bcde46f3df1c8238fae7f76 (patch) | |
tree | 15a41fad96095b0e49bb5f9c3cd76f20251ddef1 /libdislocator/libdislocator.so.c | |
parent | 38232979587b6c37b024f22849b311d7e6962edf (diff) | |
parent | 17f0aad0f0322a0c56040b3bd93d2bf020a3f3fb (diff) | |
download | afl++-9bf8f794968483055bcde46f3df1c8238fae7f76.tar.gz |
Merge branch 'master' of github.com:vanhauser-thc/AFLplusplus
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"); |