stdenv: Harden hook runners

Instead of eval, use a "nameref" to get the name of the array and
iterate with that. Also, make the for-loop parameter a local variable,
too.
This commit is contained in:
John Ericson 2017-07-06 19:29:48 -04:00
parent 74f55017d2
commit a14cf06182

View File

@ -17,8 +17,9 @@ runHook() {
shift
local var="$hookName"
if [[ "$hookName" =~ Hook$ ]]; then var+=s; else var+=Hooks; fi
eval "local -a dummy=(\"\${$var[@]}\")"
for hook in "_callImplicitHook 0 $hookName" "${dummy[@]}"; do
local -n var
local hook
for hook in "_callImplicitHook 0 $hookName" "${var[@]}"; do
_eval "$hook" "$@"
done
return 0
@ -32,8 +33,9 @@ runOneHook() {
shift
local var="$hookName"
if [[ "$hookName" =~ Hook$ ]]; then var+=s; else var+=Hooks; fi
eval "local -a dummy=(\"\${$var[@]}\")"
for hook in "_callImplicitHook 1 $hookName" "${dummy[@]}"; do
local -n var
local hook
for hook in "_callImplicitHook 1 $hookName" "${var[@]}"; do
if _eval "$hook" "$@"; then
return 0
fi