Fix reallocation logic when IsInDlsymAllocPool(ptr) is true.
authorMaxim Ostapenko <m.ostapenko@partner.samsung.com>
Mon, 26 Sep 2016 08:11:21 +0000 (08:11 +0000)
committerSylvestre Ledru <sylvestre@debian.org>
Sun, 18 Jun 2017 17:12:15 +0000 (18:12 +0100)
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@282389 91177308-0d34-0410-b5e6-96231b3b80d8

Gbp-Pq: Name upstream-asan-msan-fix-reallocation-logic.diff

compiler-rt/lib/asan/asan_malloc_linux.cc
compiler-rt/lib/msan/msan_interceptors.cc

index d7a22d6839a96c4e8ec2878e18165ccbcfed77c4..a78767c19f0f0c8b2ccb37cdb8ba05820bd96b72 100644 (file)
@@ -79,10 +79,12 @@ INTERCEPTOR(void*, realloc, void *ptr, uptr size) {
     uptr offset = (uptr)ptr - (uptr)alloc_memory_for_dlsym;
     uptr copy_size = Min(size, kDlsymAllocPoolSize - offset);
     void *new_ptr;
-    if (UNLIKELY(!asan_inited))
+    if (UNLIKELY(!asan_inited)) {
       new_ptr = AllocateFromLocalPool(size);
-    else
-      new_ptr = asan_malloc(size, &stack);
+    } else {
+      copy_size = size;
+      new_ptr = asan_malloc(copy_size, &stack);
+    }
     internal_memcpy(new_ptr, ptr, copy_size);
     return new_ptr;
   }
index 2aeaef49e54e165a4999fa1523538a181eb6c3fb..93b93aec283d669880c6759380531a86ea3e9235 100644 (file)
@@ -935,7 +935,13 @@ INTERCEPTOR(void *, realloc, void *ptr, SIZE_T size) {
   if (UNLIKELY(IsInDlsymAllocPool(ptr))) {
     uptr offset = (uptr)ptr - (uptr)alloc_memory_for_dlsym;
     uptr copy_size = Min(size, kDlsymAllocPoolSize - offset);
-    void *new_ptr = AllocateFromLocalPool(size);
+    void *new_ptr;
+    if (UNLIKELY(!msan_inited)) {
+      new_ptr = AllocateFromLocalPool(copy_size);
+    } else {
+      copy_size = size;
+      new_ptr = MsanReallocate(&stack, ptr, copy_size, sizeof(u64), false);
+    }
     internal_memcpy(new_ptr, ptr, copy_size);
     return new_ptr;
   }