aboutsummaryrefslogtreecommitdiffstats
path: root/src/fuzzer/fuzzers.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/fuzzer/fuzzers.h')
-rw-r--r--src/fuzzer/fuzzers.h38
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