summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorFilipe Cabecinhas <me@filcab.net>2016-09-13 20:47:29 +0000
committerFilipe Cabecinhas <me@filcab.net>2016-09-13 20:47:29 +0000
commit6f9e6ba0f776e778d17e9bd6aba559a49ff828e3 (patch)
treeb3ad41bbbc9e76da2665b2b30eba0e6443d2009a /lib
parentbd67606569192e2ed931b8e3e3415b02e2e4a803 (diff)
downloadcompiler-rt-6f9e6ba0f776e778d17e9bd6aba559a49ff828e3.tar.gz
[asan] Reify ErrorFreeNotMalloced
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/D24389 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@281389 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/asan/asan_errors.cc18
-rw-r--r--lib/asan/asan_errors.h20
-rw-r--r--lib/asan/asan_report.cc16
3 files changed, 39 insertions, 15 deletions
diff --git a/lib/asan/asan_errors.cc b/lib/asan/asan_errors.cc
index 30086f06f..aa3cb090e 100644
--- a/lib/asan/asan_errors.cc
+++ b/lib/asan/asan_errors.cc
@@ -123,4 +123,22 @@ void ErrorNewDeleteSizeMismatch::Print() {
"ASAN_OPTIONS=new_delete_type_mismatch=0\n");
}
+void ErrorFreeNotMalloced::Print() {
+ Decorator d;
+ Printf("%s", d.Warning());
+ char tname[128];
+ Report(
+ "ERROR: AddressSanitizer: attempting free on address "
+ "which was not malloc()-ed: %p in thread T%d%s\n",
+ addr_description.Address(), tid,
+ ThreadNameWithParenthesis(tid, tname, sizeof(tname)));
+ Printf("%s", d.EndWarning());
+ CHECK_GT(free_stack->size, 0);
+ scariness.Print();
+ GET_STACK_TRACE_FATAL(free_stack->trace[0], free_stack->top_frame_bp);
+ stack.Print();
+ addr_description.Print();
+ ReportErrorSummary("bad-free", &stack);
+}
+
} // namespace __asan
diff --git a/lib/asan/asan_errors.h b/lib/asan/asan_errors.h
index 862b6653c..1b1755329 100644
--- a/lib/asan/asan_errors.h
+++ b/lib/asan/asan_errors.h
@@ -122,12 +122,30 @@ struct ErrorNewDeleteSizeMismatch : ErrorBase {
void Print();
};
+struct ErrorFreeNotMalloced : ErrorBase {
+ // ErrorFreeNotMalloced doesn't own the stack trace.
+ const BufferedStackTrace *free_stack;
+ AddressDescription addr_description;
+ // VS2013 doesn't implement unrestricted unions, so we need a trivial default
+ // constructor
+ ErrorFreeNotMalloced() = default;
+ ErrorFreeNotMalloced(u32 tid, BufferedStackTrace *stack, uptr addr)
+ : ErrorBase(tid),
+ free_stack(stack),
+ addr_description(addr, /*shouldLockThreadRegistry=*/false) {
+ scariness.Clear();
+ scariness.Scare(40, "bad-free");
+ }
+ void Print();
+};
+
// clang-format off
#define ASAN_FOR_EACH_ERROR_KIND(macro) \
macro(StackOverflow) \
macro(DeadlySignal) \
macro(DoubleFree) \
- macro(NewDeleteSizeMismatch)
+ macro(NewDeleteSizeMismatch) \
+ macro(FreeNotMalloced)
// clang-format on
#define ASAN_DEFINE_ERROR_KIND(name) kErrorKind##name,
diff --git a/lib/asan/asan_report.cc b/lib/asan/asan_report.cc
index 92214df6c..2dc3c48f7 100644
--- a/lib/asan/asan_report.cc
+++ b/lib/asan/asan_report.cc
@@ -350,20 +350,8 @@ void ReportNewDeleteSizeMismatch(uptr addr, uptr delete_size,
void ReportFreeNotMalloced(uptr addr, BufferedStackTrace *free_stack) {
ScopedInErrorReport in_report;
- Decorator d;
- Printf("%s", d.Warning());
- char tname[128];
- u32 curr_tid = GetCurrentTidOrInvalid();
- Report("ERROR: AddressSanitizer: attempting free on address "
- "which was not malloc()-ed: %p in thread T%d%s\n", addr,
- curr_tid, ThreadNameWithParenthesis(curr_tid, tname, sizeof(tname)));
- Printf("%s", d.EndWarning());
- CHECK_GT(free_stack->size, 0);
- ScarinessScore::PrintSimple(40, "bad-free");
- GET_STACK_TRACE_FATAL(free_stack->trace[0], free_stack->top_frame_bp);
- stack.Print();
- DescribeAddressIfHeap(addr);
- ReportErrorSummary("bad-free", &stack);
+ ErrorFreeNotMalloced error(GetCurrentTidOrInvalid(), free_stack, addr);
+ in_report.ReportError(error);
}
void ReportAllocTypeMismatch(uptr addr, BufferedStackTrace *free_stack,