From ecf278874006c641e1ac486a90a885c2dbcdbb8a Mon Sep 17 00:00:00 2001 From: Philippe Antoine Date: Fri, 23 Mar 2018 10:10:01 +0100 Subject: [PATCH] Better reporter for Brostring with embedded NUL Can be reproduced with something like curl 127.0.0.1:8002/readme.html%00lol --- src/BroString.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/BroString.cc b/src/BroString.cc index c86e14cf37..0fd7a52a65 100644 --- a/src/BroString.cc +++ b/src/BroString.cc @@ -166,14 +166,16 @@ 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' ) + if ( nulTerm == NULL ) reporter->Error("string without NUL terminator: \"%s\"", exp_s); else reporter->Error("string with embedded NUL: \"%s\"", exp_s);