VeraCrypt
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2018-08-15 00:47:11 +0200
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2018-08-15 14:44:34 +0200
commitc2b69b248c004e097ffc1aa4c0dde0ddd0ba54f7 (patch)
tree4ee8316df5e409493c3db3a81f3f2117551330e3
parent6cdcbac305bb34b90d0864879ce940463fae9730 (diff)
downloadVeraCrypt-c2b69b248c004e097ffc1aa4c0dde0ddd0ba54f7.tar.gz
VeraCrypt-c2b69b248c004e097ffc1aa4c0dde0ddd0ba54f7.zip
Windows: Add various checks and replace STL code after Coverity report
-rw-r--r--src/Common/BootEncryption.cpp2
-rw-r--r--src/Common/Dlgcode.c34
-rw-r--r--src/Mount/Mount.c6
3 files changed, 18 insertions, 24 deletions
diff --git a/src/Common/BootEncryption.cpp b/src/Common/BootEncryption.cpp
index 8034d865..c3c54d09 100644
--- a/src/Common/BootEncryption.cpp
+++ b/src/Common/BootEncryption.cpp
@@ -811,7 +811,7 @@ namespace VeraCrypt
DWORD effectiveSize = min (bytesRead, remainingSize);
memcpy (buffer, ReadBuffer, effectiveSize);
offset.QuadPart = - ((LONGLONG) bytesRead) + (LONGLONG) effectiveSize;
- SetFilePointerEx (Handle, offset, NULL, FILE_CURRENT);
+ throw_sys_if (!SetFilePointerEx (Handle, offset, NULL, FILE_CURRENT));
return alignedSize + effectiveSize;
}
else
diff --git a/src/Common/Dlgcode.c b/src/Common/Dlgcode.c
index 3485eb0b..88713ac1 100644
--- a/src/Common/Dlgcode.c
+++ b/src/Common/Dlgcode.c
@@ -11960,10 +11960,8 @@ std::vector <HostDevice> GetAvailableHostDevices (bool noDeviceProperties, bool
{
for (int partNumber = 0; partNumber < MAX_HOST_PARTITION_NUMBER; partNumber++)
{
- wstringstream strm;
- strm << L"\\Device\\Harddisk" << devNumber << L"\\Partition" << partNumber;
- wstring devPathStr (strm.str());
- const wchar_t *devPath = devPathStr.c_str();
+ WCHAR devPath[32];
+ StringCbPrintfW (devPath, sizeof (devPath), L"\\Device\\Harddisk%d\\Partition%d", devNumber, partNumber);
OPEN_TEST_STRUCT openTest = {0};
if (!OpenDevice (devPath, &openTest, detectUnencryptedFilesystems && partNumber != 0, FALSE))
@@ -12003,7 +12001,7 @@ std::vector <HostDevice> GetAvailableHostDevices (bool noDeviceProperties, bool
{
DISK_GEOMETRY_EX geometry;
- int driveNumber = GetDiskDeviceDriveLetter ((wchar_t *) devPathStr.c_str());
+ int driveNumber = GetDiskDeviceDriveLetter (devPath);
if (driveNumber >= 0)
{
@@ -12064,10 +12062,8 @@ std::vector <HostDevice> GetAvailableHostDevices (bool noDeviceProperties, bool
{
for (int devNumber = 0; devNumber < 256; devNumber++)
{
- wstringstream strm;
- strm << L"\\Device\\HarddiskVolume" << devNumber;
- wstring devPathStr (strm.str());
- const wchar_t *devPath = devPathStr.c_str();
+ WCHAR devPath[32];
+ StringCbPrintfW (devPath, sizeof (devPath), L"\\Device\\HarddiskVolume%d", devNumber);
OPEN_TEST_STRUCT openTest = {0};
if (!OpenDevice (devPath, &openTest, detectUnencryptedFilesystems, FALSE))
@@ -12086,7 +12082,7 @@ std::vector <HostDevice> GetAvailableHostDevices (bool noDeviceProperties, bool
if (!noDeviceProperties)
{
- int driveNumber = GetDiskDeviceDriveLetter ((wchar_t *) devPathStr.c_str());
+ int driveNumber = GetDiskDeviceDriveLetter (devPath);
if (driveNumber >= 0)
{
@@ -12112,10 +12108,8 @@ std::vector <HostDevice> GetAvailableHostDevices (bool noDeviceProperties, bool
void AddDeviceToList (std::vector<HostDevice>& devices, int devNumber, int partNumber)
{
- wstringstream strm;
- strm << L"\\Device\\Harddisk" << devNumber << L"\\Partition" << partNumber;
- wstring devPathStr (strm.str());
- const wchar_t *devPath = devPathStr.c_str();
+ WCHAR devPath[64];
+ StringCbPrintfW (devPath, sizeof (devPath), L"\\Device\\Harddisk%d\\Partition%d", devNumber, partNumber);
HostDevice device;
device.SystemNumber = devNumber;
@@ -12391,10 +12385,8 @@ void UpdateMountableHostDeviceList ()
{
for (int devNumber = 0; devNumber < 256; devNumber++)
{
- wstringstream strm;
- strm << L"\\Device\\HarddiskVolume" << devNumber;
- wstring devPathStr (strm.str());
- const wchar_t *devPath = devPathStr.c_str();
+ WCHAR devPath[32];
+ StringCbPrintfW (devPath, sizeof (devPath), L"\\Device\\HarddiskVolume%d", devNumber);
OPEN_TEST_STRUCT openTest = {0};
if (!OpenDevice (devPath, &openTest, FALSE, FALSE))
@@ -12451,10 +12443,8 @@ wstring FindDeviceByVolumeID (const BYTE volumeID [VOLUME_ID_SIZE], BOOL bFromSe
{
for (int partNumber = 0; partNumber < MAX_HOST_PARTITION_NUMBER; partNumber++)
{
- wstringstream strm;
- strm << L"\\Device\\Harddisk" << devNumber << L"\\Partition" << partNumber;
- wstring devPathStr (strm.str());
- const wchar_t *devPath = devPathStr.c_str();
+ WCHAR devPath[32];
+ StringCbPrintfW (devPath, sizeof (devPath), L"\\Device\\Harddisk%d\\Partition%d", devNumber, partNumber);
OPEN_TEST_STRUCT openTest = {0};
if (OpenDevice (devPath, &openTest, TRUE, TRUE)
diff --git a/src/Mount/Mount.c b/src/Mount/Mount.c
index da1d74f9..1d80e030 100644
--- a/src/Mount/Mount.c
+++ b/src/Mount/Mount.c
@@ -4634,7 +4634,11 @@ BOOL CALLBACK TravelerDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
}
StringCbPrintfW (srcPath, sizeof(srcPath), L"%s\\Languages\\Language.%hs.xml", appDir, GetPreferredLangId ());
StringCbPrintfW (dstPath, sizeof(dstPath), L"%s\\VeraCrypt\\Languages\\Language.%hs.xml", dstDir, GetPreferredLangId ());
- TCCopyFile (srcPath, dstPath);
+ if (!TCCopyFile (srcPath, dstPath))
+ {
+ handleWin32Error (hwndDlg, SRC_POS);
+ goto stop;
+ }
}
// AutoRun