[PATCH] D24391: [asan] Reify ErrorMallocUsableSizeNotOwned

Filipe Cabecinhas via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 9 06:36:30 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/D24391

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
@@ -365,15 +365,8 @@
 
 void ReportMallocUsableSizeNotOwned(uptr addr, BufferedStackTrace *stack) {
   ScopedInErrorReport in_report;
-  Decorator d;
-  Printf("%s", d.Warning());
-  Report("ERROR: AddressSanitizer: attempting to call "
-             "malloc_usable_size() for pointer which is "
-             "not owned: %p\n", addr);
-  Printf("%s", d.EndWarning());
-  stack->Print();
-  DescribeAddressIfHeap(addr);
-  ReportErrorSummary("bad-malloc_usable_size", stack);
+  ErrorMallocUsableSizeNotOwned error(addr, GetCurrentTidOrInvalid(), stack);
+  in_report.ReportError(error);
 }
 
 void ReportSanitizerGetAllocatedSizeNotOwned(uptr addr,
Index: lib/asan/asan_errors.h
===================================================================
--- lib/asan/asan_errors.h
+++ lib/asan/asan_errors.h
@@ -163,13 +163,31 @@
   void Print();
 };
 
+struct ErrorMallocUsableSizeNotOwned : ErrorBase {
+  u32 tid;
+  // ErrorMallocUsableSizeNotOwned doesn't own the stack trace.
+  BufferedStackTrace *stack;
+  AddressDescriptionBase addr_description;
+  // VS2013 doesn't implement unrestricted unions, so we need a trivial default
+  // constructor
+  ErrorMallocUsableSizeNotOwned() = default;
+  ErrorMallocUsableSizeNotOwned(uptr addr, u32 tid_, BufferedStackTrace *stack_)
+      : tid(tid_), stack(stack_) {
+    addr_description =
+        AddressDescription(addr, /*shouldLockThreadRegistry=*/false);
+    scariness.Clear();
+  }
+  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)              \
-  macro(AllocTypeMismatch, alloc_type_mismatch)
+  macro(AllocTypeMismatch, alloc_type_mismatch)          \
+  macro(MallocUsableSizeNotOwned, malloc_uzable_size_not_owned)
 
 enum ErrorKind {
   kErrorKindInvalid = 0,
Index: lib/asan/asan_errors.cc
===================================================================
--- lib/asan/asan_errors.cc
+++ lib/asan/asan_errors.cc
@@ -164,4 +164,17 @@
       "ASAN_OPTIONS=alloc_dealloc_mismatch=0\n");
 }
 
+void ErrorMallocUsableSizeNotOwned::Print() {
+  Decorator d;
+  Printf("%s", d.Warning());
+  Report(
+      "ERROR: AddressSanitizer: attempting to call malloc_usable_size() for "
+      "pointer which is not owned: %p\n",
+      addr_description.Address());
+  Printf("%s", d.EndWarning());
+  stack->Print();
+  addr_description.Print();
+  ReportErrorSummary("bad-malloc_usable_size", stack);
+}
+
 }  // namespace __asan


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24391.70825.patch
Type: text/x-patch
Size: 2855 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160909/e27f8243/attachment.bin>


More information about the llvm-commits mailing list