diff options
author | Thurston Dang <thurston@google.com> | 2023-05-12 22:47:54 +0000 |
---|---|---|
committer | Thurston Dang <thurston@google.com> | 2023-05-12 23:02:19 +0000 |
commit | d3b5ac8b353cc555984d2e595a2636ba794e6eed (patch) | |
tree | 11fadb04d6980bd877fab2825d4b004fef7e7973 /compiler-rt | |
parent | 6adb9a0602bcd75acd383e13c253e471edc9b189 (diff) | |
download | llvm-d3b5ac8b353cc555984d2e595a2636ba794e6eed.tar.gz |
ASan: add testcase for backtrace interceptor
It is a known, longstanding issue that some ASan interceptors
may write to freed memory, causing corruption
(https://github.com/google/sanitizers/issues/321). This patch
adds a testcase for the backtrace interceptor (one of the
known cases).
Reviewed By: vitalybuka
Differential Revision: https://reviews.llvm.org/D150491
Diffstat (limited to 'compiler-rt')
-rw-r--r-- | compiler-rt/test/asan/TestCases/backtrace_interceptor.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/compiler-rt/test/asan/TestCases/backtrace_interceptor.cpp b/compiler-rt/test/asan/TestCases/backtrace_interceptor.cpp new file mode 100644 index 000000000000..8ffcc0894808 --- /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 <assert.h> +#include <execinfo.h> +#include <math.h> +#include <stdio.h> +#include <stdlib.h> + +#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; +} |