2019-10-29 02:46:57 +08:00
|
|
|
# First attempt at a fuzzer, using libFuzzer.
|
|
|
|
#
|
|
|
|
# compile like this:
|
|
|
|
# mkdir build-fuzzer
|
|
|
|
# cd build-fuzzer
|
|
|
|
# export LDFLAGS="-fsanitize=address,undefined"
|
|
|
|
# export CXXFLAGS="-fsanitize=fuzzer-no-link,address,undefined"
|
|
|
|
# export CFLAGS="-fsanitize=fuzzer-no-link,address,undefined"
|
|
|
|
# export CXX=clang++
|
|
|
|
# export CC=clang++
|
2019-11-08 23:32:43 +08:00
|
|
|
# cmake .. -GNinja -DCMAKE_BUILD_TYPE=Debug -DENABLE_FUZZING=On -DSIMDJSON_FUZZ_LINKMAIN=Off -DSIMDJSON_FUZZ_LDFLAGS=-fsanitize=fuzzer
|
2019-10-29 02:46:57 +08:00
|
|
|
# ninja
|
|
|
|
|
|
|
|
|
2019-11-08 23:32:43 +08:00
|
|
|
# settings this links in a main. useful for reproducing,
|
|
|
|
# kcov, gdb, afl, valgrind.
|
|
|
|
# (note that libFuzzer can also reproduce, just pass it the files)
|
|
|
|
#
|
|
|
|
# Using this by default, means the fuzzers will be built as a part of the normal
|
|
|
|
# workflow, meaning they wont bitrot and will participate in refactoring etc.
|
|
|
|
#
|
|
|
|
option(SIMDJSON_FUZZ_LINKMAIN "links a main into fuzz targets for building reproducers" On)
|
|
|
|
|
|
|
|
# For oss-fuzz - insert $LIB_FUZZING_ENGINE into the link flags, but only for
|
|
|
|
# the fuzz targets, otherwise the cmake configuration step fails.
|
|
|
|
set(SIMDJSON_FUZZ_LDFLAGS "" CACHE STRING "LDFLAGS for the fuzz targets")
|
|
|
|
|
|
|
|
set(SOURCES
|
|
|
|
fuzz_parser.cpp
|
2020-04-13 00:47:24 +08:00
|
|
|
fuzz_minify.cpp
|
2019-11-08 23:32:43 +08:00
|
|
|
fuzz_dump.cpp
|
2019-12-28 02:42:44 +08:00
|
|
|
fuzz_print_json.cpp
|
|
|
|
fuzz_dump_raw_tape.cpp
|
|
|
|
)
|
|
|
|
|
|
|
|
add_custom_target(print_all_fuzz_targets
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo ${SOURCES}
|
2019-11-08 23:32:43 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
macro(implement_fuzzer sourcefile)
|
|
|
|
get_filename_component(basename ${sourcefile} NAME_WE)
|
|
|
|
set(name ${basename})
|
|
|
|
add_executable(${name} ${sourcefile})
|
|
|
|
if (SIMDJSON_FUZZ_LINKMAIN)
|
|
|
|
target_sources(${name} PRIVATE main.cpp)
|
|
|
|
endif ()
|
2020-04-06 07:43:37 +08:00
|
|
|
target_link_libraries(${name} PRIVATE simdjson)
|
2019-11-08 23:32:43 +08:00
|
|
|
if (SIMDJSON_FUZZ_LDFLAGS)
|
|
|
|
target_link_libraries(${name} PRIVATE ${SIMDJSON_FUZZ_LDFLAGS})
|
|
|
|
endif ()
|
|
|
|
endmacro ()
|
2019-10-29 02:46:57 +08:00
|
|
|
|
2019-11-08 23:32:43 +08:00
|
|
|
foreach (X IN ITEMS ${SOURCES})
|
|
|
|
implement_fuzzer(${X})
|
|
|
|
endforeach ()
|
2019-10-29 02:46:57 +08:00
|
|
|
|