[compiler-rt] r302064 - [asan] print the 'unexpected format specifier in printf interceptor' warning just once (came up in https://github.com/google/oss-fuzz/pull/562). Not touching a similar scanf warning -- for some reason it does not fire for me.

Kostya Serebryany via llvm-commits llvm-commits at lists.llvm.org
Wed May 3 11:38:35 PDT 2017


Author: kcc
Date: Wed May  3 13:38:34 2017
New Revision: 302064

URL: http://llvm.org/viewvc/llvm-project?rev=302064&view=rev
Log:
[asan] print the 'unexpected format specifier in printf interceptor' warning just once (came up in https://github.com/google/oss-fuzz/pull/562). Not touching a similar scanf warning -- for some reason it does not fire for me. 

Added:
    compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/unexpected_format_specifier_test.cc
Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors_format.inc

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors_format.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors_format.inc?rev=302064&r1=302063&r2=302064&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors_format.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors_format.inc Wed May  3 13:38:34 2017
@@ -325,8 +325,8 @@ static void scanf_common(void *ctx, int
       continue;
     int size = scanf_get_value_size(&dir);
     if (size == FSS_INVALID) {
-      Report("WARNING: unexpected format specifier in scanf interceptor: "
-        "%.*s\n", dir.end - dir.begin, dir.begin);
+      Report("%s: WARNING: unexpected format specifier in scanf interceptor: ",
+             SanitizerToolName, "%.*s\n", dir.end - dir.begin, dir.begin);
       break;
     }
     void *argp = va_arg(aq, void *);
@@ -520,8 +520,12 @@ static void printf_common(void *ctx, con
       continue;
     int size = printf_get_value_size(&dir);
     if (size == FSS_INVALID) {
-      Report("WARNING: unexpected format specifier in printf "
-             "interceptor: %.*s\n", dir.end - dir.begin, dir.begin);
+      static int ReportedOnce;
+      if (!ReportedOnce++)
+        Report(
+            "%s: WARNING: unexpected format specifier in printf "
+            "interceptor: %.*s (reported once per process)\n",
+            SanitizerToolName, dir.end - dir.begin, dir.begin);
       break;
     }
     if (dir.convSpecifier == 'n') {

Added: compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/unexpected_format_specifier_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/unexpected_format_specifier_test.cc?rev=302064&view=auto
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/unexpected_format_specifier_test.cc (added)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/unexpected_format_specifier_test.cc Wed May  3 13:38:34 2017
@@ -0,0 +1,12 @@
+// RUN: %clang -w -O0 %s -o %t && %run %t 2>&1 | FileCheck %s
+// UNSUPPORTED: lsan
+// UNSUPPORTED: msan
+#include <stdio.h>
+int main() {
+  int a;
+  printf("%Q\n", 1);
+  printf("%Q\n", 1);
+  printf("%Q\n", 1);
+}
+// CHECK: unexpected format specifier in printf interceptor: %Q (reported once per process)
+// CHECK-NOT: unexpected format specifier in printf interceptor




More information about the llvm-commits mailing list