fuzzer_main.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // ArduinoJson - arduinojson.org
  2. // Copyright Benoit Blanchon 2014-2019
  3. // MIT License
  4. // This file is NOT use by Google's OSS fuzz
  5. // I only use it to reproduce the bugs found
  6. #include <stdint.h> // size_t
  7. #include <stdio.h> // fopen et al.
  8. #include <stdlib.h> // exit
  9. #include <iostream>
  10. #include <vector>
  11. extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size);
  12. std::vector<uint8_t> read(const char* path) {
  13. FILE* f = fopen(path, "rb");
  14. if (!f) {
  15. std::cerr << "Failed to open " << path << std::endl;
  16. exit(1);
  17. }
  18. fseek(f, 0, SEEK_END);
  19. size_t size = ftell(f);
  20. fseek(f, 0, SEEK_SET);
  21. std::vector<uint8_t> buffer(size);
  22. if (fread(buffer.data(), 1, size, f) != size) {
  23. fclose(f);
  24. std::cerr << "Failed to read " << path << std::endl;
  25. exit(1);
  26. }
  27. fclose(f);
  28. return buffer;
  29. }
  30. int main(int argc, const char* argv[]) {
  31. if (argc < 2) {
  32. std::cerr << "Usage: msgpack_fuzzer files" << std::endl;
  33. return 1;
  34. }
  35. for (int i = 1; i < argc; i++) {
  36. std::cout << "Loading " << argv[i] << std::endl;
  37. std::vector<uint8_t> buffer = read(argv[i]);
  38. LLVMFuzzerTestOneInput(buffer.data(), buffer.size());
  39. }
  40. return 0;
  41. }