diff --git a/CMakeLists.txt b/CMakeLists.txt index 66c565b5..697703b1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,3 +14,4 @@ endif() include_directories(${CMAKE_CURRENT_LIST_DIR}/src) add_subdirectory(third-party/catch) add_subdirectory(test) +add_subdirectory(fuzzing) diff --git a/fuzzing/CMakeLists.txt b/fuzzing/CMakeLists.txt new file mode 100644 index 00000000..26946e57 --- /dev/null +++ b/fuzzing/CMakeLists.txt @@ -0,0 +1,8 @@ +# ArduinoJson - arduinojson.org +# Copyright Benoit Blanchon 2014-2018 +# MIT License + +add_executable(msgpack_fuzzer + msgpack_fuzzer.cpp + fuzzer_main.cpp +) diff --git a/fuzzing/fuzzer_main.cpp b/fuzzing/fuzzer_main.cpp new file mode 100644 index 00000000..06ec63a5 --- /dev/null +++ b/fuzzing/fuzzer_main.cpp @@ -0,0 +1,34 @@ +// ArduinoJson - arduinojson.org +// Copyright Benoit Blanchon 2014-2018 +// MIT License + +// This file is NOT use by Google's OSS fuzz +// I only use it to reproduce the bugs found + +#include +#include +#include +#include + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size); + +std::string read(const char* path) { + std::ifstream file(path); + return std::string(std::istreambuf_iterator(file), + std::istreambuf_iterator()); +} + +int main(int argc, const char* argv[]) { + if (argc < 2) { + std::cerr << "Usage: msgpack_fuzzer files" << std::endl; + return 1; + } + + for (int i = 1; i < argc; i++) { + std::cout << "Loading " << argv[i] << std::endl; + std::string buffer = read(argv[i]); + LLVMFuzzerTestOneInput(reinterpret_cast(buffer.data()), + buffer.size()); + } + return 0; +}