From de14c19d14be90367a1231de56dd347e3f54931c Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 20 Dec 2016 20:50:38 -0600 Subject: [PATCH] [fuzzer] Separate main() into a new file --- test/fuzzing/hb-fuzzer.hh | 4 ++++ test/fuzzing/main.cc | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 test/fuzzing/hb-fuzzer.hh create mode 100644 test/fuzzing/main.cc diff --git a/test/fuzzing/hb-fuzzer.hh b/test/fuzzing/hb-fuzzer.hh new file mode 100644 index 000000000..d0c617e09 --- /dev/null +++ b/test/fuzzing/hb-fuzzer.hh @@ -0,0 +1,4 @@ +#include +#include + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); diff --git a/test/fuzzing/main.cc b/test/fuzzing/main.cc new file mode 100644 index 000000000..4692f7b5f --- /dev/null +++ b/test/fuzzing/main.cc @@ -0,0 +1,21 @@ +#include "hb-fuzzer.hh" + +#include +#include +#include +#include + +std::string FileToString(const std::string &Path) { + /* TODO This silently passes if file does not exist. Fix it! */ + std::ifstream T(Path.c_str()); + return std::string((std::istreambuf_iterator(T)), + std::istreambuf_iterator()); +} + +int main(int argc, char **argv) { + for (int i = 1; i < argc; i++) { + std::string s = FileToString(argv[i]); + std::cout << argv[i] << std::endl; + LLVMFuzzerTestOneInput((const unsigned char*)s.data(), s.size()); + } +}