diff options
author | van Hauser <vh@thc.org> | 2020-04-21 00:07:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-21 00:07:33 +0200 |
commit | 68218dd31cdbba2a13f42e7190e74bafed9e79c4 (patch) | |
tree | bf65624dc8c21f3c269ab2d1821451197cbf595f | |
parent | 8b319969f339aa2956a3cb733e3612df845b16e6 (diff) | |
parent | 441b64b467e17d62056c3cf7eae9e9a381644db7 (diff) | |
download | afl++-68218dd31cdbba2a13f42e7190e74bafed9e79c4.tar.gz |
Merge pull request #326 from dpmdpm2/master
Add malloc_usable_size to libdislocator.so
-rw-r--r-- | libdislocator/libdislocator.so.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/libdislocator/libdislocator.so.c b/libdislocator/libdislocator.so.c index 1fbfe9d6..19e84d9f 100644 --- a/libdislocator/libdislocator.so.c +++ b/libdislocator/libdislocator.so.c @@ -183,6 +183,9 @@ static void *__dislocator_alloc(size_t len) { else rlen = len; + /* We will also store buffer length and a canary below the actual buffer, so + let's add 8 bytes for that. */ + tlen = (1 + PG_COUNT(rlen + 8)) * PAGE_SIZE; flags = MAP_PRIVATE | MAP_ANONYMOUS; fd = -1; @@ -200,9 +203,6 @@ static void *__dislocator_alloc(size_t len) { (void)sp; #endif - /* We will also store buffer length and a canary below the actual buffer, so - let's add 8 bytes for that. */ - ret = (u8 *)mmap(NULL, tlen, PROT_READ | PROT_WRITE, flags, fd, 0); #if defined(USEHUGEPAGE) /* We try one more time with regular call */ @@ -296,10 +296,6 @@ void *calloc(size_t elem_len, size_t elem_cnt) { } -/* TODO: add a wrapper for posix_memalign, otherwise apps who use it, - will fail when freeing the memory. -*/ - /* The wrapper for malloc(). Roughly the same, also clobbers the returned memory (unlike calloc(), malloc() is not guaranteed to return zeroed memory). */ @@ -468,6 +464,12 @@ void *reallocarray(void *ptr, size_t elem_len, size_t elem_cnt) { } +size_t malloc_usable_size(void *ptr) { + + return ptr ? PTR_L(ptr) : 0; + +} + __attribute__((constructor)) void __dislocator_init(void) { u8 *tmp = (u8 *)getenv("AFL_LD_LIMIT_MB"); @@ -492,4 +494,3 @@ __attribute__((constructor)) void __dislocator_init(void) { align_allocations = !!getenv("AFL_ALIGNED_ALLOC"); } - |