From 35e303477c27099a10c0a62eb7a30c545d7601c3 Mon Sep 17 00:00:00 2001 From: Developer Date: Sat, 21 Mar 2026 01:20:29 -0400 Subject: [PATCH] CRITICAL FIX: Add explicit function validation and error checking to show_scan_menu FIXED: - Added explicit validation that show_scan_menu() function exists before calling - Added explicit validation that print_banner() exists before using it - Added error output if print_banner() call fails - Improved handling of empty available_scanners array (display '(None currently installed)') - Added error checking to ensure functions are available before use BEHAVIOR CHANGE: - Menu now validates dependencies before displaying - Better error messages if required functions are missing - More robust handling of library sourcing failures This should fix the issue where menu fails to display when libraries are not properly sourced. --- modules/security/malware-scanner.sh | 30 ++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/modules/security/malware-scanner.sh b/modules/security/malware-scanner.sh index 25389d2..b503e88 100755 --- a/modules/security/malware-scanner.sh +++ b/modules/security/malware-scanner.sh @@ -2361,20 +2361,33 @@ delete_standalone_sessions() { # Main scan menu show_scan_menu() { + # Ensure print_banner is available before calling it + if ! declare -f "print_banner" &>/dev/null; then + echo "ERROR: print_banner function not found" >&2 + return 1 + fi + # Build reference database once for the entire menu session if command -v build_reference_database &>/dev/null; then - echo "Building system reference database..." build_reference_database 2>/dev/null || true clear fi while true; do - print_banner "Malware Scanner" + # Call print_banner - MUST succeed + print_banner "Malware Scanner" || { + echo "ERROR: print_banner failed" >&2 + return 1 + } echo "Available Scanners:" - for scanner in "${available_scanners[@]}"; do - echo " • ${scanner^}" - done + if [ ${#available_scanners[@]} -eq 0 ]; then + echo " (None currently installed)" + else + for scanner in "${available_scanners[@]}"; do + echo " • ${scanner^}" + done + fi echo "" echo -e "${CYAN}Create New Scan:${NC}" @@ -2724,6 +2737,13 @@ main() { # Don't exit if none found - menu option 9 allows installation detect_scanners || true + # Verify show_scan_menu exists and is callable + if ! declare -f "show_scan_menu" &>/dev/null; then + echo "ERROR: show_scan_menu function not found" >&2 + return 1 + fi + + # Call the menu function show_scan_menu }