Skip to content

Commit af5359b

Browse files
libpsl-native: Fix _FORTIFY_SOURCE macros (#88)
This commit fixes the mistake in the `_FORTIFY_SOURCE` macro where it was not prefixed with underscore while it has to be (see e.g. https://github.com/search?q=repo%3Abminor%2Fglibc%20FORTIFY_SOURCE&type=code). Additionally, to make this macro add extra security, one has to enable optimizations. I am not sure if the build system enables them, but it is worth double checking that as well. Overall, I would recommend using `-D_FORTIFY_SOURCE=3` with `-O2` or `-O3`. (The fortify source level 3 was added recently and you can read more about it here: https://developers.redhat.com/blog/2021/04/16/broadening-compiler-checks-for-buffer-overflows-in-_fortify_source). Remove superfluous `-O2` flag, since CMake adds `-O3` for `Release` builds anyway. Co-authored-by: Andy Jordan <andy.jordan@microsoft.com>
1 parent b653177 commit af5359b

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

src/libpsl-native/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ project(PSL-NATIVE)
33

44
# Can't use add_compile_options with 2.8.11
55
set(CMAKE_BUILD_TYPE "Release")
6-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Werror -fstack-protector-strong -fpie -DFORTIFY_SOURCE=2 -O2")
6+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Werror -fstack-protector-strong -fpie -D_FORTIFY_SOURCE=2")
77

88
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
99
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,relro,-z,now")

src/libpsl-native/arm.toolchain.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
set(CMAKE_SYSTEM_NAME Linux)
22
set(CMAKE_SYSTEM_VERSION 1)
33
set(CMAKE_SYSTEM_PROCESSOR armv7l)
4-
set(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++ -fstack-protector-strong -fpie -DFORTIFY_SOURCE=2 -O2)
4+
set(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++ -fstack-protector-strong -fpie -D_FORTIFY_SOURCE=2)
55
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-z,relro,-z,now")
66
set(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc)
77

src/libpsl-native/arm64.toolchain.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
set(CMAKE_SYSTEM_NAME Linux)
22
set(CMAKE_SYSTEM_VERSION 1)
33
set(CMAKE_SYSTEM_PROCESSOR aarch64)
4-
set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++ -fstack-protector-strong -fpie -DFORTIFY_SOURCE=2 -O2)
4+
set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++ -fstack-protector-strong -fpie -D_FORTIFY_SOURCE=2)
55
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-z,relro,-z,now")
66
set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc)
77

0 commit comments

Comments
 (0)