Merge branch 'Reporter/MessageFix' of https://github.com/catenacyber/bro

* 'Reporter/MessageFix' of https://github.com/catenacyber/bro:
  Better reporter for Brostring with embedded NUL

I slightly changed the code for beautification purposes and added a
testcase. No functional changes.
This commit is contained in:
Johanna Amann 2018-04-16 10:46:55 -07:00
commit 0747080e5f
3 changed files with 15 additions and 4 deletions

View file

@ -166,17 +166,19 @@ void BroString::Set(const BroString& str)
const char* BroString::CheckString() const const char* BroString::CheckString() const
{ {
void *nulTerm;
if ( n == 0 ) if ( n == 0 )
return ""; return "";
if ( memchr(b, '\0', n + final_NUL) != &b[n] ) nulTerm = memchr(b, '\0', n + final_NUL);
if ( nulTerm != &b[n] )
{ {
// Either an embedded NUL, or no final NUL. // Either an embedded NUL, or no final NUL.
char* exp_s = Render(); char* exp_s = Render();
if ( b[n-1] != '\0' ) if ( nulTerm )
reporter->Error("string without NUL terminator: \"%s\"", exp_s);
else
reporter->Error("string with embedded NUL: \"%s\"", exp_s); reporter->Error("string with embedded NUL: \"%s\"", exp_s);
else
reporter->Error("string without NUL terminator: \"%s\"", exp_s);
delete [] exp_s; delete [] exp_s;
return "<string-with-NUL>"; return "<string-with-NUL>";

View file

@ -0,0 +1 @@
error: string with embedded NUL: "hi\x00there"

View file

@ -0,0 +1,8 @@
# @TEST-EXEC: bro -b %INPUT 2>&1
# @TEST-EXEC: btest-diff .stdout
event bro_init()
{
local a = "hi\x00there";
unique_id(a);
}