diff options
author | Kostya Serebryany <kcc@google.com> | 2017-05-03 18:38:34 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2017-05-03 18:38:34 +0000 |
commit | 72830dd7ffe3932beb5f5fbe29d84105b7df3f8a (patch) | |
tree | 4176c740c2a4af6886bd377b694da5e3d7d7cf5b | |
parent | 4e8f70074eb0b1b8612f770d269791afaac38f74 (diff) |
[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.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@302064 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/sanitizer_common/sanitizer_common_interceptors_format.inc | 12 | ||||
-rw-r--r-- | test/sanitizer_common/TestCases/Linux/unexpected_format_specifier_test.cc | 12 |
2 files changed, 20 insertions, 4 deletions
diff --git a/lib/sanitizer_common/sanitizer_common_interceptors_format.inc b/lib/sanitizer_common/sanitizer_common_interceptors_format.inc index 12563499c..5ebe5a6ba 100644 --- a/lib/sanitizer_common/sanitizer_common_interceptors_format.inc +++ b/lib/sanitizer_common/sanitizer_common_interceptors_format.inc @@ -325,8 +325,8 @@ static void scanf_common(void *ctx, int n_inputs, bool allowGnuMalloc, 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, const char *format, va_list aq) { 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') { diff --git a/test/sanitizer_common/TestCases/Linux/unexpected_format_specifier_test.cc b/test/sanitizer_common/TestCases/Linux/unexpected_format_specifier_test.cc new file mode 100644 index 000000000..f48cce8ea --- /dev/null +++ b/test/sanitizer_common/TestCases/Linux/unexpected_format_specifier_test.cc @@ -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 |