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.
This commit is contained in:
cschantz
2025-12-11 21:34:16 -05:00
parent 9f2a0cdbe8
commit 21738f8d2b
2 changed files with 2 additions and 2 deletions
+1 -1
View File
@@ -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