]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/asan/TestCases/deep_stack_uaf.cc
Vendor import of compiler-rt trunk r256633:
[FreeBSD/FreeBSD.git] / test / asan / TestCases / deep_stack_uaf.cc
1 // Check that we can store lots of stack frames if asked to.
2
3 // RUN: %clangxx_asan -O0 %s -o %t 2>&1
4 // RUN: %env_asan_opts=malloc_context_size=120:redzone=512 not %run %t 2>&1 | FileCheck %s
5 // XFAIL: arm-linux-gnueabi
6 // XFAIL: armv7l-unknown-linux-gnueabihf
7 #include <stdlib.h>
8 #include <stdio.h>
9
10 template <int depth>
11 struct DeepFree {
12   static void free(char *x) {
13     DeepFree<depth - 1>::free(x);
14   }
15 };
16
17 template<>
18 struct DeepFree<0> {
19   static void free(char *x) {
20     ::free(x);
21   }
22 };
23
24 int main() {
25   char *x = (char*)malloc(10);
26   // deep_free(x);
27   DeepFree<200>::free(x);
28   return x[5];
29   // CHECK: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}}
30   // The libcxxrt demangling procedure on FreeBSD 9.2 incorrectly appends
31   // extra 'E' characters to the end of template arguments; see:
32   // https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=192115
33   // CHECK: {{DeepFree<36>|DeepFree<36E>}}
34   // CHECK: {{DeepFree<98>|DeepFree<98E>}}
35   // CHECK: {{DeepFree<115>|DeepFree<115E>}}
36 }