| 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: %env_asan_opts=check_printf=0 %run %t 2>&1 | FileCheck --check-prefix=CHECK-OFF %s |
| 4 | // RUN: not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s |
| 5 | |
| 6 | // FIXME: printf is not intercepted on Windows yet. |
| 7 | // XFAIL: target={{.*windows-(msvc.*|gnu)}} |
| 8 | |
| 9 | // New Bionic rejects %n |
| 10 | // https://android.googlesource.com/platform/bionic/+/41398d03b7e8e0dfb951660ae713e682e9fc0336 |
| 11 | // UNSUPPORTED: android |
| 12 | |
| 13 | #include <stdio.h> |
| 14 | int main() { |
| 15 | #ifdef _MSC_VER |
| 16 | // FIXME: The test raises a dialog even though it's XFAILd. |
| 17 | return 42; |
| 18 | #endif |
| 19 | volatile char c = '0'; |
| 20 | volatile int x = 12; |
| 21 | volatile float f = 1.239; |
| 22 | volatile char s[] = "34" ; |
| 23 | volatile int n[1]; |
| 24 | printf(format: "%c %d %.3f %s%n\n" , c, x, f, s, &n[1]); |
| 25 | return 0; |
| 26 | // Check that %n is sanitized. |
| 27 | // CHECK-ON: stack-buffer-overflow |
| 28 | // CHECK-ON-NOT: 0 12 1.239 34 |
| 29 | // CHECK-OFF: 0 12 1.239 34 |
| 30 | } |
| 31 | |