From 95917f160f60b93caa8bf0656d107a05b55d3096 Mon Sep 17 00:00:00 2001 From: cschantz Date: Sat, 7 Feb 2026 02:19:43 -0500 Subject: [PATCH] Fix 2 subshell shadowing issues in reference-db.sh Fixed SUBSHELL-SHADOW issues where pipe to while loops caused variable modifications to be lost: Line 173: Database iteration progress tracking - Changed from pipe: grep ... | while read -r db - To process substitution: while read -r db < <(grep ...) - Fixes: current variable increments now visible after loop Line 415: WordPress installation iteration - Changed from pipe: find ... | while read -r wp_config - To process substitution: while read -r wp_config < <(find ...) - Prevents: Variable shadowing in subshell (best practice fix) Impact: - Subshell variables now properly scoped - Progress tracking functions will work correctly - Data integrity preserved across loop iterations These were identified by CHECK 97 (SUBSHELL-SHADOW) in the enhanced QA script. Co-Authored-By: Claude Haiku 4.5 --- lib/reference-db.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/reference-db.sh b/lib/reference-db.sh index 25a5ce2..06adc68 100755 --- a/lib/reference-db.sh +++ b/lib/reference-db.sh @@ -169,8 +169,8 @@ build_databases_section() { local total_dbs=$($mysql_cmd -Ns -e "SHOW DATABASES" 2>/dev/null | grep -v "^information_schema$\|^mysql$\|^performance_schema$\|^sys$" | wc -l) local current=0 - # Use while read to safely iterate over database names (handles spaces) - $mysql_cmd -Ns -e "SHOW DATABASES" 2>/dev/null | grep -v "^information_schema$\|^mysql$\|^performance_schema$\|^sys$" | while IFS= read -r db; do + # Use process substitution instead of pipe to avoid subshell shadowing (fixes current variable loss) + while IFS= read -r db; do [ -z "$db" ] && continue current=$((current + 1)) show_progress $current $total_dbs "Indexing databases..." @@ -186,7 +186,7 @@ build_databases_section() { local table_count=$($mysql_cmd -Ns "$db" -e "SHOW TABLES" 2>/dev/null | wc -l) echo "DB|$db|$owner|$domain|$size_mb|$table_count" >> "$SYSREF_DB" - done + done < <($mysql_cmd -Ns -e "SHOW DATABASES" 2>/dev/null | grep -v "^information_schema$\|^mysql$\|^performance_schema$\|^sys$") finish_progress echo "" >> "$SYSREF_DB" @@ -411,8 +411,8 @@ build_domains_section() { build_wordpress_section() { echo "[WORDPRESS]" >> "$SYSREF_DB" - # Find all wp-config.php files and iterate safely (handles spaces in paths) - find "$SYS_USER_HOME_BASE" -name "wp-config.php" -type f 2>/dev/null | while IFS= read -r wp_config; do + # Find all wp-config.php files using process substitution (fixes subshell shadowing) + while IFS= read -r wp_config; do [ -z "$wp_config" ] && continue local wp_dir=$(dirname "$wp_config") @@ -469,7 +469,7 @@ build_wordpress_section() { # Format: WP|domain|owner|path|db_name|db_user|version|plugin_count|theme_count echo "WP|$domain|$username|$wp_dir|$db_name|$db_user|$version|$plugin_count|$theme_count" >> "$SYSREF_DB" - done + done < <(find "$SYS_USER_HOME_BASE" -name "wp-config.php" -type f 2>/dev/null) echo "" >> "$SYSREF_DB" }