mirror of
https://github.com/zeek/zeek.git
synced 2025-10-13 12:08:20 +00:00
fuzzer-setup: Allow customization without recompiling
This change allows to invoke a reproducer with different script options and extra scripts to ease debugging and investigation. For example, enabling the DPD debug stream and adding misc/dump-events can be done as follows after this change: ZEEK_DEBUG_LOG_STDERR=1 ../../build/src/fuzzers/zeek-pop3-fuzzer <test-case> -- -B dpd misc/dump-events
This commit is contained in:
parent
631b30f5bb
commit
9530f73ec4
2 changed files with 38 additions and 8 deletions
|
@ -30,13 +30,42 @@ extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv)
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
zeek::Options options;
|
int zeek_args = 0;
|
||||||
|
char** zeek_argv = &((*argv)[*argc]);
|
||||||
|
|
||||||
|
// If the inputs given to the fuzzer executable contain "--", consider all
|
||||||
|
// following arguments to be part of Zeek's command-line and forward them to
|
||||||
|
// zeek::parse_cmdline().
|
||||||
|
//
|
||||||
|
// This allows to load more scripts and set or overwrite options without
|
||||||
|
// the need to recompile the fuzzer.
|
||||||
|
for ( int i = 0; i < *argc; i++ )
|
||||||
|
{
|
||||||
|
if ( ! strcmp((*argv)[i], "--") )
|
||||||
|
{
|
||||||
|
zeek_args = *argc - i;
|
||||||
|
(*argv)[i] = (*argv)[0]; // Fake argv[0] for parse_cmdline() with the original argv[0]
|
||||||
|
zeek_argv = &(*argv)[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Propagate change in argc upwards.
|
||||||
|
*argc = *argc - zeek_args;
|
||||||
|
|
||||||
|
zeek::Options options = zeek_args > 0 ? zeek::parse_cmdline(zeek_args, zeek_argv)
|
||||||
|
: zeek::Options{};
|
||||||
|
|
||||||
|
std::vector<std::string> default_script_options_to_set = {
|
||||||
|
"Site::local_nets={10.0.0.0/8}", "Log::default_writer=Log::WRITER_NONE",
|
||||||
|
"Reporter::info_to_stderr=F", "Reporter::warnings_to_stderr=F",
|
||||||
|
"Reporter::errors_to_stderr=F",
|
||||||
|
};
|
||||||
|
|
||||||
|
// Prepend default options.
|
||||||
|
options.script_options_to_set.insert(options.script_options_to_set.begin(),
|
||||||
|
default_script_options_to_set.begin(),
|
||||||
|
default_script_options_to_set.end());
|
||||||
options.scripts_to_load.emplace_back("local.zeek");
|
options.scripts_to_load.emplace_back("local.zeek");
|
||||||
options.script_options_to_set.emplace_back("Site::local_nets={10.0.0.0/8}");
|
|
||||||
options.script_options_to_set.emplace_back("Log::default_writer=Log::WRITER_NONE");
|
|
||||||
options.script_options_to_set.emplace_back("Reporter::info_to_stderr=F");
|
|
||||||
options.script_options_to_set.emplace_back("Reporter::warnings_to_stderr=F");
|
|
||||||
options.script_options_to_set.emplace_back("Reporter::errors_to_stderr=F");
|
|
||||||
options.deterministic_mode = true;
|
options.deterministic_mode = true;
|
||||||
options.ignore_checksums = true;
|
options.ignore_checksums = true;
|
||||||
options.abort_on_scripting_errors = true;
|
options.abort_on_scripting_errors = true;
|
||||||
|
|
|
@ -15,10 +15,11 @@ int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
using namespace std::chrono;
|
using namespace std::chrono;
|
||||||
auto agg_start = high_resolution_clock::now();
|
auto agg_start = high_resolution_clock::now();
|
||||||
auto num_inputs = argc - 1;
|
|
||||||
printf("Standalone fuzzer processing %d inputs\n", num_inputs);
|
|
||||||
|
|
||||||
LLVMFuzzerInitialize(&argc, &argv);
|
LLVMFuzzerInitialize(&argc, &argv);
|
||||||
|
|
||||||
|
auto num_inputs = argc - 1;
|
||||||
|
printf("Standalone fuzzer processing %d inputs\n", num_inputs);
|
||||||
auto fuzz_start = high_resolution_clock::now();
|
auto fuzz_start = high_resolution_clock::now();
|
||||||
|
|
||||||
for ( auto i = 0; i < num_inputs; ++i )
|
for ( auto i = 0; i < num_inputs; ++i )
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue