From 95c5cfdf619e88b7202f88b28e9f7c4fb9e89cba Mon Sep 17 00:00:00 2001 From: Developer Date: Tue, 21 Apr 2026 19:46:46 -0400 Subject: [PATCH] Fix: Improve archive validation and variable scope in Maldet installer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue: Archive found and copied successfully ('✓ Archive ready for extraction') but then fails extraction validation ('✗ No valid archive available for extraction'). Root cause: Variable scope - temp_file set inside offline archive block wasn't reliably persisting to extraction check. Solution: - Immediately validate archive after copy (verify file exists and non-empty) - Set download_success=true/false based on actual validation result - Add clearer error messages showing which variable failed check - Simplify extraction condition check Now archives are validated right after copying, so no scope issues. --- modules/security/malware-scanner.sh | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/modules/security/malware-scanner.sh b/modules/security/malware-scanner.sh index b1ccc6c..cdef99f 100755 --- a/modules/security/malware-scanner.sh +++ b/modules/security/malware-scanner.sh @@ -349,13 +349,15 @@ install_maldet_only() { if [ -n "$local_archive" ]; then echo "" echo "Using pre-downloaded archive..." - if cp "$local_archive" /tmp/maldetect-offline.tar.gz 2>/dev/null; then - temp_file="/tmp/maldetect-offline.tar.gz" + temp_file="/tmp/maldetect-offline.tar.gz" + if cp "$local_archive" "$temp_file" 2>/dev/null && [ -f "$temp_file" ] && [ -s "$temp_file" ]; then download_success=true best_source="offline-archive" echo -e "${GREEN}✓ Archive ready for extraction${NC}" else - echo -e "${RED}✗ Failed to copy archive${NC}" + echo -e "${RED}✗ Failed to copy or validate archive${NC}" + download_success=false + temp_file="" fi else echo -e "${RED}✗ No local archive found${NC}" @@ -380,8 +382,12 @@ install_maldet_only() { fi fi - # At this point, download_success should be true with temp_file set - if [ "$download_success" = true ] && [ -f "$temp_file" ] && [ -s "$temp_file" ]; then + # Extract and install if we have a valid archive + if [ "$download_success" = true ]; then + if [ ! -f "$temp_file" ] || [ ! -s "$temp_file" ]; then + echo -e "${RED}✗ Archive file missing or empty: $temp_file${NC}" + return 1 + fi echo "Installing from $best_source..." echo ""