Sanitize printf functions.
Intercept and sanitize arguments passed to printf functions in ASan and TSan
(don't do this in MSan for now). The checks are controlled by runtime flag
(off by default for now).
Patch http://llvm-reviews.chandlerc.com/D2480 by Yuri Gribov!
llvm-svn: 199729
diff --git a/compiler-rt/lib/asan/lit_tests/TestCases/printf-1.c b/compiler-rt/lib/asan/lit_tests/TestCases/printf-1.c
new file mode 100644
index 0000000..1da5200
--- /dev/null
+++ b/compiler-rt/lib/asan/lit_tests/TestCases/printf-1.c
@@ -0,0 +1,16 @@
+// RUN: %clang_asan -O2 %s -o %t
+// RUN: ASAN_OPTIONS=check_printf=1 %t 2>&1 | FileCheck %s
+// RUN: ASAN_OPTIONS=check_printf=0 %t 2>&1 | FileCheck %s
+// RUN: %t 2>&1 | FileCheck %s
+
+#include <stdio.h>
+int main() {
+ volatile char c = '0';
+ volatile int x = 12;
+ volatile float f = 1.239;
+ volatile char s[] = "34";
+ printf("%c %d %.3f %s\n", c, x, f, s);
+ return 0;
+ // Check that printf works fine under Asan.
+ // CHECK: 0 12 1.239 34
+}