[asan] rename new-delete-size-mismatch to new-delete-type-mismatch and make the report more verbose

llvm-svn: 214299
This commit is contained in:
Kostya Serebryany 2014-07-30 11:20:37 +00:00
parent e098b3b993
commit e7532e59c0
5 changed files with 18 additions and 14 deletions

View File

@ -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);
}

View File

@ -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;

View File

@ -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) {

View File

@ -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;

View File

@ -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
}