summaryrefslogtreecommitdiff
path: root/test/asan/TestCases/deep_stack_uaf.cpp
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2019-08-05 16:48:12 +0000
committerNico Weber <nicolasweber@gmx.de>2019-08-05 16:48:12 +0000
commit2f91f4f955190c500ab3a1ec4b92ad3f3af72724 (patch)
tree14f3bb241fe04d56481582cad0dcb00f3dc1a01e /test/asan/TestCases/deep_stack_uaf.cpp
parent9b46f1e9a77b1faa2e9869b9b886f05ac5d39411 (diff)
downloadcompiler-rt-2f91f4f955190c500ab3a1ec4b92ad3f3af72724.tar.gz
compiler-rt: Rename cc files below test/asan to cpp
See r367803 and similar other changes. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@367887 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/asan/TestCases/deep_stack_uaf.cpp')
-rw-r--r--test/asan/TestCases/deep_stack_uaf.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/test/asan/TestCases/deep_stack_uaf.cpp b/test/asan/TestCases/deep_stack_uaf.cpp
new file mode 100644
index 000000000..bdf0dbdb4
--- /dev/null
+++ b/test/asan/TestCases/deep_stack_uaf.cpp
@@ -0,0 +1,35 @@
+// Check that we can store lots of stack frames if asked to.
+
+// RUN: %clangxx_asan -O0 %s -o %t 2>&1
+// RUN: %env_asan_opts=malloc_context_size=120:redzone=512 not %run %t 2>&1 | FileCheck %s
+// REQUIRES: stable-runtime
+#include <stdlib.h>
+#include <stdio.h>
+
+template <int depth>
+struct DeepFree {
+ static void free(char *x) {
+ DeepFree<depth - 1>::free(x);
+ }
+};
+
+template<>
+struct DeepFree<0> {
+ static void free(char *x) {
+ ::free(x);
+ }
+};
+
+int main() {
+ char *x = (char*)malloc(10);
+ // deep_free(x);
+ DeepFree<200>::free(x);
+ return x[5];
+ // CHECK: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}}
+ // The libcxxrt demangling procedure on FreeBSD 9.2 incorrectly appends
+ // extra 'E' characters to the end of template arguments; see:
+ // https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=192115
+ // CHECK: {{DeepFree<36>|DeepFree<36E>}}
+ // CHECK: {{DeepFree<98>|DeepFree<98E>}}
+ // CHECK: {{DeepFree<115>|DeepFree<115E>}}
+}