]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/asan/TestCases/Linux/printf-fortify-2.c
Vendor import of compiler-rt trunk r351319 (just before the release_80
[FreeBSD/FreeBSD.git] / test / asan / TestCases / Linux / printf-fortify-2.c
1 // RUN: %clang -fPIC -shared -O2 -D_FORTIFY_SOURCE=2 -D_DSO %s -o %t.so
2 // RUN: %clang_asan %s -o %t %t.so
3 // RUN: not %run %t 2>&1 | FileCheck %s
4 // UNSUPPORTED: android
5 #ifdef _DSO
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 __attribute__((noinline)) int foo() {
10   char *write_buffer = (char *)malloc(1);
11   // CHECK: AddressSanitizer: heap-buffer-overflow
12   snprintf(write_buffer, 4096, "%s_%s", "one", "two");
13   return write_buffer[0];
14 }
15 #else
16 extern int foo();
17 int main() { return foo(); }
18 #endif