summaryrefslogtreecommitdiff
path: root/test/asan/TestCases/Linux/printf-fortify-1.c
blob: 2e0c70c1e648517c074ae085c23c0468e2a242fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// RUN: %clang -fPIC -shared -O2 -D_FORTIFY_SOURCE=2 -D_DSO %s -o %t.so
// RUN: %clang_asan -o %t %t.so %s
// RUN: not %run %t 2>&1 | FileCheck %s
// UNSUPPORTED: android
#ifdef _DSO
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
__attribute__((noinline)) int foo() {
  char *write_buffer = (char *)malloc(1);
  // CHECK: AddressSanitizer: heap-buffer-overflow
  sprintf(write_buffer, "%s_%s", "one", "two");
  return write_buffer[0];
}
#else
extern int foo();
int main() { return foo(); }
#endif