diff --git a/compiler-rt/test/asan/TestCases/backtrace_interceptor.cpp b/compiler-rt/test/asan/TestCases/backtrace_interceptor.cpp new file mode 100644 --- /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 +#include +#include +#include +#include + +#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; +}