[compiler-rt] d3b5ac8 - ASan: add testcase for backtrace interceptor

Thurston Dang via llvm-commits llvm-commits at lists.llvm.org
Fri May 12 16:02:54 PDT 2023


Author: Thurston Dang
Date: 2023-05-12T23:02:19Z
New Revision: d3b5ac8b353cc555984d2e595a2636ba794e6eed

URL: https://github.com/llvm/llvm-project/commit/d3b5ac8b353cc555984d2e595a2636ba794e6eed
DIFF: https://github.com/llvm/llvm-project/commit/d3b5ac8b353cc555984d2e595a2636ba794e6eed.diff

LOG: 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

Added: 
    compiler-rt/test/asan/TestCases/backtrace_interceptor.cpp

Modified: 
    

Removed: 
    


################################################################################
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 0000000000000..8ffcc0894808b
--- /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;
+}


        


More information about the llvm-commits mailing list