From e0b68f7149f9c66ba9e81878729225421f99a030 Mon Sep 17 00:00:00 2001 From: Florian Mayer Date: Fri, 18 Jun 2021 12:55:40 +0100 Subject: [PATCH] [hwasan] Clarify report for allocation-tail-overwritten. Explain what the given stack trace means before showing it, rather than only in the paragraph at the end. Reviewed By: eugenis Differential Revision: https://reviews.llvm.org/D104523 --- compiler-rt/lib/hwasan/hwasan_report.cpp | 6 ++++++ compiler-rt/test/hwasan/TestCases/tail-magic.c | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/compiler-rt/lib/hwasan/hwasan_report.cpp b/compiler-rt/lib/hwasan/hwasan_report.cpp index 7b2a85b4f6bc..b39dade11347 100644 --- a/compiler-rt/lib/hwasan/hwasan_report.cpp +++ b/compiler-rt/lib/hwasan/hwasan_report.cpp @@ -547,6 +547,12 @@ void ReportTailOverwritten(StackTrace *stack, uptr tagged_addr, uptr orig_size, Report("ERROR: %s: %s; heap object [%p,%p) of size %zd\n", SanitizerToolName, bug_type, untagged_addr, untagged_addr + orig_size, orig_size); Printf("\n%s", d.Default()); + Printf( + "Stack of invalid access unknown. Issue detected at deallocation " + "time.\n"); + Printf("%s", d.Allocation()); + Printf("deallocated here:\n"); + Printf("%s", d.Default()); stack->Print(); HwasanChunkView chunk = FindHeapChunkByAddress(untagged_addr); if (chunk.Beg()) { diff --git a/compiler-rt/test/hwasan/TestCases/tail-magic.c b/compiler-rt/test/hwasan/TestCases/tail-magic.c index acce591a7ac9..fcbc8f115d73 100644 --- a/compiler-rt/test/hwasan/TestCases/tail-magic.c +++ b/compiler-rt/test/hwasan/TestCases/tail-magic.c @@ -27,8 +27,10 @@ int main(int argc, char **argv) { overwrite_tail(); free(p); // CHECK: ERROR: HWAddressSanitizer: allocation-tail-overwritten; heap object [{{.*}}) of size 20 -// CHECK: in main {{.*}}tail-magic.c:[[@LINE-2]] +// CHECK: Stack of invalid access unknown. Issue detected at deallocation time. +// CHECK: deallocated here: +// CHECK: in main {{.*}}tail-magic.c:[[@LINE-4]] // CHECK: allocated here: -// CHECK: in main {{.*}}tail-magic.c:[[@LINE-7]] +// CHECK: in main {{.*}}tail-magic.c:[[@LINE-9]] // CHECK: Tail contains: .. .. .. .. 42 {{.. .. ..}} 66 }