mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 16:14:11 +01:00 
			
		
		
		
	Added json_fuzzer and msgpack_fuzzer in test suite
This commit is contained in:
		| @@ -128,7 +128,12 @@ matrix: | |||||||
|         apt: |         apt: | ||||||
|           sources: ['ubuntu-toolchain-r-test'] |           sources: ['ubuntu-toolchain-r-test'] | ||||||
|           packages: ['clang-6.0','llvm-6.0'] |           packages: ['clang-6.0','llvm-6.0'] | ||||||
|       env: SCRIPT=fuzz CLANG=6.0 |       env: SCRIPT=fuzz CLANG=6.0 FUZZER=json | ||||||
|  |     - addons: | ||||||
|  |         apt: | ||||||
|  |           sources: ['ubuntu-toolchain-r-test'] | ||||||
|  |           packages: ['clang-6.0','llvm-6.0'] | ||||||
|  |       env: SCRIPT=fuzz CLANG=6.0 FUZZER=msgpack | ||||||
| cache: | cache: | ||||||
|   directories: |   directories: | ||||||
|     - "~/.platformio" |     - "~/.platformio" | ||||||
|   | |||||||
| @@ -2,7 +2,7 @@ | |||||||
| # Copyright Benoit Blanchon 2014-2020 | # Copyright Benoit Blanchon 2014-2020 | ||||||
| # MIT License | # MIT License | ||||||
|  |  | ||||||
| cmake_minimum_required(VERSION 3.0) | cmake_minimum_required(VERSION 3.7) | ||||||
|  |  | ||||||
| project(ArduinoJson VERSION 6.15.1) | project(ArduinoJson VERSION 6.15.1) | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,26 +1,22 @@ | |||||||
| #!/bin/bash -eux | #!/bin/bash -eux | ||||||
|  |  | ||||||
| ROOT_DIR=$(dirname $0)/../../ | ROOT_DIR=$(dirname $0)/../../ | ||||||
| INCLUDE_DIR=${ROOT_DIR}/src/ |  | ||||||
| FUZZING_DIR=${ROOT_DIR}/extras/fuzzing/ | FUZZING_DIR=${ROOT_DIR}/extras/fuzzing/ | ||||||
| CXXFLAGS="-g -fprofile-instr-generate -fcoverage-mapping -fsanitize=address,undefined,fuzzer -fno-sanitize-recover=all" |  | ||||||
|  |  | ||||||
| fuzz() { | export CC="clang-${CLANG}" | ||||||
| 	NAME="$1" | export CXX="clang++-${CLANG}" | ||||||
| 	FUZZER="${NAME}_fuzzer" | cmake -DCMAKE_BUILD_TYPE=Debug . | ||||||
| 	FUZZER_CPP="${FUZZING_DIR}/${NAME}_fuzzer.cpp" |  | ||||||
| 	CORPUS_DIR="${FUZZING_DIR}/${NAME}_corpus" |  | ||||||
| 	SEED_CORPUS_DIR="${FUZZING_DIR}/${NAME}_seed_corpus" |  | ||||||
|  |  | ||||||
| 	clang++-${CLANG} ${CXXFLAGS} -o ${FUZZER} -I$INCLUDE_DIR ${FUZZER_CPP} | FUZZER_TARGET="${FUZZER}_fuzzer" | ||||||
|  | FUZZER_PATH="extras/fuzzing/${FUZZER_TARGET}" | ||||||
|  | CORPUS_DIR="${FUZZING_DIR}/${FUZZER}_corpus" | ||||||
|  | SEED_CORPUS_DIR="${FUZZING_DIR}/${FUZZER}_seed_corpus" | ||||||
|  |  | ||||||
| 	export ASAN_OPTIONS="detect_leaks=0" | cmake --build . --target $FUZZER_TARGET | ||||||
| 	export LLVM_PROFILE_FILE="${FUZZER}.profraw" |  | ||||||
| 	./${FUZZER} "$CORPUS_DIR" "$SEED_CORPUS_DIR" -max_total_time=30 -timeout=1 |  | ||||||
|  |  | ||||||
| 	llvm-profdata-${CLANG} merge -sparse ${LLVM_PROFILE_FILE} -o ${FUZZER}.profdata | export ASAN_OPTIONS="detect_leaks=0" | ||||||
| 	llvm-cov-${CLANG} report ./${FUZZER} -instr-profile=${FUZZER}.profdata | export LLVM_PROFILE_FILE="${FUZZER_TARGET}.profraw" | ||||||
| } | ${FUZZER_PATH} "$CORPUS_DIR" "$SEED_CORPUS_DIR" -max_total_time=60 -timeout=1 | ||||||
|  |  | ||||||
| fuzz json | llvm-profdata-${CLANG} merge -sparse ${LLVM_PROFILE_FILE} -o ${FUZZER_TARGET}.profdata | ||||||
| fuzz msgpack | llvm-cov-${CLANG} report ./${FUZZER_PATH} -instr-profile=${FUZZER_TARGET}.profdata | ||||||
|   | |||||||
| @@ -6,18 +6,49 @@ if(MSVC) | |||||||
| 	add_compile_options(-D_CRT_SECURE_NO_WARNINGS) | 	add_compile_options(-D_CRT_SECURE_NO_WARNINGS) | ||||||
| endif() | endif() | ||||||
|  |  | ||||||
| add_executable(msgpack_fuzzer | add_executable(msgpack_reproducer | ||||||
| 	msgpack_fuzzer.cpp | 	msgpack_fuzzer.cpp | ||||||
| 	fuzzer_main.cpp | 	reproducer.cpp | ||||||
| ) | ) | ||||||
| target_link_libraries(msgpack_fuzzer | target_link_libraries(msgpack_reproducer | ||||||
| 	ArduinoJson | 	ArduinoJson | ||||||
| ) | ) | ||||||
|  |  | ||||||
| add_executable(json_fuzzer | add_executable(json_reproducer | ||||||
| 	json_fuzzer.cpp | 	json_fuzzer.cpp | ||||||
| 	fuzzer_main.cpp | 	reproducer.cpp | ||||||
| ) | ) | ||||||
| target_link_libraries(json_fuzzer | target_link_libraries(json_reproducer | ||||||
| 	ArduinoJson | 	ArduinoJson | ||||||
| ) | ) | ||||||
|  |  | ||||||
|  | macro(add_fuzzer name)	 | ||||||
|  | 	set(FUZZER "${name}_fuzzer") | ||||||
|  | 	set(CORPUS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${name}_corpus") | ||||||
|  | 	set(SEED_CORPUS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${name}_seed_corpus") | ||||||
|  | 	add_executable("${FUZZER}" | ||||||
|  | 		"${FUZZER}.cpp" | ||||||
|  | 	) | ||||||
|  | 	target_link_libraries("${FUZZER}" | ||||||
|  | 		ArduinoJson | ||||||
|  | 	) | ||||||
|  | 	set_target_properties("${FUZZER}" | ||||||
|  | 		PROPERTIES  | ||||||
|  | 	    	COMPILE_FLAGS   | ||||||
|  | 				"-fprofile-instr-generate -fcoverage-mapping -fsanitize=address,undefined,fuzzer -fno-sanitize-recover=all" | ||||||
|  | 			LINK_FLAGS | ||||||
|  | 				"-fprofile-instr-generate -fcoverage-mapping -fsanitize=address,undefined,fuzzer -fno-sanitize-recover=all" | ||||||
|  | 	) | ||||||
|  |  | ||||||
|  | 	add_test( | ||||||
|  | 		NAME | ||||||
|  | 			"${FUZZER}" | ||||||
|  | 		COMMAND | ||||||
|  | 			"${FUZZER}" "${CORPUS_DIR}" "${SEED_CORPUS_DIR}" -max_total_time=5 -timeout=1 | ||||||
|  | 	) | ||||||
|  | endmacro() | ||||||
|  |  | ||||||
|  | if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 6) | ||||||
|  | 	add_fuzzer(json) | ||||||
|  | 	add_fuzzer(msgpack) | ||||||
|  | endif() | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user