diff options
-rw-r--r-- | lib/asan/asan_errors.cc | 5 | ||||
-rw-r--r-- | lib/asan/asan_errors.h | 7 | ||||
-rw-r--r-- | test/asan/TestCases/Linux/new_delete_mismatch.cc | 1 | ||||
-rw-r--r-- | test/asan/TestCases/Linux/new_delete_mismatch_global.cc | 16 | ||||
-rw-r--r-- | test/asan/TestCases/Linux/new_delete_mismatch_stack.cc | 17 |
5 files changed, 39 insertions, 7 deletions
diff --git a/lib/asan/asan_errors.cc b/lib/asan/asan_errors.cc index 33d0613f7..0ecd30dca 100644 --- a/lib/asan/asan_errors.cc +++ b/lib/asan/asan_errors.cc @@ -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(); diff --git a/lib/asan/asan_errors.h b/lib/asan/asan_errors.h index 574197ebf..7ddd7e94e 100644 --- a/lib/asan/asan_errors.h +++ b/lib/asan/asan_errors.h @@ -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 : ErrorBase { : 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(); }; diff --git a/test/asan/TestCases/Linux/new_delete_mismatch.cc b/test/asan/TestCases/Linux/new_delete_mismatch.cc index 3a71862fb..05f74bda7 100644 --- a/test/asan/TestCases/Linux/new_delete_mismatch.cc +++ b/test/asan/TestCases/Linux/new_delete_mismatch.cc @@ -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 diff --git a/test/asan/TestCases/Linux/new_delete_mismatch_global.cc b/test/asan/TestCases/Linux/new_delete_mismatch_global.cc new file mode 100644 index 000000000..3f1a78715 --- /dev/null +++ b/test/asan/TestCases/Linux/new_delete_mismatch_global.cc @@ -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 diff --git a/test/asan/TestCases/Linux/new_delete_mismatch_stack.cc b/test/asan/TestCases/Linux/new_delete_mismatch_stack.cc new file mode 100644 index 000000000..bbf07cc21 --- /dev/null +++ b/test/asan/TestCases/Linux/new_delete_mismatch_stack.cc @@ -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 |