[PATCH] D24394: [asan] Reify ErrorStringFunctionSizeOverflow

Filipe Cabecinhas via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 13 07:50:10 PDT 2016


filcab updated this revision to Diff 71172.
filcab added a comment.

Updating after https://reviews.llvm.org/D23875 (consistency on constructor args and member order)

Vitaly: I know you approved most of these, but you also said we should revisit them after https://reviews.llvm.org/D23875 lands. Let me know if they're ok to commit or if you still want changes.


https://reviews.llvm.org/D24394

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
@@ -391,15 +391,9 @@
 void ReportStringFunctionSizeOverflow(uptr offset, uptr size,
                                       BufferedStackTrace *stack) {
   ScopedInErrorReport in_report;
-  Decorator d;
-  const char *bug_type = "negative-size-param";
-  Printf("%s", d.Warning());
-  Report("ERROR: AddressSanitizer: %s: (size=%zd)\n", bug_type, size);
-  Printf("%s", d.EndWarning());
-  ScarinessScore::PrintSimple(10, bug_type);
-  stack->Print();
-  PrintAddressDescription(offset, size, bug_type);
-  ReportErrorSummary(bug_type, stack);
+  ErrorStringFunctionSizeOverflow error(GetCurrentTidOrInvalid(), stack, offset,
+                                        size);
+  in_report.ReportError(error);
 }
 
 void ReportBadParamsToAnnotateContiguousContainer(uptr beg, uptr end,
Index: lib/asan/asan_errors.h
===================================================================
--- lib/asan/asan_errors.h
+++ lib/asan/asan_errors.h
@@ -221,6 +221,26 @@
   void Print();
 };
 
+struct ErrorStringFunctionSizeOverflow : ErrorBase {
+  // ErrorStringFunctionSizeOverflow doesn't own the stack trace.
+  const BufferedStackTrace *stack;
+  AddressDescription addr_description;
+  uptr size;
+  // VS2013 doesn't implement unrestricted unions, so we need a trivial default
+  // constructor
+  ErrorStringFunctionSizeOverflow() = default;
+  ErrorStringFunctionSizeOverflow(u32 tid, BufferedStackTrace *stack_,
+                                  uptr addr, uptr size_)
+      : ErrorBase(tid),
+        stack(stack_),
+        addr_description(addr, /*shouldLockThreadRegistry=*/false),
+        size(size_) {
+    scariness.Clear();
+    scariness.Scare(10, "negative-size-param");
+  }
+  void Print();
+};
+
 // clang-format off
 #define ASAN_FOR_EACH_ERROR_KIND(macro)    \
   macro(StackOverflow)                     \
@@ -231,7 +251,8 @@
   macro(AllocTypeMismatch)                 \
   macro(MallocUsableSizeNotOwned)          \
   macro(SanitizerGetAllocatedSizeNotOwned) \
-  macro(StringFunctionMemoryRangesOverlap)
+  macro(StringFunctionMemoryRangesOverlap) \
+  macro(StringFunctionSizeOverflow)
 // clang-format on
 
 #define ASAN_DEFINE_ERROR_KIND(name) kErrorKind##name,
Index: lib/asan/asan_errors.cc
===================================================================
--- lib/asan/asan_errors.cc
+++ lib/asan/asan_errors.cc
@@ -209,4 +209,16 @@
   ReportErrorSummary(bug_type, stack);
 }
 
+void ErrorStringFunctionSizeOverflow::Print() {
+  Decorator d;
+  Printf("%s", d.Warning());
+  const char *bug_type = "negative-size-param";
+  Report("ERROR: AddressSanitizer: %s: (size=%zd)\n", bug_type, size);
+  Printf("%s", d.EndWarning());
+  scariness.Print();
+  stack->Print();
+  addr_description.Print();
+  ReportErrorSummary(bug_type, stack);
+}
+
 }  // namespace __asan


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24394.71172.patch
Type: text/x-patch
Size: 2948 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160913/a5a662f4/attachment.bin>


More information about the llvm-commits mailing list