Merge pull request #2017 from heinrich5991/pr_hardening

Add more hardening flags
This commit is contained in:
oy 2019-02-04 10:42:12 +01:00 committed by GitHub
commit 79fe483b83
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -133,7 +133,13 @@ endfunction()
if(NOT MSVC) if(NOT MSVC)
# Protect the stack pointer. # Protect the stack pointer.
# -fstack-protector-all doesn't work on MinGW. # -fstack-protector-all doesn't work on MinGW.
add_c_compiler_flag_if_supported(OUR_FLAGS -fstack-protector-all) add_c_compiler_flag_if_supported(OUR_FLAGS -fstack-protector-strong)
# Protect the stack from clashing.
add_c_compiler_flag_if_supported(OUR_FLAGS -fstack-clash-protection)
# Control-flow protection. Should protect against ROP.
add_c_compiler_flag_if_supported(OUR_FLAGS -fcf-protection)
# Inaccurate floating point numbers cause problems on mingw-w64-gcc when # Inaccurate floating point numbers cause problems on mingw-w64-gcc when
# compiling for x86, might cause problems elsewhere. So don't store floats # compiling for x86, might cause problems elsewhere. So don't store floats
@ -1797,6 +1803,7 @@ foreach(target ${TARGETS})
if(DEFINE_FORTIFY_SOURCE) if(DEFINE_FORTIFY_SOURCE)
target_compile_definitions(${target} PRIVATE $<$<NOT:$<CONFIG:Debug>>:_FORTIFY_SOURCE=2>) # Detect some buffer overflows. target_compile_definitions(${target} PRIVATE $<$<NOT:$<CONFIG:Debug>>:_FORTIFY_SOURCE=2>) # Detect some buffer overflows.
endif() endif()
target_compile_definitions(${target} PRIVATE _GLIBCXX_ASSERTIONS) # Enable run-time bounds-checking for the STL
endforeach() endforeach()
foreach(target ${TARGETS_LINK}) foreach(target ${TARGETS_LINK})