Skip to content

Commit 32f0f77

Browse files
committed
build: protect the integrity of user variables
`CMAKE_C_FLAGS` are not available to the build system to modify, they are strictly user controlled. Use `add_compile_options` to modify the compile flags globally.
1 parent 5c14e3b commit 32f0f77

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

CMakeLists.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,12 @@ add_compile_definitions(CMARK_USE_CMAKE_HEADERS)
7979
option(CMARK_FUZZ_QUADRATIC "Build quadratic fuzzing harness" OFF)
8080

8181
if(CMARK_FUZZ_QUADRATIC)
82-
set(FUZZER_FLAGS "-fsanitize=fuzzer-no-link,address -g")
83-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FUZZER_FLAGS}")
84-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FUZZER_FLAGS}")
85-
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${FUZZER_FLAGS}")
86-
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${FUZZER_FLAGS}")
82+
# FIXME(compnerd) why do we enable debug information?
83+
add_compile_options($<$<COMPILE_LANGUAGE:C>:-g>)
84+
# FIXME(compnerd) why do we use fuzzer-no-link with a custom variable for the
85+
# runtime rather than `-fsanitize=fuzzer,address`?
86+
add_compile_options($<$<COMPILE_LANGUAGE:C>:-fsanitize=fuzzer-no-link,address>)
87+
add_link_options($<$<COMPILE_LANGUAGE:C>:-fsanitize=address>)
8788
endif()
8889

8990
add_subdirectory(src)

0 commit comments

Comments
 (0)