From d3bb431de282eb65fac73eb9defd07d66e0b0706 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Fri, 25 Sep 2026 11:38:32 +0200 Subject: [PATCH] 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. --- src/Main/Forms/WaitDialog.cpp | 3 ++- src/Main/UserInterface.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Main/Forms/WaitDialog.cpp b/src/Main/Forms/WaitDialog.cpp index f9fc53b0..9d233e1f 100644 --- a/src/Main/Forms/WaitDialog.cpp +++ b/src/Main/Forms/WaitDialog.cpp @@ -33,12 +33,13 @@ namespace VeraCrypt void WaitDialog::ThrowException(Exception* ex) { #define VC_CONVERT_EXCEPTION(NAME) if (dynamic_cast (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 (PasswordOrKeyboardLayoutIncorrect); VC_CONVERT_EXCEPTION (PasswordOrMountOptionsIncorrect); VC_CONVERT_EXCEPTION (ProtectionPasswordIncorrect); VC_CONVERT_EXCEPTION (ProtectionPasswordKeyfilesIncorrect); + VC_CONVERT_EXCEPTION (PasswordIncorrect); VC_CONVERT_EXCEPTION (PasswordEmpty); VC_CONVERT_EXCEPTION (PasswordTooLong); VC_CONVERT_EXCEPTION (PasswordUTF8TooLong); diff --git a/src/Main/UserInterface.cpp b/src/Main/UserInterface.cpp index 8ea98fb6..2a5fd71a 100644 --- a/src/Main/UserInterface.cpp +++ b/src/Main/UserInterface.cpp @@ -1872,12 +1872,13 @@ const FileManager fileManagers[] = { 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 (PasswordOrKeyboardLayoutIncorrect); VC_CONVERT_EXCEPTION (PasswordOrMountOptionsIncorrect); VC_CONVERT_EXCEPTION (ProtectionPasswordIncorrect); VC_CONVERT_EXCEPTION (ProtectionPasswordKeyfilesIncorrect); + VC_CONVERT_EXCEPTION (PasswordIncorrect); VC_CONVERT_EXCEPTION (PasswordEmpty); VC_CONVERT_EXCEPTION (PasswordTooLong); VC_CONVERT_EXCEPTION (PasswordUTF8TooLong);