blob: d4e2a0ab9ccefba12566620e0abbeb663e8c470b [file] [log] [blame]
Stephen Hines2d1fdb22014-05-28 23:58:16 -07001// RUN: %clang_asan -O2 %s -o %t
2// We need replace_intrin=0 to avoid reporting errors in memcpy.
Pirama Arumuga Nainarcdce50b2015-07-01 12:26:56 -07003// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:replace_intrin=0:check_printf=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s
4// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:replace_intrin=0:check_printf=0 %run %t 2>&1 | FileCheck --check-prefix=CHECK-OFF %s
5// RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:replace_intrin=0 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s
Stephen Hines2d1fdb22014-05-28 23:58:16 -07006
Stephen Hines6a211c52014-07-21 00:49:56 -07007// FIXME: printf is not intercepted on Windows yet.
8// XFAIL: win32
9
Stephen Hines2d1fdb22014-05-28 23:58:16 -070010#include <stdio.h>
11#include <string.h>
12int main() {
13 volatile char c = '0';
14 volatile int x = 12;
15 volatile float f = 1.239;
16 volatile char s[] = "34";
17 volatile char fmt[2];
18 memcpy((char *)fmt, "%c %d %f %s\n", sizeof(fmt));
19 printf((char *)fmt, c, x, f, s);
20 return 0;
21 // Check that format string is sanitized.
22 // CHECK-ON: stack-buffer-overflow
23 // CHECK-ON-NOT: 0 12 1.239 34
24 // CHECK-OFF: 0
25}