[compiler-rt] r194107 - [ASan] Make sure slow stack unwinder doesn't return empty stacks.

Alexey Samsonov samsonov at google.com
Tue Nov 5 15:29:12 PST 2013


Author: samsonov
Date: Tue Nov  5 17:29:12 2013
New Revision: 194107

URL: http://llvm.org/viewvc/llvm-project?rev=194107&view=rev
Log:
[ASan] Make sure slow stack unwinder doesn't return empty stacks.

Added:
    compiler-rt/trunk/lib/asan/lit_tests/TestCases/malloc_context_size.cc
Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc

Added: compiler-rt/trunk/lib/asan/lit_tests/TestCases/malloc_context_size.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/TestCases/malloc_context_size.cc?rev=194107&view=auto
==============================================================================
--- compiler-rt/trunk/lib/asan/lit_tests/TestCases/malloc_context_size.cc (added)
+++ compiler-rt/trunk/lib/asan/lit_tests/TestCases/malloc_context_size.cc Tue Nov  5 17:29:12 2013
@@ -0,0 +1,19 @@
+// RUN: %clangxx_asan -O0 %s -o %t
+// RUN: ASAN_OPTIONS=malloc_context_size=0:fast_unwind_on_malloc=0 not %t 2>&1 | FileCheck %s
+// RUN: ASAN_OPTIONS=malloc_context_size=0:fast_unwind_on_malloc=1 not %t 2>&1 | FileCheck %s
+// RUN: ASAN_OPTIONS=malloc_context_size=1:fast_unwind_on_malloc=0 not %t 2>&1 | FileCheck %s
+// RUN: ASAN_OPTIONS=malloc_context_size=1:fast_unwind_on_malloc=1 not %t 2>&1 | FileCheck %s
+
+int main() {
+  char *x = new char[20];
+  delete[] x;
+  return x[0];
+  // CHECK: freed by thread T{{.*}} here:
+  // CHECK-NEXT: #0 0x{{.*}} in operator delete[]
+  // CHECK-NOT: #1 0x{{.*}}
+  // CHECK: previously allocated by thread T{{.*}} here:
+  // CHECK-NEXT: #0 0x{{.*}} in operator new[]
+  // CHECK-NOT: #1 0x{{.*}}
+
+  // CHECK: SUMMARY: AddressSanitizer: heap-use-after-free
+}

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc?rev=194107&r1=194106&r2=194107&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_linux_libcdep.cc Tue Nov  5 17:29:12 2013
@@ -160,19 +160,19 @@ static bool MatchPc(uptr cur_pc, uptr tr
 
 void StackTrace::SlowUnwindStack(uptr pc, uptr max_depth) {
   size = 0;
-  UnwindTraceArg arg = {this, max_depth};
-  if (max_depth > 1) {
-    _Unwind_Backtrace(Unwind_Trace, &arg);
-    // We need to pop a few frames so that pc is on top.
-    // trace[0] belongs to the current function so we always pop it.
-    int to_pop = 1;
-    /**/ if (size > 1 && MatchPc(pc, trace[1])) to_pop = 1;
-    else if (size > 2 && MatchPc(pc, trace[2])) to_pop = 2;
-    else if (size > 3 && MatchPc(pc, trace[3])) to_pop = 3;
-    else if (size > 4 && MatchPc(pc, trace[4])) to_pop = 4;
-    else if (size > 5 && MatchPc(pc, trace[5])) to_pop = 5;
-    PopStackFrames(to_pop);
-  }
+  if (max_depth == 0)
+    return;
+  UnwindTraceArg arg = {this, Min(max_depth + 1, kStackTraceMax)};
+  _Unwind_Backtrace(Unwind_Trace, &arg);
+  // We need to pop a few frames so that pc is on top.
+  // trace[0] belongs to the current function so we always pop it.
+  int to_pop = 1;
+  /**/ if (size > 1 && MatchPc(pc, trace[1])) to_pop = 1;
+  else if (size > 2 && MatchPc(pc, trace[2])) to_pop = 2;
+  else if (size > 3 && MatchPc(pc, trace[3])) to_pop = 3;
+  else if (size > 4 && MatchPc(pc, trace[4])) to_pop = 4;
+  else if (size > 5 && MatchPc(pc, trace[5])) to_pop = 5;
+  PopStackFrames(to_pop);
   trace[0] = pc;
 }
 





More information about the llvm-commits mailing list