From 21738f8d2b743ae3085c1825e1ba78c99f19cba8 Mon Sep 17 00:00:00 2001 From: cschantz Date: Thu, 11 Dec 2025 21:34:16 -0500 Subject: [PATCH] Fix 2 critical safety issues - empty variable integer comparisons BUG #9: php-optimizer.sh line 507 - Unsafe integer comparison Location: modules/performance/php-optimizer.sh:507 Problem: Integer comparison -ne with potentially empty variable if [ -n "$recommended_max_children" ] && [ "$recommended_max_children" -ne "$current_max_children" ] If current_max_children is empty (pool config missing pm.max_children) Results in: bash: [: -ne: unary operator expected Solution: Added -n check for current_max_children before comparison if [ -n "$recommended_max_children" ] && [ -n "$current_max_children" ] && ... Impact: Prevents crash when FPM pool config doesn't have pm.max_children set BUG #10: php-analyzer.sh line 681 - Unsafe integer comparison Location: lib/php-analyzer.sh:681 Problem: Same issue - comparing with potentially empty current_max_children if [ "$recommended" -ne "$current_max_children" ] No check if current_max_children is empty Solution: Added -n check before comparison if [ -n "$current_max_children" ] && [ "$recommended" -ne "$current_max_children" ] Impact: Prevents crash in analyze_domain_php() report generation TESTING: Both issues would trigger when analyzing domains with FPM pools that: - Don't have pm.max_children explicitly set - Use default values - Have commented out pm.max_children Common on fresh/default PHP-FPM installations. --- lib/php-analyzer.sh | 2 +- modules/performance/php-optimizer.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/php-analyzer.sh b/lib/php-analyzer.sh index 89a85a0..ee98909 100644 --- a/lib/php-analyzer.sh +++ b/lib/php-analyzer.sh @@ -678,7 +678,7 @@ analyze_domain_php() { if [ -n "$pool_config" ] && [ -f "$pool_config" ]; then current_max_children=$(grep "^pm.max_children" "$pool_config" | awk -F'=' '{print $2}' | tr -d ' ') - if [ "$recommended" -ne "$current_max_children" ]; then + if [ -n "$current_max_children" ] && [ "$recommended" -ne "$current_max_children" ]; then echo " 1. Adjust pm.max_children from $current_max_children to $recommended" echo " Reason: $reason" fi diff --git a/modules/performance/php-optimizer.sh b/modules/performance/php-optimizer.sh index 0a53936..d5f62dd 100755 --- a/modules/performance/php-optimizer.sh +++ b/modules/performance/php-optimizer.sh @@ -504,7 +504,7 @@ optimize_domain() { if [ -n "$pool_config" ] && [ -f "$pool_config" ]; then # Apply max_children change if recommended - if [ -n "$recommended_max_children" ] && [ "$recommended_max_children" -ne "$current_max_children" ]; then + if [ -n "$recommended_max_children" ] && [ -n "$current_max_children" ] && [ "$recommended_max_children" -ne "$current_max_children" ]; then if modify_fpm_pool_setting "$pool_config" "pm.max_children" "$recommended_max_children" >/dev/null 2>&1; then cecho " ${GREEN}✓${NC} Set pm.max_children = $recommended_max_children" changes_made=$((changes_made + 1))