diff --git a/src/EventRegistry.cc b/src/EventRegistry.cc index 1775fc57ab..6140746b54 100644 --- a/src/EventRegistry.cc +++ b/src/EventRegistry.cc @@ -136,4 +136,14 @@ void EventRegistry::SetErrorHandler(std::string_view name) std::string(name).c_str()); } +void EventRegistry::ActivateAllHandlers() + { + auto event_names = AllHandlers(); + for ( const auto& name : event_names ) + { + if ( auto event = Lookup(name) ) + event->SetGenerateAlways(); + } + } + } // namespace zeek diff --git a/src/EventRegistry.h b/src/EventRegistry.h index 70f5e1cf7d..bc19644793 100644 --- a/src/EventRegistry.h +++ b/src/EventRegistry.h @@ -60,6 +60,17 @@ public: void PrintDebug(); + /** + * Marks all event handlers as active. + * + * By default, zeek does not generate (raise) events that have not handled by + * any scripts. This means that these events will be invisible to a lot of other + * event handlers - and will not raise :zeek:id:`new_event`. Calling this + * function will cause all event handlers to be raised. This is likely only + * useful for debugging and fuzzing, and likely causes reduced performance. + */ + void ActivateAllHandlers(); + private: std::map, std::less<>> handlers; // Tracks whether a given event handler was registered in a diff --git a/src/fuzzers/fuzzer-setup.h b/src/fuzzers/fuzzer-setup.h index 4e0b4e79f0..b3fbb62b0d 100644 --- a/src/fuzzers/fuzzer-setup.h +++ b/src/fuzzers/fuzzer-setup.h @@ -4,6 +4,7 @@ #include #include "zeek/Event.h" +#include "zeek/EventRegistry.h" #include "zeek/broker/Manager.h" #include "zeek/file_analysis/Manager.h" #include "zeek/session/Manager.h" @@ -41,6 +42,11 @@ extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) if ( zeek::detail::setup(*argc, *argv, &options).code ) abort(); + // We have to trick the event handlers into returning true that they exist here + // even if they don't, because otherwise we lose a bit of coverage where if + // statements return false that would otherwise not. + zeek::event_registry->ActivateAllHandlers(); + return 0; } diff --git a/src/zeek.bif b/src/zeek.bif index 9b00450766..39e2055a3b 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -5366,16 +5366,7 @@ function match_signatures%(c: connection, pattern_type: int, s: string, ## only useful for debugging and causes reduced performance. function generate_all_events%(%) : bool %{ - auto event_names = event_registry->AllHandlers(); - for ( const auto& name: event_names ) - { - auto event = event_registry->Lookup(name); - if ( event == nullptr ) - continue; - - event->SetGenerateAlways(); - } - + event_registry->ActivateAllHandlers(); return zeek::val_mgr->True(); %}