Alexey Samsonov | 00cd273 | 2014-01-21 11:58:33 +0000 | [diff] [blame] | 1 | // RUN: %clang_asan -O2 %s -o %t |
Alexey Samsonov | 54411d5 | 2016-03-11 05:04:49 +0000 | [diff] [blame] | 2 | // We need replace_str=0, intercept_strlen=0 and replace_intrin=0 to avoid |
| 3 | // reporting errors in strlen() and memcpy() called by printf(). |
| 4 | // RUN: %env_asan_opts=replace_str=0:intercept_strlen=0:replace_intrin=0:check_printf=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s |
| 5 | // RUN: %env_asan_opts=replace_str=0:intercept_strlen=0:replace_intrin=0:check_printf=0 %run %t 2>&1 | FileCheck --check-prefix=CHECK-OFF %s |
| 6 | // RUN: %env_asan_opts=replace_str=0:intercept_strlen=0:replace_intrin=0 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s |
Alexey Samsonov | 00cd273 | 2014-01-21 11:58:33 +0000 | [diff] [blame] | 7 | |
Timur Iskhodzhanov | 7f29181 | 2014-05-28 13:06:14 +0000 | [diff] [blame] | 8 | // FIXME: printf is not intercepted on Windows yet. |
Petr Hosek | eb46c95 | 2018-08-09 02:16:18 +0000 | [diff] [blame] | 9 | // XFAIL: windows-msvc |
Timur Iskhodzhanov | 7f29181 | 2014-05-28 13:06:14 +0000 | [diff] [blame] | 10 | |
Alexey Samsonov | 00cd273 | 2014-01-21 11:58:33 +0000 | [diff] [blame] | 11 | #include <stdio.h> |
| 12 | #include <stdlib.h> |
| 13 | #include <string.h> |
| 14 | int main() { |
| 15 | volatile char c = '0'; |
| 16 | volatile int x = 12; |
| 17 | volatile float f = 1.239; |
| 18 | volatile char s[] = "34"; |
| 19 | char *p = strdup((const char *)s); |
| 20 | free(p); |
| 21 | printf("%c %d %.3f %s\n", c, x, f, p); |
| 22 | return 0; |
| 23 | // Check that %s is sanitized. |
| 24 | // CHECK-ON: heap-use-after-free |
| 25 | // CHECK-ON-NOT: 0 12 1.239 34 |
| 26 | // CHECK-OFF: 0 12 1.239 |
| 27 | } |