diff options
Diffstat (limited to 'gcc/testsuite/g++.dg/asan/deep-stack-uaf-1.C')
-rw-r--r-- | gcc/testsuite/g++.dg/asan/deep-stack-uaf-1.C | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/asan/deep-stack-uaf-1.C b/gcc/testsuite/g++.dg/asan/deep-stack-uaf-1.C new file mode 100644 index 0000000000..6ffec4c4c6 --- /dev/null +++ b/gcc/testsuite/g++.dg/asan/deep-stack-uaf-1.C @@ -0,0 +1,39 @@ +// Check that we can store lots of stack frames if asked to. + +// { dg-do run } +// { dg-skip-if "" { *-*-* } { "-flto" } { "" } } +// { dg-set-target-env-var ASAN_OPTIONS "malloc_context_size=120:redzone=512" } +// { dg-options "-fno-omit-frame-pointer -fno-optimize-sibling-calls" } +// { dg-additional-options "-mno-omit-leaf-frame-pointer" { target { i?86-*-* x86_64-*-* } } } +// { dg-shouldfail "asan" } + +#include <stdlib.h> +#include <stdio.h> + +template <int depth> +struct DeepFree { + static void __attribute__((noinline)) + free(char *x) { + DeepFree<depth - 1>::free(x); + } +}; + +template<> +struct DeepFree<0> { + static void __attribute__((noinline)) + free(char *x) { + ::free(x); + } +}; + +int main() { + char *x = (char*)malloc(10); + // deep_free(x); + DeepFree<200>::free(x); + return x[5]; +} + +// { dg-output "ERROR: AddressSanitizer:? heap-use-after-free on address.*(\n|\r\n|\r)" } +// { dg-output " #37 0x\[0-9a-f\]+ (in \[^\n\r]*DeepFree\[^\n\r]*36|\[(\]).*(\n|\r\n|\r)" } +// { dg-output " #99 0x\[0-9a-f\]+ (in \[^\n\r]*DeepFree\[^\n\r]*98|\[(\]).*(\n|\r\n|\r)" } +// { dg-output " #116 0x\[0-9a-f\]+ (in \[^\n\r]*DeepFree\[^\n\r]*115|\[(\])\[^\n\r]*(\n|\r\n|\r)" } |