mirror of
https://github.com/zeek/zeek.git
synced 2025-10-11 19:18:19 +00:00
Trick event handlers into returning that they exist during fuzzing
This commit is contained in:
parent
0b8615942d
commit
7f47fa24fd
4 changed files with 28 additions and 10 deletions
|
@ -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
|
||||
|
|
|
@ -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::string, std::unique_ptr<EventHandler>, std::less<>> handlers;
|
||||
// Tracks whether a given event handler was registered in a
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <cstdlib>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
|
|
11
src/zeek.bif
11
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();
|
||||
%}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue