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/// Incompatible with pass_object_info style fortified source since glibc 2.40.
5// REQUIRES: glibc-2.27 && !glibc-2.40
6#ifdef _DSO
7#include <stdio.h>
8#include <stdlib.h>
9#include <string.h>
10__attribute__((noinline)) int foo() {
11 char *read_buffer = (char *)malloc(1);
12 // CHECK: AddressSanitizer: heap-buffer-overflow
13 fprintf(stderr, read_buffer, 4096);
14 return read_buffer[0];
15}
16#else
17extern int foo();
18int main() { return foo(); }
19#endif
20

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