about summary refs log tree commit diff
diff options
context:
space:
mode:
authorvan Hauser <vh@thc.org>2020-12-31 15:56:57 +0100
committerGitHub <noreply@github.com>2020-12-31 15:56:57 +0100
commitaf10a635f5b5e2b940b14ed5015e45878c2a2d34 (patch)
treebd8a29d58ccb3b0507ce60f4ca53efe1838ae36b
parent7e6645d5a25b874b978430eeb7d1ddce1f681d98 (diff)
parent935724557f1c9ee59141c7fc4b27c3831ad52435 (diff)
downloadafl++-af10a635f5b5e2b940b14ed5015e45878c2a2d34.tar.gz
Merge pull request #670 from devnexen/libdislocator_build_fix
libdislocator, ptr algo warning fix on clang/Xcode (m1).
-rw-r--r--utils/libdislocator/libdislocator.so.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/utils/libdislocator/libdislocator.so.c b/utils/libdislocator/libdislocator.so.c
index 2324e390..c2b200cb 100644
--- a/utils/libdislocator/libdislocator.so.c
+++ b/utils/libdislocator/libdislocator.so.c
@@ -345,10 +345,10 @@ void free(void *ptr) {
   len = PTR_L(ptr);
 
   total_mem -= len;
+  u8 *   ptr_ = ptr;
 
   if (align_allocations && (len & (ALLOC_ALIGN_SIZE - 1))) {
 
-    u8 *   ptr_ = ptr;
     size_t rlen = (len & ~(ALLOC_ALIGN_SIZE - 1)) + ALLOC_ALIGN_SIZE;
     for (; len < rlen; ++len)
       if (ptr_[len] != TAIL_ALLOC_CANARY)
@@ -359,11 +359,13 @@ void free(void *ptr) {
   /* Protect everything. Note that the extra page at the end is already
      set as PROT_NONE, so we don't need to touch that. */
 
-  ptr -= PAGE_SIZE * PG_COUNT(len + 8) - len - 8;
+  ptr_ -= PAGE_SIZE * PG_COUNT(len + 8) - len - 8;
 
-  if (mprotect(ptr - 8, PG_COUNT(len + 8) * PAGE_SIZE, PROT_NONE))
+  if (mprotect(ptr_ - 8, PG_COUNT(len + 8) * PAGE_SIZE, PROT_NONE))
     FATAL("mprotect() failed when freeing memory");
 
+  ptr = ptr_;
+
   /* Keep the mapping; this is wasteful, but prevents ptr reuse. */
 
 }