From 44673e94c6ab7d9256806753c3fc692cf627708d Mon Sep 17 00:00:00 2001 From: Martin Wimpress Date: Tue, 19 Oct 2021 23:39:44 +0100 Subject: [PATCH] Add guards for $EFI_CODE and $EFI_VARS Make sure that $EFI_VARS references an actual writable file. Check if $EFI_CODE reference a symlink, if so resolve the the real file. --- quickemu | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/quickemu b/quickemu index 6cec593..441481c 100755 --- a/quickemu +++ b/quickemu @@ -381,7 +381,6 @@ function vm_boot() { echo " Please install OVMF firmware." exit 1 fi - BOOT_STATUS="EFI (${guest_os^}), OVMF ($(basename "${EFI_CODE}")), SecureBoot (${secureboot})." ;; *) if [ -e "/usr/share/OVMF/OVMF_CODE_4M.fd" ]; then @@ -398,9 +397,26 @@ function vm_boot() { echo " Please install OVMF firmware." exit 1 fi - BOOT_STATUS="EFI (${guest_os^}), OVMF ($(basename "${EFI_CODE}")), SecureBoot (${secureboot})." ;; esac + + # Make sure EFI_VARS references an actual, writeable, file + if [ ! -f "${EFI_VARS}" ] || [ ! -w "${EFI_VARS}" ]; then + echo " - EFI: ERROR! ${EFI_VARS} is not a regular file or not writeable." + echo " Deleting ${EFI_VARS}. Please re-run quickemu." + rm -f "${EFI_VARS}" + exit 1 + fi + + # If EFI firmware path is a symlink, resolve it to a real file. + #if [ -L "${EFI_CODE}" ]; then + if true; then + echo " - EFI: WARNING! ${EFI_CODE} is a symlink." + echo -n " Resolving to... " + EFI_CODE=$(realpath "${EFI_CODE}") + echo "${EFI_CODE}" + fi + BOOT_STATUS="EFI (${guest_os^}), OVMF ($(basename "${EFI_CODE}")), SecureBoot (${secureboot})." else BOOT_STATUS="Legacy BIOS (${guest_os^})" secureboot="off"