mirror of
https://github.com/veracrypt/VeraCrypt.git
synced 2025-11-11 11:08:02 -06:00
Windows: Add various checks and replace STL code after Coverity report
This commit is contained in:
@@ -811,7 +811,7 @@ namespace VeraCrypt
|
|||||||
DWORD effectiveSize = min (bytesRead, remainingSize);
|
DWORD effectiveSize = min (bytesRead, remainingSize);
|
||||||
memcpy (buffer, ReadBuffer, effectiveSize);
|
memcpy (buffer, ReadBuffer, effectiveSize);
|
||||||
offset.QuadPart = - ((LONGLONG) bytesRead) + (LONGLONG) 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;
|
return alignedSize + effectiveSize;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -11960,10 +11960,8 @@ std::vector <HostDevice> GetAvailableHostDevices (bool noDeviceProperties, bool
|
|||||||
{
|
{
|
||||||
for (int partNumber = 0; partNumber < MAX_HOST_PARTITION_NUMBER; partNumber++)
|
for (int partNumber = 0; partNumber < MAX_HOST_PARTITION_NUMBER; partNumber++)
|
||||||
{
|
{
|
||||||
wstringstream strm;
|
WCHAR devPath[32];
|
||||||
strm << L"\\Device\\Harddisk" << devNumber << L"\\Partition" << partNumber;
|
StringCbPrintfW (devPath, sizeof (devPath), L"\\Device\\Harddisk%d\\Partition%d", devNumber, partNumber);
|
||||||
wstring devPathStr (strm.str());
|
|
||||||
const wchar_t *devPath = devPathStr.c_str();
|
|
||||||
|
|
||||||
OPEN_TEST_STRUCT openTest = {0};
|
OPEN_TEST_STRUCT openTest = {0};
|
||||||
if (!OpenDevice (devPath, &openTest, detectUnencryptedFilesystems && partNumber != 0, FALSE))
|
if (!OpenDevice (devPath, &openTest, detectUnencryptedFilesystems && partNumber != 0, FALSE))
|
||||||
@@ -12003,7 +12001,7 @@ std::vector <HostDevice> GetAvailableHostDevices (bool noDeviceProperties, bool
|
|||||||
{
|
{
|
||||||
DISK_GEOMETRY_EX geometry;
|
DISK_GEOMETRY_EX geometry;
|
||||||
|
|
||||||
int driveNumber = GetDiskDeviceDriveLetter ((wchar_t *) devPathStr.c_str());
|
int driveNumber = GetDiskDeviceDriveLetter (devPath);
|
||||||
|
|
||||||
if (driveNumber >= 0)
|
if (driveNumber >= 0)
|
||||||
{
|
{
|
||||||
@@ -12064,10 +12062,8 @@ std::vector <HostDevice> GetAvailableHostDevices (bool noDeviceProperties, bool
|
|||||||
{
|
{
|
||||||
for (int devNumber = 0; devNumber < 256; devNumber++)
|
for (int devNumber = 0; devNumber < 256; devNumber++)
|
||||||
{
|
{
|
||||||
wstringstream strm;
|
WCHAR devPath[32];
|
||||||
strm << L"\\Device\\HarddiskVolume" << devNumber;
|
StringCbPrintfW (devPath, sizeof (devPath), L"\\Device\\HarddiskVolume%d", devNumber);
|
||||||
wstring devPathStr (strm.str());
|
|
||||||
const wchar_t *devPath = devPathStr.c_str();
|
|
||||||
|
|
||||||
OPEN_TEST_STRUCT openTest = {0};
|
OPEN_TEST_STRUCT openTest = {0};
|
||||||
if (!OpenDevice (devPath, &openTest, detectUnencryptedFilesystems, FALSE))
|
if (!OpenDevice (devPath, &openTest, detectUnencryptedFilesystems, FALSE))
|
||||||
@@ -12086,7 +12082,7 @@ std::vector <HostDevice> GetAvailableHostDevices (bool noDeviceProperties, bool
|
|||||||
|
|
||||||
if (!noDeviceProperties)
|
if (!noDeviceProperties)
|
||||||
{
|
{
|
||||||
int driveNumber = GetDiskDeviceDriveLetter ((wchar_t *) devPathStr.c_str());
|
int driveNumber = GetDiskDeviceDriveLetter (devPath);
|
||||||
|
|
||||||
if (driveNumber >= 0)
|
if (driveNumber >= 0)
|
||||||
{
|
{
|
||||||
@@ -12112,10 +12108,8 @@ std::vector <HostDevice> GetAvailableHostDevices (bool noDeviceProperties, bool
|
|||||||
|
|
||||||
void AddDeviceToList (std::vector<HostDevice>& devices, int devNumber, int partNumber)
|
void AddDeviceToList (std::vector<HostDevice>& devices, int devNumber, int partNumber)
|
||||||
{
|
{
|
||||||
wstringstream strm;
|
WCHAR devPath[64];
|
||||||
strm << L"\\Device\\Harddisk" << devNumber << L"\\Partition" << partNumber;
|
StringCbPrintfW (devPath, sizeof (devPath), L"\\Device\\Harddisk%d\\Partition%d", devNumber, partNumber);
|
||||||
wstring devPathStr (strm.str());
|
|
||||||
const wchar_t *devPath = devPathStr.c_str();
|
|
||||||
|
|
||||||
HostDevice device;
|
HostDevice device;
|
||||||
device.SystemNumber = devNumber;
|
device.SystemNumber = devNumber;
|
||||||
@@ -12391,10 +12385,8 @@ void UpdateMountableHostDeviceList ()
|
|||||||
{
|
{
|
||||||
for (int devNumber = 0; devNumber < 256; devNumber++)
|
for (int devNumber = 0; devNumber < 256; devNumber++)
|
||||||
{
|
{
|
||||||
wstringstream strm;
|
WCHAR devPath[32];
|
||||||
strm << L"\\Device\\HarddiskVolume" << devNumber;
|
StringCbPrintfW (devPath, sizeof (devPath), L"\\Device\\HarddiskVolume%d", devNumber);
|
||||||
wstring devPathStr (strm.str());
|
|
||||||
const wchar_t *devPath = devPathStr.c_str();
|
|
||||||
|
|
||||||
OPEN_TEST_STRUCT openTest = {0};
|
OPEN_TEST_STRUCT openTest = {0};
|
||||||
if (!OpenDevice (devPath, &openTest, FALSE, FALSE))
|
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++)
|
for (int partNumber = 0; partNumber < MAX_HOST_PARTITION_NUMBER; partNumber++)
|
||||||
{
|
{
|
||||||
wstringstream strm;
|
WCHAR devPath[32];
|
||||||
strm << L"\\Device\\Harddisk" << devNumber << L"\\Partition" << partNumber;
|
StringCbPrintfW (devPath, sizeof (devPath), L"\\Device\\Harddisk%d\\Partition%d", devNumber, partNumber);
|
||||||
wstring devPathStr (strm.str());
|
|
||||||
const wchar_t *devPath = devPathStr.c_str();
|
|
||||||
|
|
||||||
OPEN_TEST_STRUCT openTest = {0};
|
OPEN_TEST_STRUCT openTest = {0};
|
||||||
if (OpenDevice (devPath, &openTest, TRUE, TRUE)
|
if (OpenDevice (devPath, &openTest, TRUE, TRUE)
|
||||||
|
|||||||
@@ -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 (srcPath, sizeof(srcPath), L"%s\\Languages\\Language.%hs.xml", appDir, GetPreferredLangId ());
|
||||||
StringCbPrintfW (dstPath, sizeof(dstPath), L"%s\\VeraCrypt\\Languages\\Language.%hs.xml", dstDir, 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
|
// AutoRun
|
||||||
|
|||||||
Reference in New Issue
Block a user