[PATCH] D24389: [asan] Reify ErrorFreeNotMalloced
Filipe Cabecinhas via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 9 06:35:29 PDT 2016
filcab created this revision.
filcab added reviewers: kcc, eugenis, vitalybuka.
filcab added a subscriber: llvm-commits.
Herald added a subscriber: kubabrecka.
Continuing implementation mentioned in this thread: http://lists.llvm.org/pipermail/llvm-dev/2016-July/101933.html
https://reviews.llvm.org/D24389
Files:
lib/asan/asan_errors.cc
lib/asan/asan_errors.h
lib/asan/asan_report.cc
Index: lib/asan/asan_report.cc
===================================================================
--- lib/asan/asan_report.cc
+++ lib/asan/asan_report.cc
@@ -350,20 +350,8 @@
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(addr, GetCurrentTidOrInvalid(), free_stack);
+ in_report.ReportError(error);
}
void ReportAllocTypeMismatch(uptr addr, BufferedStackTrace *free_stack,
Index: lib/asan/asan_errors.h
===================================================================
--- lib/asan/asan_errors.h
+++ lib/asan/asan_errors.h
@@ -123,11 +123,30 @@
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)
+struct ErrorFreeNotMalloced : ErrorBase {
+ u32 tid;
+ AddressDescriptionBase addr_description;
+ // ErrorFreeNotMalloced doesn't own the stack trace.
+ BufferedStackTrace *free_stack;
+ // VS2013 doesn't implement unrestricted unions, so we need a trivial default
+ // constructor
+ ErrorFreeNotMalloced() = default;
+ ErrorFreeNotMalloced(uptr addr, u32 tid_, BufferedStackTrace *stack)
+ : tid(tid_), free_stack(stack) {
+ addr_description =
+ AddressDescription(addr, /*shouldLockThreadRegistry=*/false);
+ scariness.Clear();
+ scariness.Scare(40, "bad-free");
+ }
+ 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)
enum ErrorKind {
kErrorKindInvalid = 0,
Index: lib/asan/asan_errors.cc
===================================================================
--- lib/asan/asan_errors.cc
+++ lib/asan/asan_errors.cc
@@ -123,4 +123,22 @@
"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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24389.70823.patch
Type: text/x-patch
Size: 3421 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160909/6808db0a/attachment.bin>
More information about the llvm-commits
mailing list