Skip to content

Commit

Permalink
cmake: add protection flags against dll injection
Browse files Browse the repository at this point in the history
  • Loading branch information
avmanerikar committed Sep 10, 2024
1 parent 626a213 commit a2bbbf1
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions cmake/SDL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,21 @@ if(UNIX)
endif()
elseif(MSVC AND ${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
set(CMAKE_CCXX_FLAGS "/guard:cf")
endif()

# For a Windows build, a malicious DLL can be injected because of the
# uncontrolled search order for load-time linked libraries defined for a
# Windows setting. The following cmake flags change the search order so that
# DLLs are loaded from the current working directory only if it is under a path
# in the Safe Load List.
if(WIN32)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
# add Clang++ specific flags
append(CMAKE_EXE_LINKER_FLAGS "-Xlinker /DEPENDENTLOADFLAG:0x2000")
append(CMAKE_SHARED_LINKER_FLAGS "-Xlinker /DEPENDENTLOADFLAG:0x2000")
else()
# Default to MSVC-style definition
append(CMAKE_EXE_LINKER_FLAGS "/DEPENDENTLOADFLAG:0x2000")
append(CMAKE_SHARED_LINKER_FLAGS "/DEPENDENTLOADFLAG:0x2000")
endif()
endif()

0 comments on commit a2bbbf1

Please sign in to comment.