brintos

brintos / llvm-project-archived public Read only

0
0
Text · 907 B · 4c791c6 Raw
27 lines · c
1// RUN: %clang_asan -O2 %s -o %t2// RUN: %env_asan_opts=check_printf=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s3// RUN: not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s4 5// FIXME: sprintf is not intercepted on Windows yet. But this test can6// pass if sprintf calls memmove, which is intercepted, so we can't XFAIL it.7// UNSUPPORTED: target={{.*windows-msvc.*}}8 9#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];16  fputs("before sprintf\n", stderr);17  sprintf((char *)buf, "%c %d %.3f %s\n", c, x, f, s);18  fputs("after sprintf", stderr);19  fputs((const char *)buf, stderr);20  return 0;21  // Check that size of output buffer is sanitized.22  // CHECK-ON: before sprintf23  // CHECK-ON-NOT: after sprintf24  // CHECK-ON: stack-buffer-overflow25  // CHECK-ON-NOT: 0 12 1.239 3426}27