Files
clang-p2996/compiler-rt/test/asan/TestCases/Linux/printf-fortify-3.c
Maxim Ostapenko de74bdb3d2 [asan] Add interceptor for printf_chk
There could be a situation when a specific DSO was built with FORTIFY_SOURCE option. In case asan-ed binary link against that DSO,
libasan can't handle the possible memory error because it does not have interceptors for spinrtf_chk, snprintf_chk, vprintf_chk,
vsnprintf_chk, __fprintf_chk functions. Let's interceptors for them.

Patch by Denis Khalikov.

Differential Revision: https://reviews.llvm.org/D40951

llvm-svn: 320990
2017-12-18 15:31:26 +00:00

23 lines
639 B
C

// RUN: %clang -shared -fPIC -D_DSO -O2 -D_FORTIFY_SOURCE=2 %s -o %t.so
// RUN: %clang_asan %s -o %t %t.so
// RUN: not %run %t 2>&1 | FileCheck %s
// UNSUPPORTED: android
#ifdef _DSO
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
__attribute__((noinline)) char foo(const char *format, ...) {
char *write_buffer = (char *)malloc(1);
va_list ap;
va_start(ap, format);
// CHECK: AddressSanitizer: heap-buffer-overflow
vsprintf(write_buffer, format, ap);
va_end(ap);
return write_buffer[0];
}
#else
extern int foo(const char *format, ...);
int main() { return foo("%s_%s", "one", "two"); }
#endif