From b6e698b376dd5754f7855fb8666644dd2b7b5739 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Mon, 23 Dec 2024 23:10:37 +0100 Subject: Linux/macOS: check if volume doesn't exist before starting the mount operation. --- src/Main/GraphicUserInterface.cpp | 13 +++++++++++++ src/Main/TextUserInterface.cpp | 12 ++++++++++++ 2 files changed, 25 insertions(+) (limited to 'src') diff --git a/src/Main/GraphicUserInterface.cpp b/src/Main/GraphicUserInterface.cpp index 1cb62671..b8098e95 100644 --- a/src/Main/GraphicUserInterface.cpp +++ b/src/Main/GraphicUserInterface.cpp @@ -826,6 +826,19 @@ namespace VeraCrypt return volume; } + + // check if the volume path exists using stat function. Only ENOENT error is handled to exclude permission denied error + struct stat statBuf; + if (stat (string (*options.Path).c_str(), &statBuf) != 0) + { + if (errno == ENOENT) + { + SystemException ex (SRC_POS); + ShowError (ex); + return volume; + } + } + try { if ((!options.Password || options.Password->IsEmpty()) diff --git a/src/Main/TextUserInterface.cpp b/src/Main/TextUserInterface.cpp index bc3f6f5a..5dd778a0 100644 --- a/src/Main/TextUserInterface.cpp +++ b/src/Main/TextUserInterface.cpp @@ -1335,6 +1335,18 @@ namespace VeraCrypt return volume; } + // check if the volume path exists using stat function. Only ENOENT error is handled to exclude permission denied error + struct stat statBuf; + if (stat (string (*options.Path).c_str(), &statBuf) != 0) + { + if (errno == ENOENT) + { + SystemException ex (SRC_POS); + ShowError (ex); + return volume; + } + } + // Mount point if (!options.MountPoint && !options.NoFilesystem) options.MountPoint.reset (new DirectoryPath (AskString (_("Enter mount directory [default]: ")))); -- cgit v1.2.3