From 84bf540c1c23ecda50d62c9d018023e86c75bdab Mon Sep 17 00:00:00 2001 From: Tw93 Date: Sun, 11 Jan 2026 10:03:12 +0800 Subject: [PATCH] fix: safeguard empty array iterations for bash 3.2 compatibility --- lib/clean/apps.sh | 16 ++++++++++------ lib/manage/whitelist.sh | 16 +++++++++------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/lib/clean/apps.sh b/lib/clean/apps.sh index 694238c..6a11794 100644 --- a/lib/clean/apps.sh +++ b/lib/clean/apps.sh @@ -135,9 +135,11 @@ scan_installed_apps() { ) & pids+=($!) debug_log "Waiting for ${#pids[@]} background processes: ${pids[*]}" - for pid in "${pids[@]}"; do - wait "$pid" 2> /dev/null || true - done + if [[ ${#pids[@]} -gt 0 ]]; then + for pid in "${pids[@]}"; do + wait "$pid" 2> /dev/null || true + done + fi debug_log "All background processes completed" cat "$scan_tmp_dir"/*.txt >> "$installed_bundles" 2> /dev/null || true safe_remove "$scan_tmp_dir" true @@ -279,8 +281,9 @@ clean_orphaned_app_data() { for pat in "${pattern_arr[@]}"; do file_patterns+=("$base_path/$pat") done - for item_path in "${file_patterns[@]}"; do - local iteration_count=0 + if [[ ${#file_patterns[@]} -gt 0 ]]; then + for item_path in "${file_patterns[@]}"; do + local iteration_count=0 for match in $item_path; do [[ -e "$match" ]] || continue ((iteration_count++)) @@ -301,7 +304,8 @@ clean_orphaned_app_data() { ((total_orphaned_kb += size_kb)) fi done - done + done + fi done stop_section_spinner if [[ $orphaned_count -gt 0 ]]; then diff --git a/lib/manage/whitelist.sh b/lib/manage/whitelist.sh index e648e9e..41f3ade 100755 --- a/lib/manage/whitelist.sh +++ b/lib/manage/whitelist.sh @@ -248,13 +248,15 @@ is_whitelisted() { return 1 fi - for existing in "${CURRENT_WHITELIST_PATTERNS[@]}"; do - local existing_expanded="${existing/#\~/$HOME}" - # Only use exact string match to prevent glob expansion security issues - if [[ "$check_pattern" == "$existing_expanded" ]]; then - return 0 - fi - done + if [[ ${#CURRENT_WHITELIST_PATTERNS[@]} -gt 0 ]]; then + for existing in "${CURRENT_WHITELIST_PATTERNS[@]}"; do + local existing_expanded="${existing/#\~/$HOME}" + # Only use exact string match to prevent glob expansion security issues + if [[ "$check_pattern" == "$existing_expanded" ]]; then + return 0 + fi + done + fi return 1 }