summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Samsonov <samsonov@google.com>2013-11-05 23:29:12 +0000
committerAlexey Samsonov <samsonov@google.com>2013-11-05 23:29:12 +0000
commit4b9f050c2acab536356342ab96e6cc76c281ac24 (patch)
tree555a6b13e1541e05d0937598b30ccab3724d2b4d
parent4197fa23ada9682343a15b68dde08c0249db172a (diff)
downloadcompiler-rt-4b9f050c2acab536356342ab96e6cc76c281ac24.tar.gz
compiler-rt-4b9f050c2acab536356342ab96e6cc76c281ac24.tar.bz2
compiler-rt-4b9f050c2acab536356342ab96e6cc76c281ac24.tar.xz
[ASan] Make sure slow stack unwinder doesn't return empty stacks.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@194107 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/asan/lit_tests/TestCases/malloc_context_size.cc19
-rw-r--r--lib/sanitizer_common/sanitizer_linux_libcdep.cc26
2 files changed, 32 insertions, 13 deletions
diff --git a/lib/asan/lit_tests/TestCases/malloc_context_size.cc b/lib/asan/lit_tests/TestCases/malloc_context_size.cc
new file mode 100644
index 00000000..7449dbe2
--- /dev/null
+++ b/lib/asan/lit_tests/TestCases/malloc_context_size.cc
@@ -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
+}
diff --git a/lib/sanitizer_common/sanitizer_linux_libcdep.cc b/lib/sanitizer_common/sanitizer_linux_libcdep.cc
index 0bc38880..d415279d 100644
--- a/lib/sanitizer_common/sanitizer_linux_libcdep.cc
+++ b/lib/sanitizer_common/sanitizer_linux_libcdep.cc
@@ -160,19 +160,19 @@ static bool MatchPc(uptr cur_pc, uptr trace_pc) {
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;
}