From 55c3a8dc58d74bbdd4c39585eff14985838d9896 Mon Sep 17 00:00:00 2001 From: Jertzukka Date: Wed, 8 May 2024 20:00:09 +0300 Subject: Fix incorrect max hidden volume size for file containers on CLI (#1338) Currently the maximum hidden volume size for file containers is limited by available free space on the device the file container resides on, which we do not care about. This commit changes so that only Normal volumes get their `maxVolumeSize` limited by `AvailableDiskSpace`. Also the --size=max parameter is restricted from hidden volume creation as there is no way to determine a good size as we do not mount the outer volume through the CLI process flow to determine available free space on the outer volume. --- src/Main/TextUserInterface.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src/Main') diff --git a/src/Main/TextUserInterface.cpp b/src/Main/TextUserInterface.cpp index 0de76c6b..94919296 100644 --- a/src/Main/TextUserInterface.cpp +++ b/src/Main/TextUserInterface.cpp @@ -668,7 +668,7 @@ namespace VeraCrypt { parentDir = wxT("."); } - if (wxDirExists(parentDir) && wxGetDiskSpace (parentDir, nullptr, &diskSpace)) + if (options->Type == VolumeType::Normal && wxDirExists(parentDir) && wxGetDiskSpace (parentDir, nullptr, &diskSpace)) { AvailableDiskSpace = (uint64) diskSpace.GetValue (); if (maxVolumeSize > AvailableDiskSpace) @@ -678,10 +678,13 @@ namespace VeraCrypt if (options->Size == (uint64) (-1)) { - if (AvailableDiskSpace) + if (options->Type == VolumeType::Hidden) { + throw_err (_("Please do not use maximum size for hidden volume. As we do not mount the outer volume to determine the available space, it is your responsibility to choose a value so that the hidden volume does not overlap the outer volume.")); + } + else if (AvailableDiskSpace) { // caller requesting maximum size - // we use maxVolumeSize because it is guaranteed to be less of equal to AvailableDiskSpace + // we use maxVolumeSize because it is guaranteed to be less or equal to AvailableDiskSpace for outer volumes options->Size = maxVolumeSize; } else @@ -702,14 +705,17 @@ namespace VeraCrypt throw MissingArgument (SRC_POS); uint64 multiplier = 1024 * 1024; - wxString sizeStr = AskString (options->Type == VolumeType::Hidden ? _("\nEnter hidden volume size (sizeK/size[M]/sizeG/sizeT/max): ") : _("\nEnter volume size (sizeK/size[M]/sizeG.sizeT/max): ")); + wxString sizeStr = AskString (options->Type == VolumeType::Hidden ? _("\nEnter hidden volume size (sizeK/size[M]/sizeG/sizeT): ") : _("\nEnter volume size (sizeK/size[M]/sizeG.sizeT/max): ")); if (sizeStr.CmpNoCase(wxT("max")) == 0) { multiplier = 1; - if (AvailableDiskSpace) + if (options->Type == VolumeType::Hidden) { + throw_err (_("Please do not use maximum size for hidden volume. As we do not mount the outer volume to determine the available space, it is your responsibility to choose a value so that the hidden volume does not overlap the outer volume.")); + } + else if (AvailableDiskSpace) { // caller requesting maximum size - // we use maxVolumeSize because it is guaranteed to be less of equal to AvailableDiskSpace + // we use maxVolumeSize because it is guaranteed to be less or equal to AvailableDiskSpace for outer volumes options->Size = maxVolumeSize; } else -- cgit v1.2.3