1// RUN: %clang -fPIC -shared -O2 -D_FORTIFY_SOURCE=2 -D_DSO %s -o %t.so
2// RUN: %clang_asan -o %t %t.so %s
3// RUN: not %run %t 2>&1 | FileCheck %s
4// REQUIRES: glibc-2.27
5#ifdef _DSO
6#include <stdio.h>
7#include <stdlib.h>
8#include <string.h>
9__attribute__((noinline)) int foo() {
10 char *read_buffer = (char *)malloc(1);
11 // CHECK: AddressSanitizer: heap-buffer-overflow
12 fprintf(stderr, read_buffer, 4096);
13 return read_buffer[0];
14}
15#else
16extern int foo();
17int main() { return foo(); }
18#endif
19

source code of compiler-rt/test/asan/TestCases/Linux/printf-fortify-5.c