Skip to content

Commit da4f826

Browse files
committed
MDEV-5730 enhance security using special compilation options
-Wl,-z,relro,-z,now -pie -fstack-protector --param=ssp-buffer-size=4 -D_FORTIFY_SOURCE=2
1 parent 6c0e3ef commit da4f826

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,20 @@ IF (WITH_ASAN)
199199
ENDIF()
200200
ENDIF()
201201

202+
OPTION(SECURITY_HARDENED "Use security-enhancing compiler features (stack protector, relro, etc)" ON)
203+
IF(SECURITY_HARDENED)
204+
# security-enhancing flags
205+
MY_CHECK_AND_SET_COMPILER_FLAG("-pie -fPIC")
206+
MY_CHECK_AND_SET_COMPILER_FLAG("-Wl,-z,relro,-z,now")
207+
MY_CHECK_AND_SET_COMPILER_FLAG("-fstack-protector --param=ssp-buffer-size=4")
208+
209+
# sometimes _FORTIFY_SOURCE is predefined
210+
INCLUDE(CheckSymbolExists)
211+
CHECK_SYMBOL_EXISTS(_FORTIFY_SOURCE "" HAVE_FORTIFY_SOURCE)
212+
IF(NOT HAVE_FORTIFY_SOURCE)
213+
ADD_DEFINITIONS(-D_FORTIFY_SOURCE=2)
214+
ENDIF()
215+
ENDIF()
202216

203217
OPTION(ENABLE_DEBUG_SYNC "Enable debug sync (debug builds only)" ON)
204218
IF(ENABLE_DEBUG_SYNC)

0 commit comments

Comments
 (0)