blob: d49a06ff91ab18d181b1199bc2b3d71a4a8724ea [file] [log] [blame]
Alexey Samsonov00cd2732014-01-21 11:58:33 +00001// RUN: %clang_asan -O2 %s -o %t
Reid Kleckner7a211382016-03-11 19:11:15 +00002// RUN: %env_asan_opts=check_printf=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s
3// RUN: not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s
Alexey Samsonov00cd2732014-01-21 11:58:33 +00004
Reid Kleckner7a211382016-03-11 19:11:15 +00005// FIXME: sprintf is not intercepted on Windows yet.
Timur Iskhodzhanov7f291812014-05-28 13:06:14 +00006// XFAIL: win32
7
Alexey Samsonov00cd2732014-01-21 11:58:33 +00008#include <stdio.h>
9int main() {
10 volatile char c = '0';
11 volatile int x = 12;
12 volatile float f = 1.239;
13 volatile char s[] = "34";
14 volatile char buf[2];
Reid Kleckner7a211382016-03-11 19:11:15 +000015 puts("before sprintf");
Alexey Samsonov00cd2732014-01-21 11:58:33 +000016 sprintf((char *)buf, "%c %d %.3f %s\n", c, x, f, s);
Reid Kleckner7a211382016-03-11 19:11:15 +000017 puts("after sprintf");
Alexey Samsonov00cd2732014-01-21 11:58:33 +000018 puts((const char *)buf);
19 return 0;
20 // Check that size of output buffer is sanitized.
Reid Kleckner7a211382016-03-11 19:11:15 +000021 // CHECK-ON: before sprintf
22 // CHECK-ON-NOT: after sprintf
Alexey Samsonov00cd2732014-01-21 11:58:33 +000023 // CHECK-ON: stack-buffer-overflow
24 // CHECK-ON-NOT: 0 12 1.239 34
Alexey Samsonov00cd2732014-01-21 11:58:33 +000025}