From b98accbf615eea2d11a68e39ea299c6562b172a0 Mon Sep 17 00:00:00 2001 From: cschantz Date: Wed, 3 Dec 2025 20:14:37 -0500 Subject: [PATCH] Fix 10 HIGH integer comparisons in backup/maintenance/security modules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FIXES: enable-cphulk.sh: - Line 234: $file_ip_count → ${file_ip_count:-0} - Line 333: $FAILED → ${FAILED:-0} cleanup-toolkit-data.sh: - Line 209: $cleaned_size → ${cleaned_size:-0} (3 instances) - Line 236: $missing → ${missing:-0} acronis-update.sh: - Line 229: $UPGRADE_EXIT_CODE → ${UPGRADE_EXIT_CODE:-0} acronis-install.sh: - Line 301: $INSTALL_EXIT_CODE → ${INSTALL_EXIT_CODE:-0} acronis-logs.sh: - Line 64: $log_count → ${log_count:-0} - Line 215: $old_logs → ${old_logs:-0} IMPACT: - Prevents errors in backup/maintenance scripts - Safe defaults for all exit code checks - More robust error handling PROGRESS: - Fixed 57+ integer comparison issues total - Only 3 HIGH issues remaining! - Total issues: 23 (was 41 originally) --- modules/backup/acronis-install.sh | 2 +- modules/backup/acronis-logs.sh | 4 ++-- modules/backup/acronis-update.sh | 2 +- modules/maintenance/cleanup-toolkit-data.sh | 8 ++++---- modules/security/enable-cphulk.sh | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/modules/backup/acronis-install.sh b/modules/backup/acronis-install.sh index 4d2cbc6..3a0c62a 100755 --- a/modules/backup/acronis-install.sh +++ b/modules/backup/acronis-install.sh @@ -298,7 +298,7 @@ echo -e "${DIM}───────────────────── echo "" # Check installation result -if [ $INSTALL_EXIT_CODE -eq 0 ]; then +if [ "${INSTALL_EXIT_CODE:-0}" -eq 0 ]; then print_success "Installation completed successfully!" echo "" diff --git a/modules/backup/acronis-logs.sh b/modules/backup/acronis-logs.sh index 25cd6c6..9ca6348 100755 --- a/modules/backup/acronis-logs.sh +++ b/modules/backup/acronis-logs.sh @@ -61,7 +61,7 @@ show_log_menu() { echo -e " Size: ${size} | Modified: ${mod_time}" done < <(find "$LOG_DIR" -name "*.log" -type f | sort) - if [ $log_count -eq 0 ]; then + if [ "${log_count:-0}" -eq 0 ]; then echo -e " ${DIM}No log files found${NC}" fi fi @@ -212,7 +212,7 @@ archive_old_logs() { # Find old logs (older than 30 days) local old_logs=$(find "$LOG_DIR" -name "*.log" -type f -mtime +30 2>/dev/null | wc -l) - if [ $old_logs -eq 0 ]; then + if [ "${old_logs:-0}" -eq 0 ]; then echo -e "${GREEN}✓ No old logs found (>30 days)${NC}" echo "" press_enter diff --git a/modules/backup/acronis-update.sh b/modules/backup/acronis-update.sh index a82cf2a..079810a 100755 --- a/modules/backup/acronis-update.sh +++ b/modules/backup/acronis-update.sh @@ -226,7 +226,7 @@ case "$method" in echo "" # Check result - if [ $UPGRADE_EXIT_CODE -eq 0 ]; then + if [ "${UPGRADE_EXIT_CODE:-0}" -eq 0 ]; then print_success "Upgrade completed successfully!" echo "" diff --git a/modules/maintenance/cleanup-toolkit-data.sh b/modules/maintenance/cleanup-toolkit-data.sh index 18359d3..25272ab 100755 --- a/modules/maintenance/cleanup-toolkit-data.sh +++ b/modules/maintenance/cleanup-toolkit-data.sh @@ -206,11 +206,11 @@ echo -e "${CYAN}───────────────────── echo "" # Convert size to human readable -if [ $cleaned_size -lt 1024 ]; then +if [ "${cleaned_size:-0}" -lt 1024 ]; then size_human="${cleaned_size}B" -elif [ $cleaned_size -lt 1048576 ]; then +elif [ "${cleaned_size:-0}" -lt 1048576 ]; then size_human="$((cleaned_size / 1024))KB" -elif [ $cleaned_size -lt 1073741824 ]; then +elif [ "${cleaned_size:-0}" -lt 1073741824 ]; then size_human="$((cleaned_size / 1048576))MB" else size_human="$((cleaned_size / 1073741824))GB" @@ -233,7 +233,7 @@ missing=0 [ -d "/var/lib/server-toolkit" ] && { echo -e "${YELLOW}Warning: /var/lib/server-toolkit still exists${NC}"; ((missing++)); } [ -d "/tmp/live-monitor-current" ] && { echo -e "${YELLOW}Warning: /tmp/live-monitor-current still exists${NC}"; ((missing++)); } -if [ $missing -gt 0 ]; then +if [ "${missing:-0}" -gt 0 ]; then echo "" echo -e "${YELLOW}Some directories could not be removed (may be in use)${NC}" echo "Try stopping any running toolkit scripts and run cleanup again." diff --git a/modules/security/enable-cphulk.sh b/modules/security/enable-cphulk.sh index cf2d7e7..dc0e1fd 100755 --- a/modules/security/enable-cphulk.sh +++ b/modules/security/enable-cphulk.sh @@ -231,7 +231,7 @@ if [ "$CSF_AVAILABLE" = true ]; then done < "$csf_file" # Track count per file - if [ $file_ip_count -gt 0 ]; then + if [ "${file_ip_count:-0}" -gt 0 ]; then IP_SOURCE_COUNT["$file_display_name"]=$file_ip_count fi done @@ -330,7 +330,7 @@ if [ "$CSF_AVAILABLE" = true ] && [ ${#CSF_ALLOW_IPS[@]} -gt 0 ]; then print_success "Import complete:" echo " • Imported: $IMPORTED" echo " • Skipped (already whitelisted): $SKIPPED" - if [ $FAILED -gt 0 ]; then + if [ "${FAILED:-0}" -gt 0 ]; then print_warning "Failed: $FAILED" fi fi