Unix: preserve protection and keyfile exception types

Check PasswordIncorrect subclasses before the base class in both UI
exception handlers. This prevents slicing and preserves the specific
protection and keyfile error messages.
This commit is contained in:
Mounir IDRASSI
2026-09-25 11:39:11 +02:00
parent 527158e482
commit d3bb431de2
2 changed files with 4 additions and 2 deletions
+2 -1
View File
@@ -33,12 +33,13 @@ namespace VeraCrypt
void WaitDialog::ThrowException(Exception* ex) void WaitDialog::ThrowException(Exception* ex)
{ {
#define VC_CONVERT_EXCEPTION(NAME) if (dynamic_cast<NAME*> (ex)) throw (NAME&) *ex; #define VC_CONVERT_EXCEPTION(NAME) if (dynamic_cast<NAME*> (ex)) throw (NAME&) *ex;
VC_CONVERT_EXCEPTION (PasswordIncorrect); // Handle PasswordIncorrect subclasses before the base class to avoid slicing.
VC_CONVERT_EXCEPTION (PasswordKeyfilesIncorrect); VC_CONVERT_EXCEPTION (PasswordKeyfilesIncorrect);
VC_CONVERT_EXCEPTION (PasswordOrKeyboardLayoutIncorrect); VC_CONVERT_EXCEPTION (PasswordOrKeyboardLayoutIncorrect);
VC_CONVERT_EXCEPTION (PasswordOrMountOptionsIncorrect); VC_CONVERT_EXCEPTION (PasswordOrMountOptionsIncorrect);
VC_CONVERT_EXCEPTION (ProtectionPasswordIncorrect); VC_CONVERT_EXCEPTION (ProtectionPasswordIncorrect);
VC_CONVERT_EXCEPTION (ProtectionPasswordKeyfilesIncorrect); VC_CONVERT_EXCEPTION (ProtectionPasswordKeyfilesIncorrect);
VC_CONVERT_EXCEPTION (PasswordIncorrect);
VC_CONVERT_EXCEPTION (PasswordEmpty); VC_CONVERT_EXCEPTION (PasswordEmpty);
VC_CONVERT_EXCEPTION (PasswordTooLong); VC_CONVERT_EXCEPTION (PasswordTooLong);
VC_CONVERT_EXCEPTION (PasswordUTF8TooLong); VC_CONVERT_EXCEPTION (PasswordUTF8TooLong);
+2 -1
View File
@@ -1872,12 +1872,13 @@ const FileManager fileManagers[] = {
void UserInterface::ThrowException (Exception* ex) void UserInterface::ThrowException (Exception* ex)
{ {
VC_CONVERT_EXCEPTION (PasswordIncorrect); // Handle PasswordIncorrect subclasses before the base class to avoid slicing.
VC_CONVERT_EXCEPTION (PasswordKeyfilesIncorrect); VC_CONVERT_EXCEPTION (PasswordKeyfilesIncorrect);
VC_CONVERT_EXCEPTION (PasswordOrKeyboardLayoutIncorrect); VC_CONVERT_EXCEPTION (PasswordOrKeyboardLayoutIncorrect);
VC_CONVERT_EXCEPTION (PasswordOrMountOptionsIncorrect); VC_CONVERT_EXCEPTION (PasswordOrMountOptionsIncorrect);
VC_CONVERT_EXCEPTION (ProtectionPasswordIncorrect); VC_CONVERT_EXCEPTION (ProtectionPasswordIncorrect);
VC_CONVERT_EXCEPTION (ProtectionPasswordKeyfilesIncorrect); VC_CONVERT_EXCEPTION (ProtectionPasswordKeyfilesIncorrect);
VC_CONVERT_EXCEPTION (PasswordIncorrect);
VC_CONVERT_EXCEPTION (PasswordEmpty); VC_CONVERT_EXCEPTION (PasswordEmpty);
VC_CONVERT_EXCEPTION (PasswordTooLong); VC_CONVERT_EXCEPTION (PasswordTooLong);
VC_CONVERT_EXCEPTION (PasswordUTF8TooLong); VC_CONVERT_EXCEPTION (PasswordUTF8TooLong);