From 00de88f4cb03fb90a8e66203c94dd4689258af4d Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 10 Aug 2011 12:28:36 -0500 Subject: [PATCH] Fix reporter using part of the actual message as a format string When not reporting via events, the final contents of the message buffer after formatting was being used as a format string to fprintf instead of writing out the actual string. --- src/Reporter.cc | 2 +- .../btest/Baseline/core.reporter-fmt-strings/output | 1 + testing/btest/core/reporter-fmt-strings.bro | 10 ++++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 testing/btest/Baseline/core.reporter-fmt-strings/output create mode 100644 testing/btest/core/reporter-fmt-strings.bro diff --git a/src/Reporter.cc b/src/Reporter.cc index 4a8e35e650..053d6370d7 100644 --- a/src/Reporter.cc +++ b/src/Reporter.cc @@ -302,7 +302,7 @@ void Reporter::DoLog(const char* prefix, EventHandlerPtr event, FILE* out, Conne s += buffer; s += "\n"; - fprintf(out, s.c_str()); + fprintf(out, "%s", s.c_str()); } if ( alloced ) diff --git a/testing/btest/Baseline/core.reporter-fmt-strings/output b/testing/btest/Baseline/core.reporter-fmt-strings/output new file mode 100644 index 0000000000..10a883cb5d --- /dev/null +++ b/testing/btest/Baseline/core.reporter-fmt-strings/output @@ -0,0 +1 @@ +error in /Users/jsiwek/tmp/bro/testing/btest/.tmp/core.reporter-fmt-strings/reporter-fmt-strings.bro, line 9: not an event (dont_interpret_this(%s)) diff --git a/testing/btest/core/reporter-fmt-strings.bro b/testing/btest/core/reporter-fmt-strings.bro new file mode 100644 index 0000000000..0e0be77844 --- /dev/null +++ b/testing/btest/core/reporter-fmt-strings.bro @@ -0,0 +1,10 @@ +# The format string below should end up as a literal part of the reporter's +# error message to stderr and shouldn't be replaced internally. +# +# @TEST-EXEC-FAIL: bro %INPUT >output 2>&1 +# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff output + +event bro_init() +{ + event dont_interpret_this("%s"); +}