Ver código fonte

Added executable msgpack_fuzzer

Benoit Blanchon 7 anos atrás
pai
commit
00aa038818
3 arquivos alterados com 43 adições e 0 exclusões
  1. 1 0
      CMakeLists.txt
  2. 8 0
      fuzzing/CMakeLists.txt
  3. 34 0
      fuzzing/fuzzer_main.cpp

+ 1 - 0
CMakeLists.txt

@@ -14,3 +14,4 @@ endif()
 include_directories(${CMAKE_CURRENT_LIST_DIR}/src)
 include_directories(${CMAKE_CURRENT_LIST_DIR}/src)
 add_subdirectory(third-party/catch)
 add_subdirectory(third-party/catch)
 add_subdirectory(test)
 add_subdirectory(test)
+add_subdirectory(fuzzing)

+ 8 - 0
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
+)

+ 34 - 0
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 <stdint.h>
+#include <fstream>
+#include <iostream>
+#include <string>
+
+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<char>(file),
+                     std::istreambuf_iterator<char>());
+}
+
+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<const uint8_t*>(buffer.data()),
+                           buffer.size());
+  }
+  return 0;
+}