mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-18 15:56:50 +01:00
44 lines
1.2 KiB
Text
44 lines
1.2 KiB
Text
hardeningFlags=(fortify stackprotector pic strictoverflow format relro bindnow)
|
|
hardeningFlags+=("${hardeningEnable[@]}")
|
|
hardeningCFlags=()
|
|
hardeningLDFlags=()
|
|
|
|
if [[ ! $hardeningDisable == "all" ]]; then
|
|
for flag in "${hardeningFlags[@]}"
|
|
do
|
|
if [[ ! "$hardeningDisable" =~ "$flag" ]]; then
|
|
case $flag in
|
|
fortify)
|
|
hardeningCFlags+=('-O2' '-D_FORTIFY_SOURCE=2')
|
|
;;
|
|
stackprotector)
|
|
hardeningCFlags+=('-fstack-protector-strong' '--param ssp-buffer-size=4')
|
|
;;
|
|
pie)
|
|
hardeningCFlags+=('-fPIE')
|
|
if [[ ! ("$*" =~ " -shared " || "$*" =~ " -static ") ]]; then
|
|
hardeningLDFlags+=('-pie')
|
|
fi
|
|
;;
|
|
pic)
|
|
hardeningCFlags+=('-fPIC')
|
|
;;
|
|
strictoverflow)
|
|
hardeningCFlags+=('-fno-strict-overflow')
|
|
;;
|
|
format)
|
|
hardeningCFlags+=('-Wformat' '-Wformat-security' '-Werror=format-security')
|
|
;;
|
|
relro)
|
|
hardeningLDFlags+=('-z relro')
|
|
;;
|
|
bindnow)
|
|
hardeningLDFlags+=('-z now')
|
|
;;
|
|
*)
|
|
echo "Hardening flag unknown: $flag"
|
|
;;
|
|
esac
|
|
fi
|
|
done
|
|
fi
|