CMakeLists.txt 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # ArduinoJson - https://arduinojson.org
  2. # Copyright © 2014-2025, Benoit BLANCHON
  3. # MIT License
  4. set(CMAKE_CXX_STANDARD 11)
  5. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  6. if(MSVC)
  7. add_compile_options(-D_CRT_SECURE_NO_WARNINGS)
  8. endif()
  9. add_executable(msgpack_reproducer
  10. msgpack_fuzzer.cpp
  11. reproducer.cpp
  12. )
  13. target_link_libraries(msgpack_reproducer
  14. ArduinoJson
  15. )
  16. add_executable(json_reproducer
  17. json_fuzzer.cpp
  18. reproducer.cpp
  19. )
  20. target_link_libraries(json_reproducer
  21. ArduinoJson
  22. )
  23. macro(add_fuzzer name)
  24. set(FUZZER "${name}_fuzzer")
  25. set(CORPUS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${name}_corpus")
  26. set(SEED_CORPUS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${name}_seed_corpus")
  27. add_executable("${FUZZER}"
  28. "${name}_fuzzer.cpp"
  29. )
  30. target_link_libraries("${FUZZER}"
  31. ArduinoJson
  32. )
  33. set_target_properties("${FUZZER}"
  34. PROPERTIES
  35. COMPILE_FLAGS "-fprofile-instr-generate -fcoverage-mapping -fsanitize=fuzzer -fno-sanitize-recover=all"
  36. LINK_FLAGS "-fprofile-instr-generate -fcoverage-mapping -fsanitize=fuzzer -fno-sanitize-recover=all"
  37. )
  38. add_test(
  39. NAME "${FUZZER}"
  40. COMMAND "${FUZZER}" "${CORPUS_DIR}" "${SEED_CORPUS_DIR}" -max_total_time=5 -timeout=1
  41. )
  42. set_tests_properties("${FUZZER}"
  43. PROPERTIES
  44. LABELS "Fuzzing"
  45. )
  46. endmacro()
  47. # Needs Clang 6+ to compile
  48. if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 6)
  49. if(DEFINED ENV{GITHUB_ACTIONS} AND CMAKE_CXX_COMPILER_VERSION MATCHES "^11\\.")
  50. # Clang 11 fails on GitHub Actions with the following error:
  51. # > ERROR: UndefinedBehaviorSanitizer failed to allocate 0x0 (0) bytes of SetAlternateSignalStack (error code: 22)
  52. # > Sanitizer CHECK failed: /build/llvm-toolchain-11-mnvtwk/llvm-toolchain-11-11.1.0/compiler-rt/lib/sanitizer_common/sanitizer_common.cpp:54 ((0 && "unable to mmap")) != (0) (0, 0)
  53. message(WARNING "Fuzzing is disabled on GitHub Actions to workaround a bug in Clang 11")
  54. return()
  55. endif()
  56. add_fuzzer(json)
  57. add_fuzzer(msgpack)
  58. endif()