From a5a828cc1a6ade1e030aceaa22ff55af4d2c12cf Mon Sep 17 00:00:00 2001 From: Frederic Marchal Date: Sun, 21 Sep 2014 10:56:21 +0200 Subject: [PATCH] Fix _FORTIFY_SOURCE redefinition error Some systems define _FORTIFY_SOURCE by default. It conflicts with our use of that macro when --enable-extraprotection is passed to the configuration script. The solution is to undefine it before redefining it with value 2. If a higher _FORTIFY_LEVEL level ever appears, it will have to be used in this program to benefit from the highest protection possible. --- CMakeLists.txt | 3 ++- configure.in | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c7fa95..a876ea5 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -340,7 +340,8 @@ ENDIF(CMAKE_SYSTEM_NAME STREQUAL "solaris") OPTION(ENABLE_EXTRA_PROTECT "Enable compile and runtime extra protections" OFF) IF(ENABLE_EXTRA_PROTECT) GET_TARGET_PROPERTY(TMPCFLAGS sarg COMPILE_FLAGS) - SET_TARGET_PROPERTIES(sarg PROPERTIES COMPILE_FLAGS "${TMPCFLAGS} -fstack-protector -D_FORTIFY_SOURCE=2 -Werror") + # _FORTIFY_SOURCE may have been defined by the system. It must be undefined before it is changed to the value we want. + SET_TARGET_PROPERTIES(sarg PROPERTIES COMPILE_FLAGS "${TMPCFLAGS} -fstack-protector -U _FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -Werror") CHECK_C_COMPILER_FLAG("-Wformat -Werror=format-security" HAVE_WERROR_FORMAT_SECURITY) IF(HAVE_WERROR_FORMAT_SECURITY) diff --git a/configure.in b/configure.in index 696886d..0ff91f3 100644 --- a/configure.in +++ b/configure.in @@ -270,7 +270,8 @@ AS_HELP_STRING([--enable-extraprotection], [Enable compile and runtime extra protections]), [ if test "$enableval"; then - CFLAGS="${CFLAGS} -fstack-protector -D_FORTIFY_SOURCE=2" + # _FORTIFY_SOURCE may have been defined by the system. It must be undefined before it is changed to the value we want. + CFLAGS="${CFLAGS} -fstack-protector -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2" if test "x$werror_status" != "xfail" ; then CFLAGS="${CFLAGS} -Werror" fi -- 2.47.2