Skip to content

Commit a4e2d2c

Browse files
iavclaude
andcommitted
(#9400 P1b) configuration: change-tracking: replace eval with nameref
The original code used eval to read an array variable with a dynamic name: eval "var_value=\"\${${var_name}[@]}\"" # sorry eval works, but it executes arbitrary code — if $var_name were ever a crafted string, it could inject commands. bash 4.3+ nameref (local -n) creates an alias to the variable named in $var_name without executing any code: local -n _ct_arr_ref="${var_name}" var_value="${_ct_arr_ref[*]}" unset -n _ct_arr_ref unset -n removes only the alias (not the referenced array), preventing "already a nameref" warnings on subsequent loop iterations. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 02f70dd commit a4e2d2c

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

lib/functions/configuration/change-tracking.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ function track_config_variables() {
1818

1919
# if the var is an array...
2020
if [[ "${array_values:-"no"}" == "yes" ]]; then
21-
eval "var_value=\"\${${var_name}[@]}\"" # sorry
21+
# bash nameref (local -n) creates an alias for the variable named in $var_name —
22+
# no eval needed, no code-injection risk. Works for arrays and scalars alike.
23+
# unset -n removes the alias only (not the referenced array) to avoid
24+
# "already a nameref" warnings on the next loop iteration.
25+
local -n _ct_arr_ref="${var_name}"
26+
var_value="${_ct_arr_ref[*]}"
27+
unset -n _ct_arr_ref
2228
value_text="${blue_color:-}(${bright_blue_color:-}${var_value}${blue_color:-})"
2329
else
2430
var_value="${!var_name}"

0 commit comments

Comments
 (0)