Home | History | Annotate | Download | only in TestCases
      1 // RUN: %clang_asan -O2 %s -o %t
      2 // 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
      4 
      5 // FIXME: sprintf is not intercepted on Windows yet.
      6 // XFAIL: win32
      7 
      8 #include <stdio.h>
      9 int 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];
     15   fputs("before sprintf\n", stderr);
     16   sprintf((char *)buf, "%c %d %.3f %s\n", c, x, f, s);
     17   fputs("after sprintf", stderr);
     18   fputs((const char *)buf, stderr);
     19   return 0;
     20   // Check that size of output buffer is sanitized.
     21   // CHECK-ON: before sprintf
     22   // CHECK-ON-NOT: after sprintf
     23   // CHECK-ON: stack-buffer-overflow
     24   // CHECK-ON-NOT: 0 12 1.239 34
     25 }
     26