diff --git a/src/BroString.cc b/src/BroString.cc index c86e14cf37..3dca28439c 100644 --- a/src/BroString.cc +++ b/src/BroString.cc @@ -166,17 +166,19 @@ void BroString::Set(const BroString& str) const char* BroString::CheckString() const { + void *nulTerm; if ( n == 0 ) 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. char* exp_s = Render(); - if ( b[n-1] != '\0' ) - reporter->Error("string without NUL terminator: \"%s\"", exp_s); - else + if ( nulTerm ) reporter->Error("string with embedded NUL: \"%s\"", exp_s); + else + reporter->Error("string without NUL terminator: \"%s\"", exp_s); delete [] exp_s; return ""; diff --git a/testing/btest/Baseline/core.embedded-null/.stdout b/testing/btest/Baseline/core.embedded-null/.stdout new file mode 100644 index 0000000000..edf309beb0 --- /dev/null +++ b/testing/btest/Baseline/core.embedded-null/.stdout @@ -0,0 +1 @@ +error: string with embedded NUL: "hi\x00there" diff --git a/testing/btest/core/embedded-null.bro b/testing/btest/core/embedded-null.bro new file mode 100644 index 0000000000..95a4c965a9 --- /dev/null +++ b/testing/btest/core/embedded-null.bro @@ -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); + }