From: Filipe Cabecinhas Date: Tue, 13 Sep 2016 20:47:37 +0000 (+0000) Subject: [asan] Reify ErrorMallocUsableSizeNotOwned X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5f862c20cbd504914533e1d51915372560f54511;p=platform%2Fupstream%2Fllvm.git [asan] Reify ErrorMallocUsableSizeNotOwned Summary: Continuing implementation mentioned in this thread: http://lists.llvm.org/pipermail/llvm-dev/2016-July/101933.html Reviewers: kcc, eugenis, vitalybuka Subscribers: llvm-commits, kubabrecka Differential Revision: https://reviews.llvm.org/D24391 llvm-svn: 281391 --- diff --git a/compiler-rt/lib/asan/asan_errors.cc b/compiler-rt/lib/asan/asan_errors.cc index d35c228..6aeb5083 100644 --- a/compiler-rt/lib/asan/asan_errors.cc +++ b/compiler-rt/lib/asan/asan_errors.cc @@ -164,4 +164,17 @@ void ErrorAllocTypeMismatch::Print() { "ASAN_OPTIONS=alloc_dealloc_mismatch=0\n"); } +void ErrorMallocUsableSizeNotOwned::Print() { + Decorator d; + Printf("%s", d.Warning()); + Report( + "ERROR: AddressSanitizer: attempting to call malloc_usable_size() for " + "pointer which is not owned: %p\n", + addr_description.Address()); + Printf("%s", d.EndWarning()); + stack->Print(); + addr_description.Print(); + ReportErrorSummary("bad-malloc_usable_size", stack); +} + } // namespace __asan diff --git a/compiler-rt/lib/asan/asan_errors.h b/compiler-rt/lib/asan/asan_errors.h index 40c4369..4ee7c72 100644 --- a/compiler-rt/lib/asan/asan_errors.h +++ b/compiler-rt/lib/asan/asan_errors.h @@ -160,6 +160,22 @@ struct ErrorAllocTypeMismatch : ErrorBase { void Print(); }; +struct ErrorMallocUsableSizeNotOwned : ErrorBase { + // ErrorMallocUsableSizeNotOwned doesn't own the stack trace. + const BufferedStackTrace *stack; + AddressDescription addr_description; + // VS2013 doesn't implement unrestricted unions, so we need a trivial default + // constructor + ErrorMallocUsableSizeNotOwned() = default; + ErrorMallocUsableSizeNotOwned(u32 tid, BufferedStackTrace *stack_, uptr addr) + : ErrorBase(tid), + stack(stack_), + addr_description(addr, /*shouldLockThreadRegistry=*/false) { + scariness.Clear(); + } + void Print(); +}; + // clang-format off #define ASAN_FOR_EACH_ERROR_KIND(macro) \ macro(StackOverflow) \ @@ -167,7 +183,8 @@ struct ErrorAllocTypeMismatch : ErrorBase { macro(DoubleFree) \ macro(NewDeleteSizeMismatch) \ macro(FreeNotMalloced) \ - macro(AllocTypeMismatch) + macro(AllocTypeMismatch) \ + macro(MallocUsableSizeNotOwned) // clang-format on #define ASAN_DEFINE_ERROR_KIND(name) kErrorKind##name, diff --git a/compiler-rt/lib/asan/asan_report.cc b/compiler-rt/lib/asan/asan_report.cc index cf6aaff..8ae78ee 100644 --- a/compiler-rt/lib/asan/asan_report.cc +++ b/compiler-rt/lib/asan/asan_report.cc @@ -365,15 +365,8 @@ void ReportAllocTypeMismatch(uptr addr, BufferedStackTrace *free_stack, void ReportMallocUsableSizeNotOwned(uptr addr, BufferedStackTrace *stack) { ScopedInErrorReport in_report; - Decorator d; - Printf("%s", d.Warning()); - Report("ERROR: AddressSanitizer: attempting to call " - "malloc_usable_size() for pointer which is " - "not owned: %p\n", addr); - Printf("%s", d.EndWarning()); - stack->Print(); - DescribeAddressIfHeap(addr); - ReportErrorSummary("bad-malloc_usable_size", stack); + ErrorMallocUsableSizeNotOwned error(GetCurrentTidOrInvalid(), stack, addr); + in_report.ReportError(error); } void ReportSanitizerGetAllocatedSizeNotOwned(uptr addr,