fuzzer-driver_afl.cpp 1007 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. __ _____ _____ _____
  3. __| | __| | | | JSON for Modern C++ (fuzz test support)
  4. | | |__ | | | | | | version 3.7.3
  5. |_____|_____|_____|_|___| https://github.com/nlohmann/json
  6. This file implements a driver for American Fuzzy Lop (afl-fuzz). It relies on
  7. an implementation of the `LLVMFuzzerTestOneInput` function which processes a
  8. passed byte array.
  9. Licensed under the MIT License <http://opensource.org/licenses/MIT>.
  10. */
  11. #include <vector> // for vector
  12. #include <cstdint> // for uint8_t
  13. #include <iostream> // for cin
  14. extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size);
  15. int main()
  16. {
  17. #ifdef __AFL_HAVE_MANUAL_CONTROL
  18. while (__AFL_LOOP(1000))
  19. {
  20. #endif
  21. // copy stdin to byte vector
  22. std::vector<uint8_t> vec;
  23. char c;
  24. while (std::cin.get(c))
  25. {
  26. vec.push_back(static_cast<uint8_t>(c));
  27. }
  28. LLVMFuzzerTestOneInput(vec.data(), vec.size());
  29. #ifdef __AFL_HAVE_MANUAL_CONTROL
  30. }
  31. #endif
  32. }