diff options
author | Jack Lloyd <[email protected]> | 2018-12-23 18:14:52 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-12-23 18:14:52 -0500 |
commit | ef2c3d7d01ffdeb1b29c439b9ec0348302170e00 (patch) | |
tree | bfa831022451bda44fd290f284bb3363b9c6a6af /src/fuzzer/fuzzers.h | |
parent | b914ec97ebe4dd207ab15cbc6f65256c3b147b08 (diff) |
Add a multi-file input mode for test fuzzers
The test_fuzzers.py script is very slow especially on CI. Add a mode
to the test fuzzers where it will accept many files on the command
line and test each of them in turn. This is 100s of times faster,
as it avoids all overhead from fork/exec.
It has the downside that you can't tell which input caused a crash, so
retain the old mode with --one-at-a-time option for debugging work.
Diffstat (limited to 'src/fuzzer/fuzzers.h')
-rw-r--r-- | src/fuzzer/fuzzers.h | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/fuzzer/fuzzers.h b/src/fuzzer/fuzzers.h index 91a8b8cdc..8248a4f58 100644 --- a/src/fuzzer/fuzzers.h +++ b/src/fuzzer/fuzzers.h @@ -72,10 +72,48 @@ inline Botan::RandomNumberGenerator& fuzzer_rng() #error "Build configured for AFL but not being compiled by AFL compiler" #endif +#if defined(BOTAN_FUZZER_IS_TEST) + +#include <fstream> + +namespace { + +int fuzz_files(char* files[]) + { + for(size_t i = 0; files[i]; ++i) + { + std::ifstream in(files[i]); + + if(in.good()) + { + std::vector<uint8_t> buf(max_fuzzer_input_size); + in.read((char*)buf.data(), buf.size()); + const size_t got = std::cin.gcount(); + buf.resize(got); + buf.shrink_to_fit(); + + LLVMFuzzerTestOneInput(buf.data(), got); + } + } + + return 0; + } + +} + +#endif + int main(int argc, char* argv[]) { LLVMFuzzerInitialize(&argc, &argv); +#if defined(BOTAN_FUZZER_IS_TEST) + if(argc > 1) + { + return fuzz_files(&argv[1]); + } +#endif + #if defined(__AFL_LOOP) while(__AFL_LOOP(1000)) #endif |