From 0c8d54f055738ef910eeaa03e7f8176c6ff44320 Mon Sep 17 00:00:00 2001 From: Uwe Seimet <48174652+uweseimet@users.noreply.github.com> Date: Wed, 12 Oct 2022 22:10:56 +0200 Subject: [PATCH] Fixed validation of full (absolute) filename (#910) * Fixed validation of full (absolute) filename * Added missing CR/LF in rasctl output --- src/raspberrypi/rascsi/localizer.cpp | 10 +++++----- src/raspberrypi/rascsi/rascsi_executor.cpp | 6 ++++-- src/raspberrypi/rasctl/rasctl_display.cpp | 2 ++ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/raspberrypi/rascsi/localizer.cpp b/src/raspberrypi/rascsi/localizer.cpp index b3446d50..cb4bf3d9 100644 --- a/src/raspberrypi/rascsi/localizer.cpp +++ b/src/raspberrypi/rascsi/localizer.cpp @@ -114,11 +114,11 @@ Localizer::Localizer() Add(LocalizationKey::ERROR_SHUTDOWN_PERMISSION, "sv", "Saknar root-rättigheter för att kunna stänga av eller starta om systemet"); Add(LocalizationKey::ERROR_SHUTDOWN_PERMISSION, "fr", "Permissions root manquantes pour extinction ou redémarrage"); Add(LocalizationKey::ERROR_SHUTDOWN_PERMISSION, "es", "Falta el permiso de root para el apagado o el reinicio"); - Add(LocalizationKey::ERROR_FILE_OPEN, "en", "Invalid or non-existing file '%1': %2"); - Add(LocalizationKey::ERROR_FILE_OPEN, "de", "Ungültige oder fehlende Datei '%1': %2"); - Add(LocalizationKey::ERROR_FILE_OPEN, "sv", "Ogiltig eller saknad fil '%1': %2"); - Add(LocalizationKey::ERROR_FILE_OPEN, "fr", "Fichier invalide ou non-existant '%1': %2"); - Add(LocalizationKey::ERROR_FILE_OPEN, "es", "Archivo inválido o inexistente '%1': %2"); + Add(LocalizationKey::ERROR_FILE_OPEN, "en", "Invalid or non-existing file '%1'"); + Add(LocalizationKey::ERROR_FILE_OPEN, "de", "Ungültige oder fehlende Datei '%1'"); + Add(LocalizationKey::ERROR_FILE_OPEN, "sv", "Ogiltig eller saknad fil '%1'"); + Add(LocalizationKey::ERROR_FILE_OPEN, "fr", "Fichier invalide ou non-existant '%1'"); + Add(LocalizationKey::ERROR_FILE_OPEN, "es", "Archivo inválido o inexistente '%1'"); Add(LocalizationKey::ERROR_BLOCK_SIZE, "en", "Invalid block size %1 bytes"); Add(LocalizationKey::ERROR_BLOCK_SIZE, "de", "Ungültige Blockgröße %1 Bytes"); Add(LocalizationKey::ERROR_BLOCK_SIZE, "sv", "Ogiltig blockstorlek: %1 byte"); diff --git a/src/raspberrypi/rascsi/rascsi_executor.cpp b/src/raspberrypi/rascsi/rascsi_executor.cpp index f7622fde..93fe7f30 100644 --- a/src/raspberrypi/rascsi/rascsi_executor.cpp +++ b/src/raspberrypi/rascsi/rascsi_executor.cpp @@ -580,11 +580,13 @@ bool RascsiExecutor::ValidateImageFile(const CommandContext& context, shared_ptr to_string(id), to_string(lun)); } - disk->Open(filepath); + if (!disk->FileExists(filepath)) { + return context.ReturnLocalizedError(LocalizationKey::ERROR_FILE_OPEN, initial_filename); + } } } catch(const io_exception& e) { - return context.ReturnLocalizedError(LocalizationKey::ERROR_FILE_OPEN, initial_filename, e.get_msg()); + return context.ReturnLocalizedError(LocalizationKey::ERROR_FILE_OPEN, initial_filename); } full_path = filepath.GetPath(); diff --git a/src/raspberrypi/rasctl/rasctl_display.cpp b/src/raspberrypi/rasctl/rasctl_display.cpp index 8d36bbdf..0f7ee855 100644 --- a/src/raspberrypi/rasctl/rasctl_display.cpp +++ b/src/raspberrypi/rasctl/rasctl_display.cpp @@ -164,6 +164,8 @@ string RasctlDisplay::DisplayDeviceTypesInfo(const PbDeviceTypesInfo& device_typ DisplayBlockSizes(s, properties); } + s << '\n'; + return s.str(); }