Index: lib/asan/asan_errors.h =================================================================== --- lib/asan/asan_errors.h +++ lib/asan/asan_errors.h @@ -180,14 +180,34 @@ void Print(); }; -#define FOR_EACH_ERROR_KIND_MEMBER_NAME_PAIR(macro) \ - macro(StackOverflow, stack_overflow) \ - macro(DeadlySignal, deadly_signal) \ - macro(DoubleFree, double_free) \ - macro(NewDeleteSizeMismatch, new_delete_size_mismatch) \ - macro(FreeNotMalloced, free_not_malloced) \ - macro(AllocTypeMismatch, alloc_type_mismatch) \ - macro(MallocUsableSizeNotOwned, malloc_uzable_size_not_owned) +struct ErrorSanitizerGetAllocatedSizeNotOwned : ErrorBase { + u32 tid; + // ErrorSanitizerGetAllocatedSizeNotOwned doesn't own the stack trace. + BufferedStackTrace *stack; + AddressDescriptionBase addr_description; + // VS2013 doesn't implement unrestricted unions, so we need a trivial default + // constructor + ErrorSanitizerGetAllocatedSizeNotOwned() = default; + ErrorSanitizerGetAllocatedSizeNotOwned(uptr addr, u32 tid_, + BufferedStackTrace *stack_) + : tid(tid_), stack(stack_) { + addr_description = + AddressDescription(addr, /*shouldLockThreadRegistry=*/false); + scariness.Clear(); + } + void Print(); +}; + +#define FOR_EACH_ERROR_KIND_MEMBER_NAME_PAIR(macro) \ + macro(StackOverflow, stack_overflow) \ + macro(DeadlySignal, deadly_signal) \ + macro(DoubleFree, double_free) \ + macro(NewDeleteSizeMismatch, new_delete_size_mismatch) \ + macro(FreeNotMalloced, free_not_malloced) \ + macro(AllocTypeMismatch, alloc_type_mismatch) \ + macro(MallocUsableSizeNotOwned, malloc_usable_size_not_owned) \ + macro(SanitizerGetAllocatedSizeNotOwned, \ + sanitizer_get_allocated_size_not_owned) enum ErrorKind { kErrorKindInvalid = 0, Index: lib/asan/asan_errors.cc =================================================================== --- lib/asan/asan_errors.cc +++ lib/asan/asan_errors.cc @@ -177,4 +177,17 @@ ReportErrorSummary("bad-malloc_usable_size", stack); } +void ErrorSanitizerGetAllocatedSizeNotOwned::Print() { + Decorator d; + Printf("%s", d.Warning()); + Report( + "ERROR: AddressSanitizer: attempting to call " + "__sanitizer_get_allocated_size() for pointer which is not owned: %p\n", + addr_description.Address()); + Printf("%s", d.EndWarning()); + stack->Print(); + addr_description.Print(); + ReportErrorSummary("bad-__sanitizer_get_allocated_size", stack); +} + } // namespace __asan Index: lib/asan/asan_report.cc =================================================================== --- lib/asan/asan_report.cc +++ lib/asan/asan_report.cc @@ -372,15 +372,9 @@ void ReportSanitizerGetAllocatedSizeNotOwned(uptr addr, BufferedStackTrace *stack) { ScopedInErrorReport in_report; - Decorator d; - Printf("%s", d.Warning()); - Report("ERROR: AddressSanitizer: attempting to call " - "__sanitizer_get_allocated_size() for pointer which is " - "not owned: %p\n", addr); - Printf("%s", d.EndWarning()); - stack->Print(); - DescribeAddressIfHeap(addr); - ReportErrorSummary("bad-__sanitizer_get_allocated_size", stack); + ErrorSanitizerGetAllocatedSizeNotOwned error(addr, GetCurrentTidOrInvalid(), + stack); + in_report.ReportError(error); } void ReportStringFunctionMemoryRangesOverlap(const char *function,