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:
+1
-1
@@ -678,7 +678,7 @@ analyze_domain_php() {
|
|||||||
if [ -n "$pool_config" ] && [ -f "$pool_config" ]; then
|
if [ -n "$pool_config" ] && [ -f "$pool_config" ]; then
|
||||||
current_max_children=$(grep "^pm.max_children" "$pool_config" | awk -F'=' '{print $2}' | tr -d ' ')
|
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 " 1. Adjust pm.max_children from $current_max_children to $recommended"
|
||||||
echo " Reason: $reason"
|
echo " Reason: $reason"
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -504,7 +504,7 @@ optimize_domain() {
|
|||||||
|
|
||||||
if [ -n "$pool_config" ] && [ -f "$pool_config" ]; then
|
if [ -n "$pool_config" ] && [ -f "$pool_config" ]; then
|
||||||
# Apply max_children change if recommended
|
# 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
|
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"
|
cecho " ${GREEN}✓${NC} Set pm.max_children = $recommended_max_children"
|
||||||
changes_made=$((changes_made + 1))
|
changes_made=$((changes_made + 1))
|
||||||
|
|||||||
Reference in New Issue
Block a user