From ef2c3d7d01ffdeb1b29c439b9ec0348302170e00 Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Sun, 23 Dec 2018 18:14:52 -0500 Subject: 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. --- src/fuzzer/fuzzers.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src/fuzzer') 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 + +namespace { + +int fuzz_files(char* files[]) + { + for(size_t i = 0; files[i]; ++i) + { + std::ifstream in(files[i]); + + if(in.good()) + { + std::vector 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 -- cgit v1.2.3