summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFilipe Cabecinhas <me@filcab.net>2016-09-13 20:47:42 +0000
committerFilipe Cabecinhas <me@filcab.net>2016-09-13 20:47:42 +0000
commitb0de43a673597631f222aae4a764d820562bdbfa (patch)
treec72bc7d88aed452238d8d4017905e1942e5775e0
parent5f862c20cbd504914533e1d51915372560f54511 (diff)
downloadbcm5719-llvm-b0de43a673597631f222aae4a764d820562bdbfa.tar.gz
bcm5719-llvm-b0de43a673597631f222aae4a764d820562bdbfa.zip
[asan] Reify ErrorSanitizerGetAllocatedSizeNotOwned
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/D24392 llvm-svn: 281392
-rw-r--r--compiler-rt/lib/asan/asan_errors.cc13
-rw-r--r--compiler-rt/lib/asan/asan_errors.h20
-rw-r--r--compiler-rt/lib/asan/asan_report.cc12
3 files changed, 35 insertions, 10 deletions
diff --git a/compiler-rt/lib/asan/asan_errors.cc b/compiler-rt/lib/asan/asan_errors.cc
index 6aeb5083a36..418a20012f3 100644
--- a/compiler-rt/lib/asan/asan_errors.cc
+++ b/compiler-rt/lib/asan/asan_errors.cc
@@ -177,4 +177,17 @@ void ErrorMallocUsableSizeNotOwned::Print() {
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
diff --git a/compiler-rt/lib/asan/asan_errors.h b/compiler-rt/lib/asan/asan_errors.h
index 4ee7c722c05..cac0cf82d26 100644
--- a/compiler-rt/lib/asan/asan_errors.h
+++ b/compiler-rt/lib/asan/asan_errors.h
@@ -176,6 +176,23 @@ struct ErrorMallocUsableSizeNotOwned : ErrorBase {
void Print();
};
+struct ErrorSanitizerGetAllocatedSizeNotOwned : ErrorBase {
+ // ErrorSanitizerGetAllocatedSizeNotOwned doesn't own the stack trace.
+ const BufferedStackTrace *stack;
+ AddressDescription addr_description;
+ // VS2013 doesn't implement unrestricted unions, so we need a trivial default
+ // constructor
+ ErrorSanitizerGetAllocatedSizeNotOwned() = default;
+ ErrorSanitizerGetAllocatedSizeNotOwned(u32 tid, BufferedStackTrace *stack_,
+ uptr addr)
+ : ErrorBase(tid),
+ stack(stack_),
+ addr_description(addr, /*shouldLockThreadRegistry=*/false) {
+ scariness.Clear();
+ }
+ void Print();
+};
+
// clang-format off
#define ASAN_FOR_EACH_ERROR_KIND(macro) \
macro(StackOverflow) \
@@ -184,7 +201,8 @@ struct ErrorMallocUsableSizeNotOwned : ErrorBase {
macro(NewDeleteSizeMismatch) \
macro(FreeNotMalloced) \
macro(AllocTypeMismatch) \
- macro(MallocUsableSizeNotOwned)
+ macro(MallocUsableSizeNotOwned) \
+ macro(SanitizerGetAllocatedSizeNotOwned)
// clang-format on
#define ASAN_DEFINE_ERROR_KIND(name) kErrorKind##name,
diff --git a/compiler-rt/lib/asan/asan_report.cc b/compiler-rt/lib/asan/asan_report.cc
index 8ae78ee1f4f..29ae230dcba 100644
--- a/compiler-rt/lib/asan/asan_report.cc
+++ b/compiler-rt/lib/asan/asan_report.cc
@@ -372,15 +372,9 @@ void ReportMallocUsableSizeNotOwned(uptr addr, BufferedStackTrace *stack) {
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(GetCurrentTidOrInvalid(), stack,
+ addr);
+ in_report.ReportError(error);
}
void ReportStringFunctionMemoryRangesOverlap(const char *function,
OpenPOWER on IntegriCloud