CMakeLists.txt 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. option(ENABLE_FUZZING "Create executables and targets for fuzzing cJSON with afl." Off)
  2. if (ENABLE_FUZZING)
  3. find_program(AFL_FUZZ afl-fuzz)
  4. if ("${AFL_FUZZ}" MATCHES "AFL_FUZZ-NOTFOUND")
  5. message(FATAL_ERROR "Couldn't find afl-fuzz.")
  6. endif()
  7. add_executable(afl-main afl.c)
  8. target_link_libraries(afl-main "${CJSON_LIB}")
  9. if (NOT ENABLE_SANITIZERS)
  10. message(FATAL_ERROR "Enable sanitizers with -DENABLE_SANITIZERS=On to do fuzzing.")
  11. endif()
  12. option(ENABLE_FUZZING_PRINT "Fuzz printing functions together with parser." On)
  13. set(fuzz_print_parameter "no")
  14. if (ENABLE_FUZZING_PRINT)
  15. set(fuzz_print_parameter "yes")
  16. endif()
  17. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-error")
  18. add_custom_target(afl
  19. COMMAND "${AFL_FUZZ}" -i "${CMAKE_CURRENT_SOURCE_DIR}/inputs" -o "${CMAKE_CURRENT_BINARY_DIR}/findings" -x "${CMAKE_CURRENT_SOURCE_DIR}/json.dict" -- "${CMAKE_CURRENT_BINARY_DIR}/afl-main" "@@" "${fuzz_print_parameter}"
  20. DEPENDS afl-main)
  21. endif()
  22. if(ENABLE_CJSON_TEST)
  23. ADD_EXECUTABLE(fuzz_main fuzz_main.c cjson_read_fuzzer.c)
  24. TARGET_LINK_LIBRARIES(fuzz_main cjson)
  25. endif()