Files
clang-p2996/compiler-rt/test/asan/TestCases/deep_stack_uaf.cpp
Charlie Barto 0360f3218a [asan][windows] Make tests more flexable (#85274)
Contains test changes from
https://github.com/llvm/llvm-project/pull/81677 that are simple test
changes. For the most part just makes the tests allow more flexibility
in the callstacks produced by asan.

Note: this PR has the exact changes from
https://github.com/llvm/llvm-project/pull/81677 in addition to a revert
commit to remove the ones that require other things from that PR. This
will be squashed, ofc. I just left things unsquashed for reviewing
pleasure :).

This is a non-functional-change
2024-03-15 10:42:21 -07:00

36 lines
969 B
C++

// 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=125: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>}}
}