[NFC][Sanitizer] Add argument checks to BufferedStackTrace::Unwind* functions
authorJulian Lettner <jlettner@apple.com>
Sat, 23 Feb 2019 02:36:23 +0000 (02:36 +0000)
committerJulian Lettner <jlettner@apple.com>
Sat, 23 Feb 2019 02:36:23 +0000 (02:36 +0000)
Reviewers: vitalybuka

Differential Revision: https://reviews.llvm.org/D58555

llvm-svn: 354717

compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.cc
compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h
compiler-rt/lib/sanitizer_common/sanitizer_stacktrace_sparc.cc
compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_markup.cc
compiler-rt/lib/sanitizer_common/sanitizer_unwind_linux_libcdep.cc
compiler-rt/lib/sanitizer_common/sanitizer_unwind_win.cc

index 536ca65..3c55603 100644 (file)
@@ -70,8 +70,10 @@ static inline uhwptr *GetCanonicFrame(uptr bp,
 
 void BufferedStackTrace::UnwindFast(uptr pc, uptr bp, uptr stack_top,
                                     uptr stack_bottom, u32 max_depth) {
-  const uptr kPageSize = GetPageSizeCached();
+  CHECK_NE(stack_bottom, 0);
+  CHECK_GT(stack_top, stack_bottom);
   CHECK_GE(max_depth, 2);
+  const uptr kPageSize = GetPageSizeCached();
   trace_buffer[0] = pc;
   size = 1;
   if (stack_top < 4096) return;  // Sanity check for stack top.
index 4080e47..803f993 100644 (file)
@@ -56,9 +56,11 @@ struct StackTrace {
   void Print() const;
 
   static bool WillUseFastUnwind(bool request_fast_unwind) {
+    static_assert(SANITIZER_CAN_FAST_UNWIND || SANITIZER_CAN_SLOW_UNWIND,
+                  "Neither fast nor slow unwinder is supported");
     if (!SANITIZER_CAN_FAST_UNWIND)
       return false;
-    else if (!SANITIZER_CAN_SLOW_UNWIND)
+    if (!SANITIZER_CAN_SLOW_UNWIND)
       return true;
     return request_fast_unwind;
   }
index 4b0e10e..c3623e0 100644 (file)
@@ -23,8 +23,10 @@ namespace __sanitizer {
 
 void BufferedStackTrace::UnwindFast(uptr pc, uptr bp, uptr stack_top,
                                     uptr stack_bottom, u32 max_depth) {
-  const uptr kPageSize = GetPageSizeCached();
+  CHECK_NE(stack_bottom, 0);
+  CHECK_GT(stack_top, stack_bottom);
   CHECK_GE(max_depth, 2);
+  const uptr kPageSize = GetPageSizeCached();
   trace_buffer[0] = pc;
   size = 1;
   if (stack_top < 4096) return;  // Sanity check for stack top.
index 794d511..aee49b4 100644 (file)
@@ -132,9 +132,9 @@ void BufferedStackTrace::UnwindSlow(uptr pc, u32 max_depth) {
   trace_buffer[0] = pc;
 }
 
-void BufferedStackTrace::UnwindSlow(uptr pc, void *context,
-                                                    u32 max_depth) {
-  CHECK_NE(context, nullptr);
+void BufferedStackTrace::UnwindSlow(uptr pc, void *context, u32 max_depth) {
+  CHECK(context);
+  CHECK_GE(max_depth, 2);
   UNREACHABLE("signal context doesn't exist");
 }
 #endif  // SANITIZER_CAN_SLOW_UNWIND
index 26e3e61..f165605 100644 (file)
@@ -138,8 +138,8 @@ void BufferedStackTrace::UnwindSlow(uptr pc, u32 max_depth) {
   trace_buffer[0] = pc;
 }
 
-void BufferedStackTrace::UnwindSlow(uptr pc, void *context,
-                                                    u32 max_depth) {
+void BufferedStackTrace::UnwindSlow(uptr pc, void *context, u32 max_depth) {
+  CHECK(context);
   CHECK_GE(max_depth, 2);
   if (!unwind_backtrace_signal_arch) {
     UnwindSlow(pc, max_depth);
index b0dccf5..93908ab 100644 (file)
@@ -39,8 +39,9 @@ void BufferedStackTrace::UnwindSlow(uptr pc, u32 max_depth) {
   PopStackFrames(pc_location);
 }
 
-void BufferedStackTrace::UnwindSlow(uptr pc, void *context,
-  u32 max_depth) {
+void BufferedStackTrace::UnwindSlow(uptr pc, void *context, u32 max_depth) {
+  CHECK(context);
+  CHECK_GE(max_depth, 2);
   CONTEXT ctx = *(CONTEXT *)context;
   STACKFRAME64 stack_frame;
   memset(&stack_frame, 0, sizeof(stack_frame));