diff --git a/aux/broccoli b/aux/broccoli index 31c3d1d9ef..aff2b1eba1 160000 --- a/aux/broccoli +++ b/aux/broccoli @@ -1 +1 @@ -Subproject commit 31c3d1d9efa706969f0cd98223444c5f064a6fa7 +Subproject commit aff2b1eba11d9df4e580ec0a039e01c94bb9c6a2 diff --git a/src/CompHash.cc b/src/CompHash.cc index fcd5f61e53..6893cafd8f 100644 --- a/src/CompHash.cc +++ b/src/CompHash.cc @@ -644,7 +644,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey* k, const char* kp0, Func* f = Func::GetFuncPtrByID(*kp); if ( ! f ) - reporter->InternalError("failed to look up unique function id %"PRIu32" in CompositeHash::RecoverOneVal()"); + reporter->InternalError("failed to look up unique function id %" PRIu32 " in CompositeHash::RecoverOneVal()", *kp); pval = new Val(f); diff --git a/src/File.cc b/src/File.cc index ada75fe401..37ce7c0b4b 100644 --- a/src/File.cc +++ b/src/File.cc @@ -285,7 +285,7 @@ FILE* BroFile::BringIntoCache() if ( ! f ) { - reporter->Error("can't open %s", this); + reporter->Error("can't open %s", name); f = fopen("/dev/null", "w"); diff --git a/src/OSFinger.h b/src/OSFinger.h index 1e745505eb..e5a0829640 100644 --- a/src/OSFinger.h +++ b/src/OSFinger.h @@ -103,7 +103,7 @@ protected: void Error(const char* msg) { - reporter->Error(msg); + reporter->Error("%s", msg); err = true; } diff --git a/src/RemoteSerializer.cc b/src/RemoteSerializer.cc index e359a4a749..6a0ac54446 100644 --- a/src/RemoteSerializer.cc +++ b/src/RemoteSerializer.cc @@ -3085,7 +3085,7 @@ void RemoteSerializer::FatalError(const char* msg) { msg = fmt("fatal error, shutting down communication: %s", msg); Log(LogError, msg); - reporter->Error(msg); + reporter->Error("%s", msg); closed = true; kill(child_pid, SIGQUIT); diff --git a/src/Reporter.h b/src/Reporter.h index d0fc66299b..6c57a26cba 100644 --- a/src/Reporter.h +++ b/src/Reporter.h @@ -15,6 +15,13 @@ class Connection; class Location; +// Check printf-style variadic arguments if we can. +#if __GNUC__ +#define FMT_ATTR __attribute__((format(printf, 2, 3))) // sic! 1st is "this" I guess. +#else +#define FMT_ATTR +#endif + class Reporter { public: Reporter(); @@ -22,25 +29,25 @@ public: // Report an informational message, nothing that needs specific // attention. - void Info(const char* fmt, ...); + void Info(const char* fmt, ...) FMT_ATTR; // Report a warning that may indicate a problem. - void Warning(const char* fmt, ...); + void Warning(const char* fmt, ...) FMT_ATTR; // Report a non-fatal error. Processing proceeds normally after the error // has been reported. - void Error(const char* fmt, ...); + void Error(const char* fmt, ...) FMT_ATTR; // Returns the number of errors reported so far. int Errors() { return errors; } // Report a fatal error. Bro will terminate after the message has been // reported. - void FatalError(const char* fmt, ...); + void FatalError(const char* fmt, ...) FMT_ATTR; // Report a fatal error. Bro will terminate after the message has been // reported and always generate a core dump. - void FatalErrorWithCore(const char* fmt, ...); + void FatalErrorWithCore(const char* fmt, ...) FMT_ATTR; // Report a traffic weirdness, i.e., an unexpected protocol situation // that may lead to incorrectly processing a connnection. @@ -51,15 +58,15 @@ public: // Syslog a message. This methods does nothing if we're running // offline from a trace. - void Syslog(const char* fmt, ...); + void Syslog(const char* fmt, ...) FMT_ATTR; // Report about a potential internal problem. Bro will continue // normally. - void InternalWarning(const char* fmt, ...); + void InternalWarning(const char* fmt, ...) FMT_ATTR; // Report an internal program error. Bro will terminate with a core // dump after the message has been reported. - void InternalError(const char* fmt, ...); + void InternalError(const char* fmt, ...) FMT_ATTR; // Toggle whether non-fatal messages should be reported through the // scripting layer rather on standard output. Fatal errors are always diff --git a/src/Serializer.cc b/src/Serializer.cc index d38e8b3976..b82da0aaf3 100644 --- a/src/Serializer.cc +++ b/src/Serializer.cc @@ -909,7 +909,7 @@ bool FileSerializer::Read(UnserialInfo* info, const char* file, bool header) void FileSerializer::ReportError(const char* str) { - reporter->Error(str); + reporter->Error("%s", str); } void FileSerializer::GotID(ID* id, Val* val) diff --git a/src/Serializer.h b/src/Serializer.h index eabdbc62c1..db09cc837f 100644 --- a/src/Serializer.h +++ b/src/Serializer.h @@ -261,7 +261,7 @@ public: virtual ~CloneSerializer() { } protected: - virtual void ReportError(const char* msg) { reporter->Error(msg); } + virtual void ReportError(const char* msg) { reporter->Error("%s", msg); } virtual void GotID(ID* id, Val* val) { } virtual void GotEvent(const char* name, double time, EventHandlerPtr event, val_list* args) { } diff --git a/src/Val.cc b/src/Val.cc index 164994b3b8..9238315b49 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -2118,7 +2118,7 @@ Val* TableVal::Delete(const Val* index) Val* va = v ? (v->Value() ? v->Value() : this->Ref()) : 0; if ( subnets && ! subnets->Remove(index) ) - reporter->InternalError( "index not in prefix table" ); + reporter->InternalError("index not in prefix table"); if ( LoggingAccess() ) { @@ -2160,7 +2160,7 @@ Val* TableVal::Delete(const HashKey* k) { Val* index = table_hash->RecoverVals(k); if ( ! subnets->Remove(index) ) - reporter->InternalError( "index not in prefix table" ); + reporter->InternalError("index not in prefix table"); Unref(index); } @@ -2417,7 +2417,7 @@ void TableVal::DoExpire(double t) { Val* index = RecoverIndex(k); if ( ! subnets->Remove(index) ) - reporter->InternalError( "index not in prefix table" ); + reporter->InternalError("index not in prefix table"); Unref(index); } diff --git a/src/bro.bif b/src/bro.bif index d8cc9d4696..0fd20397f0 100644 --- a/src/bro.bif +++ b/src/bro.bif @@ -1855,7 +1855,7 @@ function decode_base64%(s: string%): string return new StringVal(t); else { - reporter->Error("error in decoding string %s", @ARG@[0]); + reporter->Error("error in decoding string %s", s->CheckString()); return new StringVal(""); } %} @@ -1987,8 +1987,8 @@ function precompile_pcap_filter%(id: PcapFilterID, s: string%): bool if ( ! pkt_srcs[i]->PrecompileFilter(id->ForceAsInt(), s->CheckString()) ) { - reporter->Error( "precompile_pcap_filter: %s", - pkt_srcs[i]->ErrorMsg() ); + reporter->Error("precompile_pcap_filter: %s", + pkt_srcs[i]->ErrorMsg()); success = false; } } diff --git a/src/main.cc b/src/main.cc index 678b21affb..f450537d5e 100644 --- a/src/main.cc +++ b/src/main.cc @@ -951,7 +951,7 @@ int main(int argc, char** argv) { reporter->Info("invoked event handlers:"); for ( int i = 0; i < alive_handlers->length(); ++i ) - reporter->Info((*alive_handlers)[i]); + reporter->Info("%s", (*alive_handlers)[i]); } delete alive_handlers; diff --git a/src/net_util.cc b/src/net_util.cc index 233548e34e..c0bacc98b2 100644 --- a/src/net_util.cc +++ b/src/net_util.cc @@ -283,7 +283,7 @@ uint32 mask_addr(uint32 a, uint32 top_bits_to_keep) { if ( top_bits_to_keep > 32 ) { - reporter->Error("bad address mask value %s", top_bits_to_keep); + reporter->Error("bad address mask value %d", top_bits_to_keep); return a; } diff --git a/src/parse.y b/src/parse.y index 1035155963..495931aae0 100644 --- a/src/parse.y +++ b/src/parse.y @@ -1593,7 +1593,7 @@ resolve_id: $$ = lookup_ID($1, current_module.c_str()); if ( ! $$ ) - reporter->Error("identifier not defined:", $1); + reporter->Error("identifier not defined: %s", $1); delete [] $1; } @@ -1650,7 +1650,7 @@ int yyerror(const char msg[]) strcat(msgbuf, "\nDocumentation mode is enabled: " "remember to check syntax of ## style comments\n"); - reporter->Error(msgbuf); + reporter->Error("%s", msgbuf); return 0; } diff --git a/src/scan.l b/src/scan.l index 2b1d86929a..88d4e9e5e0 100644 --- a/src/scan.l +++ b/src/scan.l @@ -50,7 +50,7 @@ char last_tok[128]; // a read fails. #define YY_INPUT(buf,result,max_size) \ if ( ((result = fread(buf, 1, max_size, yyin)) == 0) && ferror(yyin) ) \ - reporter->Error(fmt("read failed with \"%s\"", strerror(errno))); + reporter->Error("read failed with \"%s\"", strerror(errno)); // reST documents that we've created (or have at least opened so far). std::list docs_generated; @@ -408,7 +408,7 @@ F RET_CONST(new Val(false, TYPE_BOOL)) uint32 p = atoi(yytext); if ( p > 65535 ) { - reporter->Error("bad port number -", yytext); + reporter->Error("bad port number - %s", yytext); p = 0; } RET_CONST(new PortVal(p, TRANSPORT_TCP)) @@ -417,7 +417,7 @@ F RET_CONST(new Val(false, TYPE_BOOL)) uint32 p = atoi(yytext); if ( p > 65535 ) { - reporter->Error("bad port number -", yytext); + reporter->Error("bad port number - %s", yytext); p = 0; } RET_CONST(new PortVal(p, TRANSPORT_UDP)) @@ -426,7 +426,7 @@ F RET_CONST(new Val(false, TYPE_BOOL)) uint32 p = atoi(yytext); if ( p > 255 ) { - reporter->Error("bad port number -", yytext); + reporter->Error("bad port number - %s", yytext); p = 0; } RET_CONST(new PortVal(p, TRANSPORT_ICMP)) @@ -435,7 +435,7 @@ F RET_CONST(new Val(false, TYPE_BOOL)) uint32 p = atoi(yytext); if ( p > 255 ) { - reporter->Error("bad port number -", yytext); + reporter->Error("bad port number - %s", yytext); p = 0; } RET_CONST(new PortVal(p, TRANSPORT_UNKNOWN)) @@ -499,7 +499,7 @@ F RET_CONST(new Val(false, TYPE_BOOL)) [/\\\n] return yytext[0]; -<*>. reporter->Error("unrecognized character -", yytext); +<*>. reporter->Error("unrecognized character - %s", yytext); <> last_tok[0] = '\0'; return EOF;