Skip to content

Commit

Permalink
ASan: add testcase for backtrace interceptor
Browse files Browse the repository at this point in the history
It is a known, longstanding issue that some ASan interceptors
may write to freed memory, causing corruption
(google/sanitizers#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
  • Loading branch information
thurstond committed May 12, 2023
1 parent 6adb9a0 commit d3b5ac8
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions compiler-rt/test/asan/TestCases/backtrace_interceptor.cpp
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit d3b5ac8

Please sign in to comment.