Skip to content

Commit 376107e

Browse files
fix: replace eval with associative array in quota_check.sh
Replace unsafe eval-based dynamic variable names with a declare -A associative array keyed by 'region:index'. This eliminates potential code-injection risks from eval and improves script maintainability. Addresses Copilot review comments on PR microsoft#131 (lines 191, 216, 226, 294 of scripts/quota_check.sh). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 9c8071b commit 376107e

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

scripts/quota_check.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ MODEL_COUNT=${#MODEL_NAMES[@]}
180180

181181
# ---- Results tracking ----
182182
declare -A REGION_STATUS
183+
declare -A RESULTS
183184
VALID_REGIONS=()
184185

185186
# ---- Main quota check loop ----
@@ -213,7 +214,7 @@ for REGION in "${REGIONS[@]}"; do
213214
echo " (Looked for: $primary_key${alt_key:+, $alt_key})"
214215
fi
215216
ALL_PASS=false
216-
eval "RESULT_${safe_region}_${i}=N_A"
217+
RESULTS["${safe_region}:${i}"]="N_A"
217218
continue
218219
fi
219220

@@ -223,7 +224,7 @@ for REGION in "${REGIONS[@]}"; do
223224
LIMIT=${LIMIT%%.*}
224225
AVAILABLE=$((LIMIT - CURRENT))
225226

226-
eval "RESULT_${safe_region}_${i}=${AVAILABLE}_${LIMIT}"
227+
RESULTS["${safe_region}:${i}"]="${AVAILABLE}_${LIMIT}"
227228

228229
if [[ "$AVAILABLE" -lt "$mcap" ]]; then
229230
echo "$display | Used: $CURRENT | Limit: $LIMIT | Available: $AVAILABLE | Need: $mcap"
@@ -291,7 +292,7 @@ for REGION in "${REGIONS[@]}"; do
291292

292293
for ((i=0; i<MODEL_COUNT; i++)); do
293294
mcap="${MODEL_CAPS[$i]}"
294-
eval "val=\${RESULT_${safe_region}_${i}:-N_A}"
295+
val="${RESULTS["${safe_region}:${i}"]:-N_A}"
295296

296297
if [[ "$val" == "N_A" ]]; then
297298
printf "%-30s" "⚠️ N/A"

0 commit comments

Comments
 (0)