[compiler-rt] r350085 - Do not rely on that subject of ErrorAllocTypeMismatch is a heap address.

Martin Liska via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 27 00:39:14 PST 2018


Author: marxin
Date: Thu Dec 27 00:39:13 2018
New Revision: 350085

URL: http://llvm.org/viewvc/llvm-project?rev=350085&view=rev
Log:
Do not rely on that subject of ErrorAllocTypeMismatch is a heap address.

Differential Revision: https://reviews.llvm.org/D54856.

Added:
    compiler-rt/trunk/test/asan/TestCases/Linux/new_delete_mismatch_global.cc
    compiler-rt/trunk/test/asan/TestCases/Linux/new_delete_mismatch_stack.cc
Modified:
    compiler-rt/trunk/lib/asan/asan_errors.cc
    compiler-rt/trunk/lib/asan/asan_errors.h
    compiler-rt/trunk/test/asan/TestCases/Linux/new_delete_mismatch.cc

Modified: compiler-rt/trunk/lib/asan/asan_errors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_errors.cc?rev=350085&r1=350084&r2=350085&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_errors.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_errors.cc Thu Dec 27 00:39:13 2018
@@ -125,9 +125,8 @@ void ErrorAllocTypeMismatch::Print() {
   Decorator d;
   Printf("%s", d.Error());
   Report("ERROR: AddressSanitizer: %s (%s vs %s) on %p\n",
-         scariness.GetDescription(),
-         alloc_names[alloc_type], dealloc_names[dealloc_type],
-         addr_description.addr);
+         scariness.GetDescription(), alloc_names[alloc_type],
+         dealloc_names[dealloc_type], addr_description.Address());
   Printf("%s", d.Default());
   CHECK_GT(dealloc_stack->size, 0);
   scariness.Print();

Modified: compiler-rt/trunk/lib/asan/asan_errors.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_errors.h?rev=350085&r1=350084&r2=350085&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_errors.h (original)
+++ compiler-rt/trunk/lib/asan/asan_errors.h Thu Dec 27 00:39:13 2018
@@ -110,8 +110,8 @@ struct ErrorFreeNotMalloced : ErrorBase
 
 struct ErrorAllocTypeMismatch : ErrorBase {
   const BufferedStackTrace *dealloc_stack;
-  HeapAddressDescription addr_description;
   AllocType alloc_type, dealloc_type;
+  AddressDescription addr_description;
 
   ErrorAllocTypeMismatch() = default;  // (*)
   ErrorAllocTypeMismatch(u32 tid, BufferedStackTrace *stack, uptr addr,
@@ -119,9 +119,8 @@ struct ErrorAllocTypeMismatch : ErrorBas
       : ErrorBase(tid, 10, "alloc-dealloc-mismatch"),
         dealloc_stack(stack),
         alloc_type(alloc_type_),
-        dealloc_type(dealloc_type_) {
-    GetHeapAddressInformation(addr, 1, &addr_description);
-  };
+        dealloc_type(dealloc_type_),
+        addr_description(addr, 1, false) {}
   void Print();
 };
 

Modified: compiler-rt/trunk/test/asan/TestCases/Linux/new_delete_mismatch.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Linux/new_delete_mismatch.cc?rev=350085&r1=350084&r2=350085&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Linux/new_delete_mismatch.cc (original)
+++ compiler-rt/trunk/test/asan/TestCases/Linux/new_delete_mismatch.cc Thu Dec 27 00:39:13 2018
@@ -14,3 +14,4 @@ int main() {
 }
 
 // CHECK: AddressSanitizer: alloc-dealloc-mismatch (operator new [] vs operator delete) on 0x
+// CHECK: is located 0 bytes inside of 10-byte region

Added: compiler-rt/trunk/test/asan/TestCases/Linux/new_delete_mismatch_global.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Linux/new_delete_mismatch_global.cc?rev=350085&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Linux/new_delete_mismatch_global.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Linux/new_delete_mismatch_global.cc Thu Dec 27 00:39:13 2018
@@ -0,0 +1,16 @@
+// Check that we report delete on a memory that belongs to a global variable.
+
+// RUN: %clangxx_asan -g %s -o %t && %env_asan_opts=alloc_dealloc_mismatch=1 not %run %t 2>&1 | FileCheck %s
+
+#include <stdlib.h>
+
+static volatile char *x;
+char a[10];
+
+int main() {
+  x = &a[0];
+  delete x;
+}
+
+// CHECK: AddressSanitizer: attempting free on address which was not malloc()-ed
+// CHECK: is located 0 bytes inside of global variable 'a' defined in

Added: compiler-rt/trunk/test/asan/TestCases/Linux/new_delete_mismatch_stack.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Linux/new_delete_mismatch_stack.cc?rev=350085&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Linux/new_delete_mismatch_stack.cc (added)
+++ compiler-rt/trunk/test/asan/TestCases/Linux/new_delete_mismatch_stack.cc Thu Dec 27 00:39:13 2018
@@ -0,0 +1,17 @@
+// Check that we report delete on a memory that belongs to a stack variable.
+
+// RUN: %clangxx_asan -g %s -o %t && %env_asan_opts=alloc_dealloc_mismatch=1 not %run %t 2>&1 | FileCheck %s
+
+#include <stdlib.h>
+
+static volatile char *x;
+
+int main() {
+  char a[10];
+  x = &a[0];
+  delete x;
+}
+
+// CHECK: AddressSanitizer: attempting free on address which was not malloc()-ed
+// CHECK: is located in stack of thread T0 at offset
+// CHECK: 'a'{{.*}} <== Memory access at offset {{16|32}} is inside this variable




More information about the llvm-commits mailing list