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
--- /dev/null
+// 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;
+}