blob: 2af81b0efa15bd8687c4822253cfc1b322a481bd [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
Peter Collingbourne7b17c9d2018-04-20 19:07:35 +00005// FIXME: sprintf is not intercepted on Windows yet. But this test can
6// pass if sprintf calls memmove, which is intercepted, so we can't XFAIL it.
Petr Hosekeb46c952018-08-09 02:16:18 +00007// UNSUPPORTED: windows-msvc
Timur Iskhodzhanov7f291812014-05-28 13:06:14 +00008
Alexey Samsonov00cd2732014-01-21 11:58:33 +00009#include <stdio.h>
10int main() {
11 volatile char c = '0';
12 volatile int x = 12;
13 volatile float f = 1.239;
14 volatile char s[] = "34";
15 volatile char buf[2];
Reid Kleckner60e53cd2016-03-11 21:07:48 +000016 fputs("before sprintf\n", stderr);
Alexey Samsonov00cd2732014-01-21 11:58:33 +000017 sprintf((char *)buf, "%c %d %.3f %s\n", c, x, f, s);
Reid Kleckner60e53cd2016-03-11 21:07:48 +000018 fputs("after sprintf", stderr);
19 fputs((const char *)buf, stderr);
Alexey Samsonov00cd2732014-01-21 11:58:33 +000020 return 0;
21 // Check that size of output buffer is sanitized.
Reid Kleckner7a211382016-03-11 19:11:15 +000022 // CHECK-ON: before sprintf
23 // CHECK-ON-NOT: after sprintf
Alexey Samsonov00cd2732014-01-21 11:58:33 +000024 // CHECK-ON: stack-buffer-overflow
25 // CHECK-ON-NOT: 0 12 1.239 34
Alexey Samsonov00cd2732014-01-21 11:58:33 +000026}