2016-02-26 17:38:15 +00:00
|
|
|
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')
|
|
|
|
;;
|
|
|
|
pie)
|
2016-03-05 23:14:55 +00:00
|
|
|
hardeningCFlags+=('-fPIE')
|
2016-03-06 14:27:41 +00:00
|
|
|
if [[ ! "$*" =~ "-shared" ]]; then
|
|
|
|
hardeningLDFlags+=('-pie')
|
|
|
|
fi
|
2016-02-26 17:38:15 +00:00
|
|
|
;;
|
|
|
|
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
|