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
@@ -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))