Commit a4e2d2c
(#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
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
22 | 28 | | |
23 | 29 | | |
24 | 30 | | |
| |||
0 commit comments