88endif ()
99
1010include (ExternalProject)
11+ find_package (Protobuf REQUIRED)
12+
13+ set (CURL_FUZZER_PROTO ${CMAKE_CURRENT_SOURCE_DIR} /schemas/curl_fuzzer.proto)
14+ protobuf_generate_cpp(CURL_FUZZER_PROTO_SRCS CURL_FUZZER_PROTO_HDRS
15+ ${CURL_FUZZER_PROTO} )
16+
17+ add_library (curl_fuzzer_proto STATIC ${CURL_FUZZER_PROTO_SRCS} )
18+ target_include_directories (curl_fuzzer_proto PUBLIC
19+ ${CMAKE_CURRENT_BINARY_DIR}
20+ ${PROTOBUF_INCLUDE_DIRS} )
21+ target_link_libraries (curl_fuzzer_proto PUBLIC ${PROTOBUF_LIBRARIES} )
22+
23+ # Install libprotobuf-mutator
24+ #
25+ # renovate: datasource=github-tags depName=google/libprotobuf-mutator
26+ set (LIB_PROTO_MUTATOR_TAG master)
27+ set (LIB_PROTO_MUTATOR_INSTALL_DIR ${CMAKE_BINARY_DIR} /libprotobuf-mutator-install )
28+ set (LIB_PROTO_MUTATOR_INCLUDE_DIR ${LIB_PROTO_MUTATOR_INSTALL_DIR} /include )
29+ set (LIB_PROTO_MUTATOR_STATIC_LIB ${LIB_PROTO_MUTATOR_INSTALL_DIR} /lib/libprotobuf-mutator.a)
30+ set (LIB_PROTO_MUTATOR_FUZZER_LIB ${LIB_PROTO_MUTATOR_INSTALL_DIR} /lib/libprotobuf-mutator-libfuzzer.a)
31+
32+ ExternalProject_Add(libprotobuf_mutator_external
33+ GIT_REPOSITORY https://github.com/google/libprotobuf-mutator.git
34+ GIT_TAG ${LIB_PROTO_MUTATOR_TAG}
35+ PREFIX ${CMAKE_BINARY_DIR} /libprotobuf-mutator
36+ CMAKE_ARGS
37+ -DCMAKE_INSTALL_PREFIX=${LIB_PROTO_MUTATOR_INSTALL_DIR}
38+ -DBUILD_SHARED_LIBS=OFF
39+ -DLIB_PROTO_MUTATOR_DOWNLOAD_PROTOBUF=OFF
40+ -DLIB_PROTO_MUTATOR_WITH_LIBFUZZER=ON
41+ -DLIB_PROTO_MUTATOR_EXAMPLES=OFF
42+ -DLIB_PROTO_MUTATOR_TESTING=OFF
43+ -DCMAKE_POSITION_INDEPENDENT_CODE=ON
44+ BUILD_BYPRODUCTS ${LIB_PROTO_MUTATOR_STATIC_LIB} ${LIB_PROTO_MUTATOR_FUZZER_LIB}
45+ INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install
46+ DOWNLOAD_EXTRACT_TIMESTAMP TRUE
47+ DOWNLOAD_NO_PROGRESS 1
48+ )
1149
1250# Install zlib
1351#
@@ -223,7 +261,8 @@ add_custom_target(deps
223261 zstd_external
224262 libidn2_external
225263 ${GDB_DEP}
226- openldap_external
264+ openldap_external
265+ libprotobuf_mutator_external
227266)
228267
229268# Now for the main dependencies!
@@ -336,7 +375,11 @@ else()
336375endif ()
337376
338377# Common sources and flags
339- set (COMMON_SOURCES curl_fuzzer.cc curl_fuzzer_tlv.cc curl_fuzzer_callback.cc)
378+ set (COMMON_SOURCES
379+ curl_fuzzer.cc
380+ curl_fuzzer_tlv.cc
381+ curl_fuzzer_callback.cc
382+ curl_fuzzer_scenario.cc)
340383set (COMMON_FLAGS -g -DCURL_DISABLE_DEPRECATION)
341384set (COMMON_LINK_LIBS
342385 ${CURL_LIB_DIR} /libcurl.a
@@ -348,19 +391,22 @@ set(COMMON_LINK_LIBS
348391 ${OPENLDAP_STATIC_LIB_LDAP}
349392 ${OPENLDAP_STATIC_LIB_LBER}
350393 ${LIB_FUZZING_ENGINE}
394+ ${LIB_PROTO_MUTATOR_FUZZER_LIB}
395+ ${LIB_PROTO_MUTATOR_STATIC_LIB}
396+ curl_fuzzer_proto
351397 pthread
352398 m
353399)
354400set (COMMON_LINK_OPTIONS ${LIB_FUZZING_ENGINE_FLAG} )
355401
356402# Ensure that curl and its dependencies are built before the fuzzers
357- set (FUZZ_DEPS curl_external ${CURL_DEPS} ${LIB_FUZZING_ENGINE_DEP} )
403+ set (FUZZ_DEPS curl_external ${CURL_DEPS} ${LIB_FUZZING_ENGINE_DEP} curl_fuzzer_proto libprotobuf_mutator_external )
358404
359405# Helper macro to define a fuzzer target
360406macro (curl_add_fuzzer _name _proto)
361407 add_executable (${_name} ${COMMON_SOURCES} )
362408 target_compile_options (${_name} PRIVATE ${COMMON_FLAGS} -DFUZZ_PROTOCOLS_${_proto} )
363- target_include_directories (${_name} PRIVATE ${CURL_INCLUDE_DIRS} )
409+ target_include_directories (${_name} PRIVATE ${CURL_INCLUDE_DIRS} ${LIB_PROTO_MUTATOR_INCLUDE_DIR} ${LIB_PROTO_MUTATOR_INCLUDE_DIR} /libprotobuf-mutator )
364410 target_link_libraries (${_name} PRIVATE ${COMMON_LINK_LIBS} )
365411 target_link_options (${_name} PRIVATE ${COMMON_LINK_OPTIONS} )
366412 add_dependencies (${_name} ${FUZZ_DEPS} )
@@ -387,7 +433,7 @@ curl_add_fuzzer(curl_fuzzer_ws WS)
387433# BUFQ fuzzer
388434add_executable (curl_fuzzer_bufq fuzz_bufq.cc)
389435target_compile_options (curl_fuzzer_bufq PRIVATE ${COMMON_FLAGS} )
390- target_include_directories (curl_fuzzer_bufq PRIVATE ${CURL_INCLUDE_DIRS} )
436+ target_include_directories (curl_fuzzer_bufq PRIVATE ${CURL_INCLUDE_DIRS} ${LIB_PROTO_MUTATOR_INCLUDE_DIR} ${LIB_PROTO_MUTATOR_INCLUDE_DIR} /libprotobuf-mutator )
391437target_link_libraries (curl_fuzzer_bufq PRIVATE ${COMMON_LINK_LIBS} )
392438target_link_options (curl_fuzzer_bufq PRIVATE ${COMMON_LINK_OPTIONS} )
393439add_dependencies (curl_fuzzer_bufq ${FUZZ_DEPS} )
0 commit comments