From 4fea6403cedd19650d85d5619cd380503e01da73 Mon Sep 17 00:00:00 2001 From: audriusbuika Date: Thu, 16 Apr 2026 04:31:02 +0300 Subject: [PATCH] Windows: Fix elevated COM format drive validation and device path normalization (#1670) * Windows: Add input validation whitelists to elevated COM methods * Windows: Add drive number validation to FormatNtfs and FormatFs COM methods * Windows: Fix correctness regressions in elevated COM format and device path validation * Windows: Revert unready COM input validation; keep FormatNtfs/FormatFs return fix --- src/Common/BootEncryption.cpp | 2 +- src/Format/FormatCom.cpp | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Common/BootEncryption.cpp b/src/Common/BootEncryption.cpp index 1fb26a9a..215b1f86 100644 --- a/src/Common/BootEncryption.cpp +++ b/src/Common/BootEncryption.cpp @@ -1041,7 +1041,7 @@ namespace VeraCrypt FileOpen = false; Elevated = false; - if (path.find(L"\\\\?\\") == 0) + if (path.find(L"\\\\?\\") == 0 || path.find(L"\\\\.\\") == 0) effectivePath = path; else effectivePath = wstring (L"\\\\.\\") + path; diff --git a/src/Format/FormatCom.cpp b/src/Format/FormatCom.cpp index 738116b0..a78c96fb 100644 --- a/src/Format/FormatCom.cpp +++ b/src/Format/FormatCom.cpp @@ -92,6 +92,8 @@ public: virtual BOOL STDMETHODCALLTYPE FormatNtfs (int driveNo, int clusterSize) { + if (driveNo < 0 || driveNo > 25) + return ERROR_INVALID_PARAMETER; return ::FormatNtfs (driveNo, clusterSize, TRUE); } @@ -134,6 +136,8 @@ public: virtual BOOL STDMETHODCALLTYPE FormatFs (int driveNo, int clusterSize, int fsType) { + if (driveNo < 0 || driveNo > 25) + return ERROR_INVALID_PARAMETER; return ::FormatFs (driveNo, clusterSize, fsType, TRUE); }