summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compiler-rt/test/asan/TestCases/backtrace_interceptor.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/compiler-rt/test/asan/TestCases/backtrace_interceptor.cpp b/compiler-rt/test/asan/TestCases/backtrace_interceptor.cpp
new file mode 100644
index 000000000000..8ffcc0894808
--- /dev/null
+++ b/compiler-rt/test/asan/TestCases/backtrace_interceptor.cpp
@@ -0,0 +1,28 @@
+// RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
+
+// Interceptor can cause use-after-free
+// (https://github.com/google/sanitizers/issues/321)
+// XFAIL: *
+
+// Test the backtrace() interceptor.
+
+#include <assert.h>
+#include <execinfo.h>
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#define MAX_BT 100
+
+int main() {
+ void **buffer = (void **)malloc(sizeof(void *) * MAX_BT);
+ assert(buffer != NULL);
+ free(buffer);
+
+ int numEntries = backtrace(buffer, MAX_BT);
+ printf("backtrace returned %d entries\n", numEntries);
+
+ // CHECK: use-after-free
+ // CHECK: SUMMARY
+ return 0;
+}