summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFilipe Cabecinhas <me@filcab.net>2016-08-31 07:38:09 +0000
committerFilipe Cabecinhas <me@filcab.net>2016-08-31 07:38:09 +0000
commitb16672d91d47737e813b073b544c4139fda3fe72 (patch)
treee18dfd972c824196a9a376237cbc48f3c6807092
parent2c07a069b8e72dd820117c010aa569d3d1a180dd (diff)
downloadbcm5719-llvm-b16672d91d47737e813b073b544c4139fda3fe72.tar.gz
bcm5719-llvm-b16672d91d47737e813b073b544c4139fda3fe72.zip
Reify ErrorDoubleFree
Summary: Keep reifying other errors. Reviewers: kcc, samsonov Subscribers: llvm-commits, kubabrecka Differential Revision: https://reviews.llvm.org/D23717 llvm-svn: 280201
-rw-r--r--compiler-rt/lib/asan/asan_errors.cc18
-rw-r--r--compiler-rt/lib/asan/asan_errors.h25
-rw-r--r--compiler-rt/lib/asan/asan_report.cc17
3 files changed, 45 insertions, 15 deletions
diff --git a/compiler-rt/lib/asan/asan_errors.cc b/compiler-rt/lib/asan/asan_errors.cc
index ea30c1cb219..b1ab07ee894 100644
--- a/compiler-rt/lib/asan/asan_errors.cc
+++ b/compiler-rt/lib/asan/asan_errors.cc
@@ -13,6 +13,7 @@
//===----------------------------------------------------------------------===//
#include "asan_errors.h"
+#include "asan_descriptions.h"
#include "asan_stack.h"
namespace __asan {
@@ -33,4 +34,21 @@ void ErrorStackOverflow::Print() {
ReportErrorSummary("stack-overflow", &stack);
}
+void ErrorDoubleFree::Print() {
+ Decorator d;
+ Printf("%s", d.Warning());
+ char tname[128];
+ Report(
+ "ERROR: AddressSanitizer: attempting double-free on %p in "
+ "thread T%d%s:\n",
+ addr_description.addr, tid,
+ ThreadNameWithParenthesis(tid, tname, sizeof(tname)));
+ Printf("%s", d.EndWarning());
+ GET_STACK_TRACE_FATAL(second_free_stack->trace[0],
+ second_free_stack->top_frame_bp);
+ stack.Print();
+ addr_description.Print();
+ ReportErrorSummary("double-free", &stack);
+}
+
} // namespace __asan
diff --git a/compiler-rt/lib/asan/asan_errors.h b/compiler-rt/lib/asan/asan_errors.h
index 87bc8690f6a..637bb44d22a 100644
--- a/compiler-rt/lib/asan/asan_errors.h
+++ b/compiler-rt/lib/asan/asan_errors.h
@@ -44,9 +44,27 @@ struct ErrorStackOverflow : ErrorBase {
void Print();
};
+struct ErrorDoubleFree : ErrorBase {
+ u32 tid;
+ HeapAddressDescription addr_description;
+ // ErrorDoubleFree doesn't own the stack trace.
+ BufferedStackTrace *second_free_stack;
+ // VS2013 doesn't implement unrestricted unions, so we need a trivial default
+ // constructor
+ ErrorDoubleFree() = default;
+ ErrorDoubleFree(uptr addr, u32 tid_, BufferedStackTrace *stack)
+ : tid(tid_), second_free_stack(stack) {
+ CHECK_GT(second_free_stack->size, 0);
+ GetHeapAddressInformation(addr, 1, &addr_description);
+ scariness.Scare(42, "double-free");
+ }
+ void Print();
+};
+
enum ErrorKind {
kErrorKindInvalid = 0,
kErrorKindStackOverflow,
+ kErrorKindDoubleFree,
};
struct ErrorDescription {
@@ -58,11 +76,15 @@ struct ErrorDescription {
// add a lot of code and the benefit wouldn't be that big.
union {
ErrorStackOverflow stack_overflow;
+ ErrorDoubleFree double_free;
};
ErrorDescription() { internal_memset(this, 0, sizeof(*this)); }
ErrorDescription(const ErrorStackOverflow &e) // NOLINT
: kind(kErrorKindStackOverflow),
stack_overflow(e) {}
+ ErrorDescription(const ErrorDoubleFree &e) // NOLINT
+ : kind(kErrorKindDoubleFree),
+ double_free(e) {}
bool IsValid() { return kind != kErrorKindInvalid; }
void Print() {
@@ -70,6 +92,9 @@ struct ErrorDescription {
case kErrorKindStackOverflow:
stack_overflow.Print();
return;
+ case kErrorKindDoubleFree:
+ double_free.Print();
+ return;
case kErrorKindInvalid:
CHECK(0);
}
diff --git a/compiler-rt/lib/asan/asan_report.cc b/compiler-rt/lib/asan/asan_report.cc
index c8395a5c25d..d4dfdc9b38f 100644
--- a/compiler-rt/lib/asan/asan_report.cc
+++ b/compiler-rt/lib/asan/asan_report.cc
@@ -388,21 +388,8 @@ void ReportDeadlySignal(const char *description, const SignalContext &sig) {
void ReportDoubleFree(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 double-free on %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(42, "double-free");
- GET_STACK_TRACE_FATAL(free_stack->trace[0], free_stack->top_frame_bp);
- stack.Print();
- DescribeAddressIfHeap(addr);
- ReportErrorSummary("double-free", &stack);
+ ErrorDoubleFree error{addr, GetCurrentTidOrInvalid(), free_stack}; // NOLINT
+ in_report.ReportError(error);
}
void ReportNewDeleteSizeMismatch(uptr addr, uptr alloc_size, uptr delete_size,
OpenPOWER on IntegriCloud