mirror of
https://github.com/zeek/zeek.git
synced 2025-10-13 03:58:20 +00:00
Add standalone driver for fuzz targets
Useful for cases that don't need to use a fuzzing engine, but just run the fuzz targets over some set of inputs, like for regression/CI tests. Also added a POP3 fuzzer dictionary, seed corpus, and README with examples.
This commit is contained in:
parent
8f1b34b915
commit
78b0b2183d
8 changed files with 168 additions and 8 deletions
47
src/fuzzers/standalone-driver.cc
Normal file
47
src/fuzzers/standalone-driver.cc
Normal file
|
@ -0,0 +1,47 @@
|
|||
#include <cstdio>
|
||||
#include <cstdint>
|
||||
#include <cassert>
|
||||
#include <memory>
|
||||
#include <chrono>
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size);
|
||||
extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv);
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
using namespace std::chrono;
|
||||
auto agg_start = high_resolution_clock::now();
|
||||
auto num_inputs = argc - 1;
|
||||
printf("Standalone fuzzer processing %d inputs\n", num_inputs);
|
||||
|
||||
LLVMFuzzerInitialize(&argc, &argv);
|
||||
|
||||
for ( auto i = 0; i < num_inputs; ++i )
|
||||
{
|
||||
auto input_file_name = argv[i + 1];
|
||||
printf(" %s:", input_file_name);
|
||||
|
||||
auto f = fopen(input_file_name, "r");
|
||||
assert(f);
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
auto input_length = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
|
||||
auto input_buffer = std::make_unique<uint8_t[]>(input_length);
|
||||
auto bytes_read = fread(input_buffer.get(), 1, input_length, f);
|
||||
assert(bytes_read == input_length);
|
||||
|
||||
auto start = high_resolution_clock::now();
|
||||
LLVMFuzzerTestOneInput(input_buffer.get(), input_length);
|
||||
auto stop = high_resolution_clock::now();
|
||||
auto dt = duration<double>(stop - start).count();
|
||||
|
||||
printf(" %6zu bytes, %f seconds\n", input_length, dt);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
auto agg_stop = high_resolution_clock::now();
|
||||
auto agg_dt = duration<double>(agg_stop - agg_start).count();
|
||||
printf("Processed %d inputs in %fs\n", num_inputs, agg_dt);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue