From e7532e59c057a07a27a569cc249cc3a27ff22194 Mon Sep 17 00:00:00 2001 From: Kostya Serebryany Date: Wed, 30 Jul 2014 11:20:37 +0000 Subject: [PATCH] [asan] rename new-delete-size-mismatch to new-delete-type-mismatch and make the report more verbose llvm-svn: 214299 --- compiler-rt/lib/asan/asan_allocator2.cc | 2 +- compiler-rt/lib/asan/asan_flags.h | 2 +- compiler-rt/lib/asan/asan_report.cc | 12 +++++++----- compiler-rt/lib/asan/asan_rtl.cc | 4 ++-- compiler-rt/test/asan/TestCases/Linux/sized_delete_test.cc | 12 +++++++----- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/compiler-rt/lib/asan/asan_allocator2.cc b/compiler-rt/lib/asan/asan_allocator2.cc index 969b895..fc626a7 100644 --- a/compiler-rt/lib/asan/asan_allocator2.cc +++ b/compiler-rt/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(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/compiler-rt/lib/asan/asan_flags.h b/compiler-rt/lib/asan/asan_flags.h index 8424104..d8cbbae 100644 --- a/compiler-rt/lib/asan/asan_flags.h +++ b/compiler-rt/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/compiler-rt/lib/asan/asan_report.cc b/compiler-rt/lib/asan/asan_report.cc index 4f162fa..56a6480 100644 --- a/compiler-rt/lib/asan/asan_report.cc +++ b/compiler-rt/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(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/compiler-rt/lib/asan/asan_rtl.cc b/compiler-rt/lib/asan/asan_rtl.cc index 809cc7c..e0f61e9 100644 --- a/compiler-rt/lib/asan/asan_rtl.cc +++ b/compiler-rt/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/compiler-rt/test/asan/TestCases/Linux/sized_delete_test.cc b/compiler-rt/test/asan/TestCases/Linux/sized_delete_test.cc index 822e057..19b7fc1 100644 --- a/compiler-rt/test/asan/TestCases/Linux/sized_delete_test.cc +++ b/compiler-rt/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 #include @@ -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(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 } -- 2.7.4