summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2014-07-30 11:20:37 +0000
committerKostya Serebryany <kcc@google.com>2014-07-30 11:20:37 +0000
commit9c4881481eed4ff08f8b74ee1471efe70c3f6fd1 (patch)
treec20d4996e3ff03cb989f129624139275a0b0dcab
parentac60245e84ec9c1bd0dfd3857fd2687fa7091300 (diff)
[asan] rename new-delete-size-mismatch to new-delete-type-mismatch and make the report more verbose
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@214299 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/asan/asan_allocator2.cc2
-rw-r--r--lib/asan/asan_flags.h2
-rw-r--r--lib/asan/asan_report.cc12
-rw-r--r--lib/asan/asan_rtl.cc4
-rw-r--r--test/asan/TestCases/Linux/sized_delete_test.cc12
5 files changed, 18 insertions, 14 deletions
diff --git a/lib/asan/asan_allocator2.cc b/lib/asan/asan_allocator2.cc
index 969b895d4..fc626a733 100644
--- a/lib/asan/asan_allocator2.cc
+++ b/lib/asan/asan_allocator2.cc
@@ -454,7 +454,7 @@ static void Deallocate(void *ptr, uptr delete_size, StackTrace *stack,
uptr chunk_beg = p - kChunkHeaderSize;
AsanChunk *m = reinterpret_cast<AsanChunk *>(chunk_beg);
- if (delete_size && flags()->new_delete_size_mismatch &&
+ if (delete_size && flags()->new_delete_type_mismatch &&
delete_size != m->UsedSize()) {
ReportNewDeleteSizeMismatch(p, delete_size, stack);
}
diff --git a/lib/asan/asan_flags.h b/lib/asan/asan_flags.h
index 842410487..d8cbbae1f 100644
--- a/lib/asan/asan_flags.h
+++ b/lib/asan/asan_flags.h
@@ -58,7 +58,7 @@ struct Flags {
bool poison_heap;
bool poison_partial;
bool alloc_dealloc_mismatch;
- bool new_delete_size_mismatch;
+ bool new_delete_type_mismatch;
bool strict_memcmp;
bool strict_init_order;
bool start_deactivated;
diff --git a/lib/asan/asan_report.cc b/lib/asan/asan_report.cc
index 4f162fa14..56a648023 100644
--- a/lib/asan/asan_report.cc
+++ b/lib/asan/asan_report.cc
@@ -659,19 +659,21 @@ void ReportNewDeleteSizeMismatch(uptr addr, uptr delete_size,
Printf("%s", d.Warning());
char tname[128];
u32 curr_tid = GetCurrentTidOrInvalid();
- Report("ERROR: AddressSanitizer: new-delete-size-mismatch on %p in "
+ Report("ERROR: AddressSanitizer: new-delete-type-mismatch on %p in "
"thread T%d%s:\n",
addr, curr_tid,
ThreadNameWithParenthesis(curr_tid, tname, sizeof(tname)));
- Printf("%s sized operator delete called with size %zd\n", d.EndWarning(),
- delete_size);
+ Printf("%s object passed to delete has wrong type:\n", d.EndWarning());
+ Printf(" size of the allocated type: %zd bytes;\n"
+ " size of the deallocated type: %zd bytes.\n",
+ asan_mz_size(reinterpret_cast<void*>(addr)), delete_size);
CHECK_GT(free_stack->size, 0);
GET_STACK_TRACE_FATAL(free_stack->trace[0], free_stack->top_frame_bp);
stack.Print();
DescribeHeapAddress(addr, 1);
- ReportErrorSummary("new-delete-size-mismatch", &stack);
+ ReportErrorSummary("new-delete-type-mismatch", &stack);
Report("HINT: if you don't care about these warnings you may set "
- "ASAN_OPTIONS=new_delete_size_mismatch=0\n");
+ "ASAN_OPTIONS=new_delete_type_mismatch=0\n");
}
void ReportFreeNotMalloced(uptr addr, StackTrace *free_stack) {
diff --git a/lib/asan/asan_rtl.cc b/lib/asan/asan_rtl.cc
index 809cc7c4a..e0f61e9df 100644
--- a/lib/asan/asan_rtl.cc
+++ b/lib/asan/asan_rtl.cc
@@ -199,7 +199,7 @@ static void ParseFlagsFromString(Flags *f, const char *str) {
ParseFlag(str, &f->alloc_dealloc_mismatch, "alloc_dealloc_mismatch",
"Report errors on malloc/delete, new/free, new/delete[], etc.");
- ParseFlag(str, &f->new_delete_size_mismatch, "new_delete_size_mismatch",
+ ParseFlag(str, &f->new_delete_type_mismatch, "new_delete_type_mismatch",
"Report errors on mismatch betwen size of new and delete.");
ParseFlag(str, &f->strict_memcmp, "strict_memcmp",
@@ -278,7 +278,7 @@ void InitializeFlags(Flags *f, const char *env) {
// https://code.google.com/p/address-sanitizer/issues/detail?id=309
// TODO(glider,timurrrr): Fix known issues and enable this back.
f->alloc_dealloc_mismatch = (SANITIZER_MAC == 0) && (SANITIZER_WINDOWS == 0);
- f->new_delete_size_mismatch = true;
+ f->new_delete_type_mismatch = true;
f->strict_memcmp = true;
f->strict_init_order = false;
f->start_deactivated = false;
diff --git a/test/asan/TestCases/Linux/sized_delete_test.cc b/test/asan/TestCases/Linux/sized_delete_test.cc
index 822e05722..19b7fc1c2 100644
--- a/test/asan/TestCases/Linux/sized_delete_test.cc
+++ b/test/asan/TestCases/Linux/sized_delete_test.cc
@@ -1,7 +1,7 @@
// RUN: %clangxx_asan -Xclang -fsized-deallocation -O0 %s -o %t
// RUN: not %run %t 2>&1 | FileCheck %s
-// RUN: ASAN_OPTIONS=new_delete_size_mismatch=1 not %run %t 2>&1 | FileCheck %s
-// RUN: ASAN_OPTIONS=new_delete_size_mismatch=0 %run %t
+// RUN: ASAN_OPTIONS=new_delete_type_mismatch=1 not %run %t 2>&1 | FileCheck %s
+// RUN: ASAN_OPTIONS=new_delete_type_mismatch=0 %run %t
#include <new>
#include <stdio.h>
@@ -51,8 +51,10 @@ int main() {
// Here asan should bark as we are passing a wrong type of pointer
// to sized delete.
Del12(reinterpret_cast<S12*>(new S20));
- // CHECK: AddressSanitizer: new-delete-size-mismatch
- // CHECK: sized operator delete called with size
+ // CHECK: AddressSanitizer: new-delete-type-mismatch
+ // CHECK: object passed to delete has wrong type:
+ // CHECK: size of the allocated type: 20 bytes;
+ // CHECK: size of the deallocated type: 12 bytes.
// CHECK: is located 0 bytes inside of 20-byte region
- // CHECK: SUMMARY: AddressSanitizer: new-delete-size-mismatch
+ // CHECK: SUMMARY: AddressSanitizer: new-delete-type-mismatch
}