diff options
author | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2016-02-07 02:07:38 +0100 |
---|---|---|
committer | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2016-02-07 02:39:43 +0100 |
commit | ae7ec4802a81770ff164e465b8d1fb51624ca093 (patch) | |
tree | 369c0ddf810ea03ae2d1426a661b54ca5288c34c | |
parent | 229bd668f414cac163d12be9a3284b79d95b4ac0 (diff) | |
download | VeraCrypt-ae7ec4802a81770ff164e465b8d1fb51624ca093.tar.gz VeraCrypt-ae7ec4802a81770ff164e465b8d1fb51624ca093.zip |
Windows:Fix various issues and warnings reported by static code analysis tool Coverity.
-rw-r--r-- | src/Common/BootEncryption.cpp | 46 | ||||
-rw-r--r-- | src/Common/Cmdline.c | 2 | ||||
-rw-r--r-- | src/Common/Combo.c | 2 | ||||
-rw-r--r-- | src/Common/Dlgcode.c | 14 | ||||
-rw-r--r-- | src/Common/Exception.h | 4 | ||||
-rw-r--r-- | src/Common/Format.c | 12 | ||||
-rw-r--r-- | src/Common/Keyfiles.c | 32 | ||||
-rw-r--r-- | src/Common/Keyfiles.h | 2 | ||||
-rw-r--r-- | src/Common/Password.c | 4 | ||||
-rw-r--r-- | src/Common/Progress.c | 26 | ||||
-rw-r--r-- | src/Common/Random.c | 6 | ||||
-rw-r--r-- | src/Common/Volumes.c | 8 | ||||
-rw-r--r-- | src/Crypto/Whirlpool.c | 2 | ||||
-rw-r--r-- | src/ExpandVolume/DlgExpandVolume.cpp | 2 | ||||
-rw-r--r-- | src/ExpandVolume/WinMain.cpp | 2 | ||||
-rw-r--r-- | src/Format/InPlace.c | 12 | ||||
-rw-r--r-- | src/Format/Tcformat.c | bin | 645228 -> 645430 bytes | |||
-rw-r--r-- | src/Mount/Hotkeys.c | 7 | ||||
-rw-r--r-- | src/Mount/MainCom.cpp | 3 | ||||
-rw-r--r-- | src/Mount/Mount.c | 80 | ||||
-rw-r--r-- | src/Setup/SelfExtract.c | 20 | ||||
-rw-r--r-- | src/Setup/Setup.c | 2 |
22 files changed, 174 insertions, 114 deletions
diff --git a/src/Common/BootEncryption.cpp b/src/Common/BootEncryption.cpp index b04507de..07eb9a99 100644 --- a/src/Common/BootEncryption.cpp +++ b/src/Common/BootEncryption.cpp @@ -690,9 +690,9 @@ namespace VeraCrypt GetSystemDriveConfiguration();
ProbeRealDriveSizeRequest request;
- StringCbCopyW (request.DeviceName, sizeof (request.DeviceName), DriveConfig.DrivePartition.DevicePath.c_str());
+ StringCchCopyW (request.DeviceName, ARRAYSIZE (request.DeviceName), DriveConfig.DrivePartition.DevicePath.c_str());
CallDriver (TC_IOCTL_PROBE_REAL_DRIVE_SIZE, &request, sizeof (request), &request, sizeof (request));
DriveConfig.DrivePartition.Info.PartitionLength = request.RealDriveSize;
@@ -719,9 +719,9 @@ namespace VeraCrypt wstringstream partPath;
partPath << L"\\Device\\Harddisk" << driveNumber << L"\\Partition" << partNumber;
DISK_PARTITION_INFO_STRUCT diskPartInfo = {0};
- StringCbCopyW (diskPartInfo.deviceName, sizeof (diskPartInfo.deviceName), partPath.str().c_str());
+ StringCchCopyW (diskPartInfo.deviceName, ARRAYSIZE (diskPartInfo.deviceName), partPath.str().c_str());
try
{
CallDriver (TC_IOCTL_GET_DRIVE_PARTITION_INFO, &diskPartInfo, sizeof (diskPartInfo), &diskPartInfo, sizeof (diskPartInfo));
@@ -832,9 +832,9 @@ namespace VeraCrypt OPEN_TEST_STRUCT openTestStruct;
memset (&openTestStruct, 0, sizeof (openTestStruct));
DWORD dwResult;
- StringCbCopyW (&openTestStruct.wszFileName[0], sizeof(openTestStruct.wszFileName),devicePath);
+ StringCchCopyW (&openTestStruct.wszFileName[0], ARRAYSIZE(openTestStruct.wszFileName),devicePath);
openTestStruct.bDetectTCBootLoader = TRUE;
return (DeviceIoControl (hDriver, TC_IOCTL_OPEN_TEST,
@@ -934,9 +934,9 @@ namespace VeraCrypt bool BootEncryption::SystemDriveIsDynamic ()
{
GetSystemDriveConfigurationRequest request;
- StringCbCopyW (request.DevicePath, sizeof (request.DevicePath), GetSystemDriveConfiguration().DeviceKernelPath.c_str());
+ StringCchCopyW (request.DevicePath, ARRAYSIZE (request.DevicePath), GetSystemDriveConfiguration().DeviceKernelPath.c_str());
CallDriver (TC_IOCTL_GET_SYSTEM_DRIVE_CONFIG, &request, sizeof (request), &request, sizeof (request));
return request.DriveIsDynamic ? true : false;
}
@@ -1239,9 +1239,9 @@ namespace VeraCrypt if (config && bufLength < TC_BOOT_CFG_FLAG_AREA_SIZE)
throw ParameterIncorrect (SRC_POS);
GetSystemDriveConfigurationRequest request;
- StringCbCopyW (request.DevicePath, sizeof (request.DevicePath), GetSystemDriveConfiguration().DeviceKernelPath.c_str());
+ StringCchCopyW (request.DevicePath, ARRAYSIZE (request.DevicePath), GetSystemDriveConfiguration().DeviceKernelPath.c_str());
try
{
CallDriver (TC_IOCTL_GET_SYSTEM_DRIVE_CONFIG, &request, sizeof (request), &request, sizeof (request));
@@ -1972,9 +1972,9 @@ namespace VeraCrypt byte regKeyBuf[65536];
DWORD size = (DWORD) (sizeof (regKeyBuf) - strSize);
// SetupInstallFromInfSection() does not support prepending of values so we have to modify the registry directly
- StringCbCopyA ((char *) regKeyBuf, sizeof(regKeyBuf), filter.c_str());
+ StringCchCopyA ((char *) regKeyBuf, ARRAYSIZE(regKeyBuf), filter.c_str());
if (RegQueryValueExA (regKey, filterReg.c_str(), NULL, NULL, regKeyBuf + strSize, &size) != ERROR_SUCCESS)
size = 1;
@@ -2114,8 +2114,9 @@ namespace VeraCrypt // check if service exists
SC_HANDLE service = OpenService (scm, TC_SYSTEM_FAVORITES_SERVICE_NAME, SERVICE_ALL_ACCESS);
if (service)
{
+ finally_do_arg (SC_HANDLE, service, { CloseServiceHandle (finally_arg); });
// ensure that its parameters are correct
throw_sys_if (!ChangeServiceConfig (service,
SERVICE_WIN32_OWN_PROCESS,
SERVICE_AUTO_START,
@@ -2584,25 +2585,28 @@ namespace VeraCrypt // Some chipset drivers may prevent access to the last sector of the drive
if (!systemPartitionOnly)
{
DISK_GEOMETRY geometry = GetDriveGeometry (config.DriveNumber);
- Buffer sector (geometry.BytesPerSector);
+ if ((geometry.BytesPerSector > 0) && (geometry.BytesPerSector < TC_MAX_VOLUME_SECTOR_SIZE))
+ {
+ Buffer sector (geometry.BytesPerSector);
- Device device (config.DevicePath);
- device.CheckOpened (SRC_POS);
+ Device device (config.DevicePath);
+ device.CheckOpened (SRC_POS);
- try
- {
- device.SeekAt (config.DrivePartition.Info.PartitionLength.QuadPart - geometry.BytesPerSector);
- device.Read (sector.Ptr(), (DWORD) sector.Size());
- }
- catch (SystemException &e)
- {
- if (e.ErrorCode != ERROR_CRC)
+ try
{
- e.Show (ParentWindow);
- Error ("WHOLE_DRIVE_ENCRYPTION_PREVENTED_BY_DRIVERS", ParentWindow);
- throw UserAbort (SRC_POS);
+ device.SeekAt (config.DrivePartition.Info.PartitionLength.QuadPart - geometry.BytesPerSector);
+ device.Read (sector.Ptr(), (DWORD) sector.Size());
+ }
+ catch (SystemException &e)
+ {
+ if (e.ErrorCode != ERROR_CRC)
+ {
+ e.Show (ParentWindow);
+ Error ("WHOLE_DRIVE_ENCRYPTION_PREVENTED_BY_DRIVERS", ParentWindow);
+ throw UserAbort (SRC_POS);
+ }
}
}
}
@@ -2640,9 +2644,9 @@ namespace VeraCrypt void BootEncryption::RestrictPagingFilesToSystemPartition ()
{
wchar_t pagingFiles[128] = {0};
- StringCbCopyW (pagingFiles, sizeof(pagingFiles), L"X:\\pagefile.sys 0 0");
+ StringCchCopyW (pagingFiles, ARRAYSIZE(pagingFiles), L"X:\\pagefile.sys 0 0");
pagingFiles[0] = GetWindowsDirectory()[0];
throw_sys_if (!WriteLocalMachineRegistryMultiString (L"System\\CurrentControlSet\\Control\\Session Manager\\Memory Management", L"PagingFiles", pagingFiles, (DWORD) (wcslen (pagingFiles) + 2) * sizeof (wchar_t)));
}
diff --git a/src/Common/Cmdline.c b/src/Common/Cmdline.c index b140309f..759c63f5 100644 --- a/src/Common/Cmdline.c +++ b/src/Common/Cmdline.c @@ -172,9 +172,9 @@ int GetArgumentValue (wchar_t **lpszCommandLineArgs, int *nArgIdx, if (x == 0)
{
/* Handles the case of space between parameter code
and value */
- StringCbCopyW (lpszValue, nValueSize, lpszCommandLineArgs[*nArgIdx + 1]);
+ StringCchCopyW (lpszValue, nValueSize, lpszCommandLineArgs[*nArgIdx + 1]);
lpszValue[nValueSize - 1] = 0;
(*nArgIdx)++;
return HAS_ARGUMENT;
}
diff --git a/src/Common/Combo.c b/src/Common/Combo.c index 56e0afc5..0340b23a 100644 --- a/src/Common/Combo.c +++ b/src/Common/Combo.c @@ -231,9 +231,9 @@ void DumpCombo (HWND hComboBox, int bClear) if (szTmp[0] != 0)
{
wchar_t q[MAX_PATH * 2] = { 0 };
- XmlQuoteTextW (szTmp, q, sizeof (q));
+ XmlQuoteTextW (szTmp, q, ARRAYSIZE (q));
fwprintf (f, L"\n\t\t<volume>%s</volume>", q);
}
}
diff --git a/src/Common/Dlgcode.c b/src/Common/Dlgcode.c index e2b00f7a..4ffae65c 100644 --- a/src/Common/Dlgcode.c +++ b/src/Common/Dlgcode.c @@ -715,9 +715,9 @@ DWORD handleWin32Error (HWND hwndDlg, const char* srcPos) if (lpMsgBuf)
pszDesc = (wchar_t*) lpMsgBuf;
else
{
- StringCbPrintfW (szErrorValue, sizeof (szErrorValue), L"Error 0x%.8X", dwError);
+ StringCchPrintfW (szErrorValue, ARRAYSIZE (szErrorValue), L"Error 0x%.8X", dwError);
pszDesc = szErrorValue;
}
MessageBoxW (hwndDlg, AppendSrcPos (pszDesc, srcPos).c_str (), lpszTitle, ICON_HAND);
@@ -852,9 +852,9 @@ std::wstring FitPathInGfxWidth (HWND hwnd, HFONT hFont, LONG width, const std::w HDC hdc = GetDC (hwnd);
SelectObject (hdc, (HGDIOBJ) hFont);
wchar_t pathBuf[TC_MAX_PATH];
- StringCbCopyW (pathBuf, sizeof (pathBuf), path.c_str());
+ StringCchCopyW (pathBuf, ARRAYSIZE (pathBuf), path.c_str());
if (DrawText (hdc, pathBuf, (int) path.size(), &rect, DT_CALCRECT | DT_MODIFYSTRING | DT_PATH_ELLIPSIS | DT_SINGLELINE) != 0)
newPath = pathBuf;
@@ -4897,15 +4897,19 @@ static BOOL PerformBenchmark(HWND hBenchDlg, HWND hwndDlg) #endif
if (QueryPerformanceFrequency (&benchmarkPerformanceFrequency) == 0)
{
+ if (ci)
+ crypto_close (ci);
MessageBoxW (hwndDlg, GetString ("ERR_PERF_COUNTER"), lpszTitle, ICON_HAND);
return FALSE;
}
lpTestBuffer = (BYTE *) malloc(benchmarkBufferSize - (benchmarkBufferSize % 16));
if (lpTestBuffer == NULL)
{
+ if (ci)
+ crypto_close (ci);
MessageBoxW (hwndDlg, GetString ("ERR_MEM_ALLOC"), lpszTitle, ICON_HAND);
return FALSE;
}
VirtualLock (lpTestBuffer, benchmarkBufferSize - (benchmarkBufferSize % 16));
@@ -8131,9 +8135,9 @@ BOOL SaveBufferToFile (const char *inputBuffer, const wchar_t *destinationFile, if (MoveFileEx (destinationFile, renamedPath, MOVEFILE_REPLACE_EXISTING))
{
dst = CreateFile (destinationFile,
GENERIC_WRITE,
- FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, bAppend ? OPEN_EXISTING : CREATE_ALWAYS, 0, NULL);
+ FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, 0, NULL);
dwLastError = GetLastError();
if (dst == INVALID_HANDLE_VALUE)
{
/* restore the original file name */
@@ -9371,9 +9375,9 @@ void RestoreDefaultKeyFilesParam (void) {
KeyFileRemoveAll (&FirstKeyFile);
if (defaultKeyFilesParam.FirstKeyFile != NULL)
{
- FirstKeyFile = KeyFileCloneAll (defaultKeyFilesParam.FirstKeyFile);
+ KeyFileCloneAll (defaultKeyFilesParam.FirstKeyFile, &FirstKeyFile);
KeyFilesEnable = defaultKeyFilesParam.EnableKeyFiles;
}
else
KeyFilesEnable = FALSE;
@@ -11294,9 +11298,9 @@ BOOL IsApplicationInstalled (const wchar_t *appName, BOOL b32bitApp) {
const wchar_t *uninstallRegName = L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
BOOL installed = FALSE;
HKEY unistallKey;
- LONG res = RegOpenKeyEx (HKEY_LOCAL_MACHINE, uninstallRegName, 0, KEY_READ | b32bitApp? KEY_WOW64_32KEY: KEY_WOW64_64KEY, &unistallKey);
+ LONG res = RegOpenKeyEx (HKEY_LOCAL_MACHINE, uninstallRegName, 0, KEY_READ | (b32bitApp? KEY_WOW64_32KEY: KEY_WOW64_64KEY), &unistallKey);
if (res != ERROR_SUCCESS)
{
SetLastError (res);
return FALSE;
diff --git a/src/Common/Exception.h b/src/Common/Exception.h index a54f803d..f3635a1d 100644 --- a/src/Common/Exception.h +++ b/src/Common/Exception.h @@ -76,9 +76,9 @@ namespace VeraCrypt void Show (HWND parent) const
{
char szErrCode[16];
- StringCbPrintfA (szErrCode, sizeof(szErrCode), "0x%.8X", LastError);
+ StringCchPrintfA (szErrCode, ARRAYSIZE(szErrCode), "0x%.8X", LastError);
string msgBody = "The Random Generator initialization failed.\n\n\n(If you report a bug in connection with this, please include the following technical information in the bug report:\n" + string (SrcPos) + "\nLast Error = " + string (szErrCode) + ")";
MessageBoxA (parent, msgBody.c_str(), "VeraCrypt", MB_ICONERROR | MB_SETFOREGROUND);
}
@@ -92,9 +92,9 @@ namespace VeraCrypt void Show (HWND parent) const
{
char szErrCode[16];
- StringCbPrintfA (szErrCode, sizeof(szErrCode), "0x%.8X", LastError);
+ StringCchPrintfA (szErrCode, ARRAYSIZE(szErrCode), "0x%.8X", LastError);
string msgBody = "Windows Crypto API failed.\n\n\n(If you report a bug in connection with this, please include the following technical information in the bug report:\n" + string (SrcPos) + "\nLast Error = " + string (szErrCode) + ")";
MessageBoxA (parent, msgBody.c_str(), "VeraCrypt", MB_ICONERROR | MB_SETFOREGROUND);
}
diff --git a/src/Common/Format.c b/src/Common/Format.c index a3200bb4..fe12c041 100644 --- a/src/Common/Format.c +++ b/src/Common/Format.c @@ -137,9 +137,9 @@ int TCFormatVolume (volatile FORMAT_VOL_PARAMETERS *volParams) num_sectors = dataAreaSize / FormatSectorSize;
if (volParams->bDevice)
{
- StringCbCopyW (deviceName, sizeof(deviceName), volParams->volumePath);
+ StringCchCopyW (deviceName, ARRAYSIZE(deviceName), volParams->volumePath);
driveLetter = GetDiskDeviceDriveLetter (deviceName);
}
@@ -873,24 +873,24 @@ BOOL FormatFs (int driveNo, int clusterSize, int fsType) WCHAR szLabel[2] = {0};
switch (fsType)
{
case FILESYS_NTFS:
- StringCbCopyW (szFsFormat, sizeof (szFsFormat),L"NTFS");
+ StringCchCopyW (szFsFormat, ARRAYSIZE (szFsFormat),L"NTFS");
break;
case FILESYS_EXFAT:
- StringCbCopyW (szFsFormat, sizeof (szFsFormat),L"EXFAT");
+ StringCchCopyW (szFsFormat, ARRAYSIZE (szFsFormat),L"EXFAT");
break;
default:
return FALSE;
}
if (GetSystemDirectory (dllPath, MAX_PATH))
{
- StringCbCatW(dllPath, sizeof(dllPath), L"\\fmifs.dll");
+ StringCchCatW(dllPath, ARRAYSIZE(dllPath), L"\\fmifs.dll");
}
else
- StringCbCopyW(dllPath, sizeof(dllPath), L"C:\\Windows\\System32\\fmifs.dll");
+ StringCchCopyW(dllPath, ARRAYSIZE(dllPath), L"C:\\Windows\\System32\\fmifs.dll");
hModule = LoadLibrary (dllPath);
if (hModule == NULL)
@@ -901,9 +901,9 @@ BOOL FormatFs (int driveNo, int clusterSize, int fsType) FreeLibrary (hModule);
return FALSE;
}
- StringCbCatW (dir, sizeof(dir), L":\\");
+ StringCchCatW (dir, ARRAYSIZE(dir), L":\\");
FormatExError = TRUE;
// Windows sometimes fails to format a volume (hosted on a removable medium) as NTFS.
diff --git a/src/Common/Keyfiles.c b/src/Common/Keyfiles.c index 9dcf1dcc..9db05266 100644 --- a/src/Common/Keyfiles.c +++ b/src/Common/Keyfiles.c @@ -118,22 +118,28 @@ KeyFile *KeyFileClone (KeyFile *keyFile) return clone;
}
-KeyFile *KeyFileCloneAll (KeyFile *firstKeyFile)
+void KeyFileCloneAll (KeyFile *firstKeyFile, KeyFile **outputKeyFile)
{
- KeyFile *cloneFirstKeyFile = KeyFileClone (firstKeyFile);
- KeyFile *kf;
-
- if (firstKeyFile == NULL) return NULL;
- kf = firstKeyFile->Next;
- while (kf != NULL)
+ if (outputKeyFile)
{
- KeyFileAdd (cloneFirstKeyFile, KeyFileClone (kf));
- kf = kf->Next;
- }
+ KeyFile *cloneFirstKeyFile = KeyFileClone (firstKeyFile);
+ KeyFile *kf;
- return cloneFirstKeyFile;
+ KeyFileRemoveAll (outputKeyFile);
+ if (firstKeyFile)
+ {
+ kf = firstKeyFile->Next;
+ while (kf != NULL)
+ {
+ KeyFileAdd (cloneFirstKeyFile, KeyFileClone (kf));
+ kf = kf->Next;
+ }
+
+ *outputKeyFile = cloneFirstKeyFile;
+ }
+ }
}
static BOOL KeyFileProcess (unsigned __int8 *keyPool, KeyFile *keyFile)
@@ -450,9 +456,9 @@ BOOL CALLBACK KeyFilesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa param = (KeyFilesDlgParam *) lParam;
origParam = *(KeyFilesDlgParam *) lParam;
- param->FirstKeyFile = KeyFileCloneAll (param->FirstKeyFile);
+ KeyFileCloneAll (param->FirstKeyFile, ¶m->FirstKeyFile);
LocalizeDialog (hwndDlg, "IDD_KEYFILES");
DragAcceptFiles (hwndDlg, TRUE);
@@ -636,9 +642,9 @@ BOOL CALLBACK KeyFilesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa {
KeyFile *kf = (KeyFile *) malloc (sizeof (KeyFile));
if (kf)
{
- DragQueryFile (hdrop, i++, kf->FileName, sizeof (kf->FileName));
+ DragQueryFile (hdrop, i++, kf->FileName, ARRAYSIZE (kf->FileName));
param->FirstKeyFile = KeyFileAdd (param->FirstKeyFile, kf);
LoadKeyList (hwndDlg, param->FirstKeyFile);
}
}
diff --git a/src/Common/Keyfiles.h b/src/Common/Keyfiles.h index 2972a765..10b9b77e 100644 --- a/src/Common/Keyfiles.h +++ b/src/Common/Keyfiles.h @@ -37,9 +37,9 @@ typedef struct KeyFile *KeyFileAdd (KeyFile *firstKeyFile, KeyFile *keyFile);
void KeyFileRemoveAll (KeyFile **firstKeyFile);
KeyFile *KeyFileClone (KeyFile *keyFile);
-KeyFile *KeyFileCloneAll (KeyFile *firstKeyFile);
+void KeyFileCloneAll (KeyFile *firstKeyFile, KeyFile **outputKeyFile);
BOOL KeyFilesApply (HWND hwndDlg, Password *password, KeyFile *firstKeyFilem, const wchar_t* volumeFileName);
BOOL CALLBACK KeyFilesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
BOOL KeyfilesPopupMenu (HWND hwndDlg, POINT popupPosition, KeyFilesDlgParam *dialogParam);
diff --git a/src/Common/Password.c b/src/Common/Password.c index 59c82e51..8a93065d 100644 --- a/src/Common/Password.c +++ b/src/Common/Password.c @@ -42,10 +42,10 @@ void VerifyPasswordAndUpdate (HWND hwndDlg, HWND hButton, HWND hPassword, int utf8Len1, utf8Len2;
UNREFERENCED_PARAMETER (hwndDlg); /* Remove warning */
- GetWindowText (hPassword, szTmp1, sizeof (szTmp1));
- GetWindowText (hVerify, szTmp2, sizeof (szTmp2));
+ GetWindowText (hPassword, szTmp1, ARRAYSIZE (szTmp1));
+ GetWindowText (hVerify, szTmp2, ARRAYSIZE (szTmp2));
utf8Len1 = WideCharToMultiByte (CP_UTF8, 0, szTmp1, -1, szTmp1Utf8, MAX_PASSWORD + 1, NULL, NULL);
utf8Len2 = WideCharToMultiByte (CP_UTF8, 0, szTmp2, -1, szTmp2Utf8, MAX_PASSWORD + 1, NULL, NULL);
diff --git a/src/Common/Progress.c b/src/Common/Progress.c index 1d610def..19bd2171 100644 --- a/src/Common/Progress.c +++ b/src/Common/Progress.c @@ -77,50 +77,50 @@ BOOL UpdateProgressBarProc (__int64 byteOffset) {
double perc = (double) (100.0 * (bProgressBarReverse ? ((double) (TotalSize - byteOffset)) : ((double) byteOffset)) / (TotalSize == 0 ? 0.0001 : ((double) TotalSize)));
if (perc > 99.999999999)
- StringCbCopyW (text,sizeof(text), GetString ("PROCESSED_PORTION_100_PERCENT"));
+ StringCchCopyW (text,ARRAYSIZE(text), GetString ("PROCESSED_PORTION_100_PERCENT"));
else
- StringCbPrintfW (text, sizeof text, GetString ("PROCESSED_PORTION_X_PERCENT"), perc);
+ StringCchPrintfW (text, ARRAYSIZE (text), GetString ("PROCESSED_PORTION_X_PERCENT"), perc);
- StringCbCatW (text, sizeof(speed), L" ");
+ StringCchCatW (text, ARRAYSIZE(text), L" ");
}
else
{
GetSizeString (bytesDone, text, sizeof(text));
if (bytesDone < (unsigned __int64) BYTES_PER_MB * 1000000)
- StringCbPrintfW(text, sizeof(text), L"%I64d %s ", bytesDone / BYTES_PER_MB, GetString ("MB"));
+ StringCchPrintfW(text, ARRAYSIZE(text), L"%I64d %s ", bytesDone / BYTES_PER_MB, GetString ("MB"));
else if (bytesDone < (unsigned __int64) BYTES_PER_GB * 1000000)
- StringCbPrintfW(text, sizeof(text), L"%I64d %s ", bytesDone / BYTES_PER_GB, GetString ("GB"));
+ StringCchPrintfW(text, ARRAYSIZE(text), L"%I64d %s ", bytesDone / BYTES_PER_GB, GetString ("GB"));
else if (bytesDone < (unsigned __int64) BYTES_PER_TB * 1000000)
- StringCbPrintfW(text, sizeof(text), L"%I64d %s ", bytesDone / BYTES_PER_TB, GetString ("TB"));
+ StringCchPrintfW(text, ARRAYSIZE(text), L"%I64d %s ", bytesDone / BYTES_PER_TB, GetString ("TB"));
else
- StringCbPrintfW(text, sizeof(text), L"%I64d %s ", bytesDone / BYTES_PER_PB, GetString ("PB"));
+ StringCchPrintfW(text, ARRAYSIZE(text), L"%I64d %s ", bytesDone / BYTES_PER_PB, GetString ("PB"));
}
SetWindowTextW (GetDlgItem (hCurPage, IDC_BYTESWRITTEN), text);
if (!bShowStatus)
{
GetSpeedString (bRWThroughput ? bytesPerSec*2 : bytesPerSec, speed, sizeof(speed));
- StringCbCatW (speed, sizeof(speed), L" ");
+ StringCchCatW (speed, ARRAYSIZE(speed), L" ");
SetWindowTextW (GetDlgItem (hCurPage, IDC_WRITESPEED), speed);
}
if (byteOffset < TotalSize)
{
int64 sec = (int64) ((bProgressBarReverse ? byteOffset : (TotalSize - byteOffset)) / (bytesPerSec == 0 ? 0.001 : bytesPerSec));
if (bytesPerSec == 0 || sec > 60 * 60 * 24 * 999)
- StringCbPrintfW (text, sizeof(text), L"%s ", GetString ("NOT_APPLICABLE_OR_NOT_AVAILABLE"));
+ StringCchPrintfW (text, ARRAYSIZE(text), L"%s ", GetString ("NOT_APPLICABLE_OR_NOT_AVAILABLE"));
else if (sec >= 60 * 60 * 24 * 2)
- StringCbPrintfW (text, sizeof(text), L"%I64d %s ", sec / (60 * 24 * 60), days);
+ StringCchPrintfW (text, ARRAYSIZE(text), L"%I64d %s ", sec / (60 * 24 * 60), days);
else if (sec >= 120 * 60)
- StringCbPrintfW (text, sizeof(text), L"%I64d %s ", sec / (60 * 60), hours);
+ StringCchPrintfW (text, ARRAYSIZE(text), L"%I64d %s ", sec / (60 * 60), hours);
else if (sec >= 120)
- StringCbPrintfW (text, sizeof(text), L"%I64d %s ", sec / 60, minutes);
+ StringCchPrintfW (text, ARRAYSIZE(text), L"%I64d %s ", sec / 60, minutes);
else
- StringCbPrintfW (text, sizeof(text), L"%I64d %s ", sec, seconds);
+ StringCchPrintfW (text, ARRAYSIZE(text), L"%I64d %s ", sec, seconds);
SetWindowTextW (GetDlgItem (hCurPage, IDC_TIMEREMAIN), text);
}
diff --git a/src/Common/Random.c b/src/Common/Random.c index 31dea511..21c18dad 100644 --- a/src/Common/Random.c +++ b/src/Common/Random.c @@ -670,12 +670,12 @@ BOOL SlowPoll (void) functions */
wchar_t dllPath[MAX_PATH];
if (GetSystemDirectory (dllPath, MAX_PATH))
{
- StringCbCatW(dllPath, sizeof(dllPath), L"\\NETAPI32.DLL");
+ StringCchCatW(dllPath, ARRAYSIZE(dllPath), L"\\NETAPI32.DLL");
}
else
- StringCbCopyW(dllPath, sizeof(dllPath), L"C:\\Windows\\System32\\NETAPI32.DLL");
+ StringCchCopyW(dllPath, ARRAYSIZE(dllPath), L"C:\\Windows\\System32\\NETAPI32.DLL");
hNetAPI32 = LoadLibrary (dllPath);
if (hNetAPI32 != NULL)
{
@@ -724,9 +724,9 @@ BOOL SlowPoll (void) DISK_PERFORMANCE diskPerformance;
wchar_t szDevice[24];
/* Check whether we can access this device */
- StringCbPrintfW (szDevice, sizeof(szDevice), L"\\\\.\\PhysicalDrive%d", nDrive);
+ StringCchPrintfW (szDevice, ARRAYSIZE(szDevice), L"\\\\.\\PhysicalDrive%d", nDrive);
hDevice = CreateFile (szDevice, 0, FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, NULL);
if (hDevice == INVALID_HANDLE_VALUE)
break;
diff --git a/src/Common/Volumes.c b/src/Common/Volumes.c index 50fd8765..b7c77e9c 100644 --- a/src/Common/Volumes.c +++ b/src/Common/Volumes.c @@ -1021,18 +1021,18 @@ int CreateVolumeHeaderInMemory (HWND hwndDlg, BOOL bBoot, char *header, int ea, MasterKeyGUIView[0] = 0;
for (i = 0; i < j; i++)
{
wchar_t tmp2[8] = {0};
- StringCbPrintfW (tmp2, sizeof(tmp2), L"%02X", (int) (unsigned char) keyInfo.master_keydata[i + primaryKeyOffset]);
- StringCbCatW (MasterKeyGUIView, sizeof(MasterKeyGUIView), tmp2);
+ StringCchPrintfW (tmp2, ARRAYSIZE(tmp2), L"%02X", (int) (unsigned char) keyInfo.master_keydata[i + primaryKeyOffset]);
+ StringCchCatW (MasterKeyGUIView, ARRAYSIZE(MasterKeyGUIView), tmp2);
}
HeaderKeyGUIView[0] = 0;
for (i = 0; i < NBR_KEY_BYTES_TO_DISPLAY; i++)
{
wchar_t tmp2[8];
- StringCbPrintfW (tmp2, sizeof(tmp2), L"%02X", (int) (unsigned char) dk[primaryKeyOffset + i]);
- StringCbCatW (HeaderKeyGUIView, sizeof(HeaderKeyGUIView), tmp2);
+ StringCchPrintfW (tmp2, ARRAYSIZE(tmp2), L"%02X", (int) (unsigned char) dk[primaryKeyOffset + i]);
+ StringCchCatW (HeaderKeyGUIView, ARRAYSIZE(HeaderKeyGUIView), tmp2);
}
if (dots3)
{
diff --git a/src/Crypto/Whirlpool.c b/src/Crypto/Whirlpool.c index bfc627f3..d8442cd1 100644 --- a/src/Crypto/Whirlpool.c +++ b/src/Crypto/Whirlpool.c @@ -567,8 +567,9 @@ void WhirlpoolTransform(uint64 *digest, const uint64 *block) { uint64 s[8]; // the cipher state uint64 k[8]; // the round key int r; + uint64 w0 = 0, w1 = 0, w2 = 0, w3 = 0, w4 = 0, w5 = 0, w6 = 0, w7 = 0; // temporary storage // Compute and apply K^0 to the cipher state // Also apply part of the Miyaguchi-Preneel compression function for (r=0; r<8; r++) @@ -626,9 +627,8 @@ void WhirlpoolTransform(uint64 *digest, const uint64 *block) // Iterate over all rounds: r=0; while (1) { - uint64 w0, w1, w2, w3, w4, w5, w6, w7; // temporary storage uint32 t; KSL(0, 4, 3, 2, 1, 0) KSL(0, 0, 7, 6, 5, 4) diff --git a/src/ExpandVolume/DlgExpandVolume.cpp b/src/ExpandVolume/DlgExpandVolume.cpp index 135f8d48..73a38b59 100644 --- a/src/ExpandVolume/DlgExpandVolume.cpp +++ b/src/ExpandVolume/DlgExpandVolume.cpp @@ -304,9 +304,9 @@ BOOL CALLBACK ExpandVolProgressDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, L {
SetDlgItemText(hwndDlg, IDC_BOX_STATUS, L"IMPORTANT: Move your mouse as randomly as possible within this window. The longer you move it, the better. This significantly increases the cryptographic strength of the encryption keys. Then click 'Continue' to expand the volume.");
}
- SendMessage (GetDlgItem (hwndDlg, IDC_DISPLAY_POOL_CONTENTS), BM_SETCHECK, showRandPool ? BST_CHECKED : BST_UNCHECKED, 0);
+ SendMessage (GetDlgItem (hwndDlg, IDC_DISPLAY_POOL_CONTENTS), BM_SETCHECK, BST_UNCHECKED, 0);
hEntropyBar = GetDlgItem (hwndDlg, IDC_ENTROPY_BAR);
SendMessage (hEntropyBar, PBM_SETRANGE32, 0, maxEntropyLevel);
SendMessage (hEntropyBar, PBM_SETSTEP, 1, 0);
SetTimer (hwndDlg, TIMER_ID_RANDVIEW, TIMER_INTERVAL_RANDVIEW, NULL);
diff --git a/src/ExpandVolume/WinMain.cpp b/src/ExpandVolume/WinMain.cpp index 89d1738d..e6efd1db 100644 --- a/src/ExpandVolume/WinMain.cpp +++ b/src/ExpandVolume/WinMain.cpp @@ -758,9 +758,9 @@ BOOL CALLBACK ExtcvPasswordDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARA {
KeyFile *kf = (KeyFile *) malloc (sizeof (KeyFile));
if (kf)
{
- DragQueryFile (hdrop, i++, kf->FileName, sizeof (kf->FileName));
+ DragQueryFile (hdrop, i++, kf->FileName, ARRAYSIZE (kf->FileName));
FirstKeyFile = KeyFileAdd (FirstKeyFile, kf);
KeyFilesEnable = TRUE;
}
}
diff --git a/src/Format/InPlace.c b/src/Format/InPlace.c index aa1e83c4..a6b6abeb 100644 --- a/src/Format/InPlace.c +++ b/src/Format/InPlace.c @@ -413,9 +413,9 @@ int EncryptPartitionInPlaceBegin (volatile FORMAT_VOL_PARAMETERS *volParams, vol }
dataAreaSize = GetVolumeDataAreaSize (volParams->hiddenVol, deviceSize);
- StringCbCopyW (deviceName, sizeof(deviceName), volParams->volumePath);
+ StringCchCopyW (deviceName, ARRAYSIZE(deviceName), volParams->volumePath);
driveLetter = GetDiskDeviceDriveLetter (deviceName);
@@ -1283,8 +1283,18 @@ int DecryptPartitionInPlace (volatile FORMAT_VOL_PARAMETERS *volParams, volatile nStatus = ERR_OS_ERROR;
goto closing_seq;
}
+ if ( (driveGeometry.BytesPerSector == 0)
+ || (driveGeometry.BytesPerSector > TC_MAX_VOLUME_SECTOR_SIZE)
+ || (driveGeometry.BytesPerSector % ENCRYPTION_DATA_UNIT_SIZE != 0)
+ )
+ {
+ Error ("SECTOR_SIZE_UNSUPPORTED", hwndDlg);
+ nStatus = ERR_DONT_REPORT;
+ goto closing_seq;
+ }
+
sectorSize = driveGeometry.BytesPerSector;
tmpSectorBuf = (byte *) TCalloc (sectorSize);
diff --git a/src/Format/Tcformat.c b/src/Format/Tcformat.c Binary files differindex aa63f0a4..25be494d 100644 --- a/src/Format/Tcformat.c +++ b/src/Format/Tcformat.c diff --git a/src/Mount/Hotkeys.c b/src/Mount/Hotkeys.c index 014e4dc6..59fa1093 100644 --- a/src/Mount/Hotkeys.c +++ b/src/Mount/Hotkeys.c @@ -388,9 +388,14 @@ BOOL CALLBACK HotkeysDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPar EnableWindow (GetDlgItem (hwndDlg, IDC_HOTKEY_REMOVE), FALSE);
DisplayHotkeyList(hwndDlg);
- SetTimer (hwndDlg, 0xfe, 10, NULL);
+ if (SetTimer (hwndDlg, 0xfe, 10, NULL) == 0)
+ {
+ Error ("CANNOT_SET_TIMER", MainDlg);
+ EndDialog (hwndDlg, IDCANCEL);
+ return 1;
+ }
return 1;
}
case WM_TIMER:
diff --git a/src/Mount/MainCom.cpp b/src/Mount/MainCom.cpp index a89a4428..738b243d 100644 --- a/src/Mount/MainCom.cpp +++ b/src/Mount/MainCom.cpp @@ -279,10 +279,11 @@ extern "C" int UacChangePwd (wchar_t *lpszVolume, Password *oldPassword, int old CoInitialize (NULL);
if (ComGetInstance (hwndDlg, &tc))
{
+ CComBSTR bstrVolume (lpszVolume);
WaitCursor ();
- r = tc->ChangePasswordEx3 (lpszVolume, oldPassword, old_pkcs5, old_pim, truecryptMode, newPassword, pkcs5, pim, wipePassCount, (LONG_PTR) hwndDlg);
+ r = tc->ChangePasswordEx3 (bstrVolume, oldPassword, old_pkcs5, old_pim, truecryptMode, newPassword, pkcs5, pim, wipePassCount, (LONG_PTR) hwndDlg);
NormalCursor ();
}
else
r = -1;
diff --git a/src/Mount/Mount.c b/src/Mount/Mount.c index 2bbb8af8..86337d6b 100644 --- a/src/Mount/Mount.c +++ b/src/Mount/Mount.c @@ -1551,9 +1551,17 @@ void LoadDriveLetters (HWND hwndDlg, HWND hTree, int drive) GetSizeString (GetSysEncDeviceSize(TRUE), szTmpW, sizeof(szTmpW));
ListSubItemSet (hTree, listItem.iItem, 2, szTmpW);
- EAGetName (szTmp, propSysEnc.ea, 1);
+ if (propSysEnc.ea >= EAGetFirst() && propSysEnc.ea <= EAGetCount())
+ {
+ EAGetName (szTmp, propSysEnc.ea, 1);
+ }
+ else
+ {
+ szTmp[0] = L'?';
+ szTmp[1] = 0;
+ }
listItem.iSubItem = 3;
ListView_SetItem (hTree, &listItem);
ListSubItemSet (hTree, listItem.iItem, 4, GetString (IsHiddenOSRunning() ? "HIDDEN" : "SYSTEM_VOLUME_TYPE_ADJECTIVE"));
@@ -3001,9 +3009,9 @@ BOOL CALLBACK PasswordDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa {
KeyFile *kf = (KeyFile *) malloc (sizeof (KeyFile));
if (kf)
{
- DragQueryFile (hdrop, i++, kf->FileName, sizeof (kf->FileName));
+ DragQueryFile (hdrop, i++, kf->FileName, ARRAYSIZE (kf->FileName));
FirstKeyFile = KeyFileAdd (FirstKeyFile, kf);
KeyFilesEnable = TRUE;
}
}
@@ -3743,9 +3751,9 @@ BOOL CALLBACK VolumePropertiesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP // Encryption algorithm
ListItemAdd (list, i, GetString ("ENCRYPTION_ALGORITHM"));
- if (prop.ea == 0 || prop.ea > EAGetCount ())
+ if (prop.ea < EAGetFirst() || prop.ea > EAGetCount ())
{
ListSubItemSet (list, i, 1, L"?");
return 1;
}
@@ -5848,15 +5856,15 @@ static BOOL CheckMountList (HWND hwndDlg, BOOL bForceTaskBarUpdate) selDrive = (wchar_t) HIWORD (GetSelectedLong (GetDlgItem (MainDlg, IDC_DRIVELIST)));
LoadDriveLetters (hwndDlg, GetDlgItem (MainDlg, IDC_DRIVELIST), 0);
NormalCursor ();
- if (selDrive != -1 && (current.ulMountedDrives & (1 << (selDrive - L'A'))) == 0 && !IsDriveAvailable (selDrive - L'A'))
+ if (selDrive != ((wchar_t) 0xFFFF) && (current.ulMountedDrives & (1 << (selDrive - L'A'))) == 0 && !IsDriveAvailable (selDrive - L'A'))
{
nSelectedDriveIndex = -1;
return FALSE;
}
- if (selDrive != -1)
+ if (selDrive != ((wchar_t) 0xFFFF))
SelectItem (GetDlgItem (MainDlg, IDC_DRIVELIST),selDrive);
}
try
@@ -5899,14 +5907,14 @@ static BOOL CheckMountList (HWND hwndDlg, BOOL bForceTaskBarUpdate) LoadDriveLetters (hwndDlg, GetDlgItem (MainDlg, IDC_DRIVELIST), driveLetterToRefresh);
RecentBootEncStatus = newBootEncStatus;
- if (selDrive != -1 && (current.ulMountedDrives & (1 << (selDrive - L'A'))) == 0 && !IsDriveAvailable (selDrive - L'A'))
+ if (selDrive != ((wchar_t) 0xFFFF) && (current.ulMountedDrives & (1 << (selDrive - L'A'))) == 0 && !IsDriveAvailable (selDrive - L'A'))
{
nSelectedDriveIndex = -1;
}
- if (selDrive != -1)
+ if (selDrive != ((wchar_t) 0xFFFF))
{
SelectItem (GetDlgItem (MainDlg, IDC_DRIVELIST),selDrive);
}
}
@@ -6068,11 +6076,11 @@ void DisplayDriveListContextMenu (HWND hwndDlg, LPARAM lParam) if (ListView_GetItemPosition (hList, nSelectedDriveIndex, &pt))
{
pt.x += 2 + ::GetSystemMetrics(SM_CXICON);
pt.y += 2;
- ClientToScreen (hList, &pt);
- mPos = MAKELONG (pt.x, pt.y);
}
+ ClientToScreen (hList, &pt);
+ mPos = MAKELONG (pt.x, pt.y);
}
menuItem = TrackPopupMenu (popup,
TPM_RETURNCMD | TPM_LEFTBUTTON,
@@ -6276,10 +6284,10 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa defaultMountOptions = mountOptions;
if (FirstCmdKeyFile)
{
KeyFilesEnable = defaultKeyFilesParam.EnableKeyFiles = TRUE;
- FirstKeyFile = KeyFileCloneAll (FirstCmdKeyFile);
- defaultKeyFilesParam.FirstKeyFile = KeyFileCloneAll (FirstCmdKeyFile);
+ KeyFileCloneAll (FirstCmdKeyFile, &FirstKeyFile);
+ KeyFileCloneAll (FirstCmdKeyFile, &defaultKeyFilesParam.FirstKeyFile);
}
if (!MountAllDevices (hwndDlg, !Silent && !CmdVolumePasswordValid && IsPasswordCacheEmpty()))
exitCode = 1;
@@ -6290,10 +6298,10 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa defaultMountOptions = mountOptions;
if (FirstCmdKeyFile)
{
KeyFilesEnable = defaultKeyFilesParam.EnableKeyFiles = TRUE;
- FirstKeyFile = KeyFileCloneAll (FirstCmdKeyFile);
- defaultKeyFilesParam.FirstKeyFile = KeyFileCloneAll (FirstCmdKeyFile);
+ KeyFileCloneAll (FirstCmdKeyFile, &FirstKeyFile);
+ KeyFileCloneAll (FirstCmdKeyFile, &defaultKeyFilesParam.FirstKeyFile);
}
if (!MountFavoriteVolumes (hwndDlg, FALSE, LogOn))
exitCode = 1;
@@ -6341,8 +6349,9 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa }
if (FirstCmdKeyFile)
{
+ KeyFileRemoveAll (&FirstKeyFile);
FirstKeyFile = FirstCmdKeyFile;
KeyFilesEnable = TRUE;
}
@@ -7413,9 +7422,9 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa Warning ("NO_VOLUME_SELECTED", hwndDlg);
}
else
{
- GetVolumePath (hwndDlg, volPath, sizeof (volPath));
+ GetVolumePath (hwndDlg, volPath, ARRAYSIZE (volPath));
WaitCursor ();
int iStatus = 0;
@@ -8017,9 +8026,9 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa case WM_DROPFILES:
{
HDROP hdrop = (HDROP) wParam;
- DragQueryFile (hdrop, 0, szFileName, sizeof szFileName);
+ DragQueryFile (hdrop, 0, szFileName, ARRAYSIZE (szFileName));
DragFinish (hdrop);
AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, bHistory);
EnableDisableButtons (hwndDlg);
@@ -8172,9 +8181,9 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine) wchar_t szTmp[32] = {0};
bAuto = TRUE;
if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs,
- &i, nNoCommandLineArgs, szTmp, sizeof (szTmp)))
+ &i, nNoCommandLineArgs, szTmp, ARRAYSIZE (szTmp)))
{
if (!_wcsicmp (szTmp, L"devices"))
bAutoMountDevices = TRUE;
else if (!_wcsicmp (szTmp, L"favorites"))
@@ -8197,9 +8206,9 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine) bCmdTryEmptyPasswordWhenKeyfileUsed = TRUE;
bCmdTryEmptyPasswordWhenKeyfileUsedValid = TRUE;
if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, &i, nNoCommandLineArgs,
- szTmp, sizeof (szTmp)))
+ szTmp, ARRAYSIZE (szTmp)))
{
if (!_wcsicmp(szTmp,L"n") || !_wcsicmp(szTmp,L"no"))
bCmdTryEmptyPasswordWhenKeyfileUsed = FALSE;
else if (!_wcsicmp(szTmp,L"y") || !_wcsicmp(szTmp,L"yes"))
@@ -8216,9 +8225,9 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine) bCacheInDriver = TRUE;
bIncludePimInCache = FALSE;
if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, &i, nNoCommandLineArgs,
- szTmp, sizeof (szTmp)))
+ szTmp, ARRAYSIZE (szTmp)))
{
if (!_wcsicmp(szTmp,L"n") || !_wcsicmp(szTmp,L"no"))
bCacheInDriver = FALSE;
else if (!_wcsicmp(szTmp,L"y") || !_wcsicmp(szTmp,L"yes"))
@@ -8241,9 +8250,9 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine) case CommandDismount:
if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, &i, nNoCommandLineArgs,
- szDriveLetter, sizeof (szDriveLetter)))
+ szDriveLetter, ARRAYSIZE (szDriveLetter)))
{
if ( (wcslen(szDriveLetter) == 1)
|| (wcslen(szDriveLetter) == 2 && szDriveLetter[1] == L':')
)
@@ -8271,16 +8280,16 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine) break;
case OptionKeyfile:
if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, &i,
- nNoCommandLineArgs, tmpPath, sizeof (tmpPath)))
+ nNoCommandLineArgs, tmpPath, ARRAYSIZE (tmpPath)))
{
KeyFile *kf;
RelativePath2Absolute (tmpPath);
kf = (KeyFile *) malloc (sizeof (KeyFile));
if (kf)
{
- StringCbCopyW (kf->FileName, sizeof(kf->FileName), tmpPath);
+ StringCchCopyW (kf->FileName, ARRAYSIZE(kf->FileName), tmpPath);
FirstCmdKeyFile = KeyFileAdd (FirstCmdKeyFile, kf);
}
}
else
@@ -8289,9 +8298,9 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine) break;
case OptionLetter:
if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, &i, nNoCommandLineArgs,
- szDriveLetter, sizeof (szDriveLetter)))
+ szDriveLetter, ARRAYSIZE (szDriveLetter)))
{
if ( (wcslen(szDriveLetter) == 1)
|| (wcslen(szDriveLetter) == 2 && szDriveLetter[1] == L':')
)
@@ -8314,9 +8323,9 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine) wchar_t szTmp[8] = {0};
bHistory = bHistoryCmdLine = TRUE;
if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, &i, nNoCommandLineArgs,
- szTmp, sizeof (szTmp)))
+ szTmp, ARRAYSIZE (szTmp)))
{
if (!_wcsicmp(szTmp,L"n") || !_wcsicmp(szTmp,L"no"))
bHistory = FALSE;
else if (!_wcsicmp(szTmp,L"y") || !_wcsicmp(szTmp,L"yes"))
@@ -8330,9 +8339,9 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine) case OptionMountOption:
{
wchar_t szTmp[64] = {0};
if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs,
- &i, nNoCommandLineArgs, szTmp, sizeof (szTmp)))
+ &i, nNoCommandLineArgs, szTmp, ARRAYSIZE (szTmp)))
{
if (!_wcsicmp (szTmp, L"ro") || !_wcsicmp (szTmp, L"readonly"))
mountOptions.ReadOnly = TRUE;
@@ -8369,9 +8378,9 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine) case OptionPassword:
{
wchar_t szTmp[MAX_PASSWORD + 1];
if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, &i, nNoCommandLineArgs,
- szTmp, sizeof (szTmp)))
+ szTmp, ARRAYSIZE (szTmp)))
{
int iLen = WideCharToMultiByte (CP_UTF8, 0, szTmp, -1, (char*) CmdVolumePassword.Text, MAX_PASSWORD + 1, NULL, NULL);
burn (szTmp, sizeof (szTmp));
if (iLen > 0)
@@ -8388,9 +8397,9 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine) break;
case OptionVolume:
if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, &i,
- nNoCommandLineArgs, szFileName, sizeof (szFileName)))
+ nNoCommandLineArgs, szFileName, ARRAYSIZE (szFileName)))
{
RelativePath2Absolute (szFileName);
AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, bHistory);
CmdLineVolumeSpecified = TRUE;
@@ -8403,9 +8412,9 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine) {
wchar_t szTmp[32] = {0};
if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs,
- &i, nNoCommandLineArgs, szTmp, sizeof (szTmp)))
+ &i, nNoCommandLineArgs, szTmp, ARRAYSIZE (szTmp)))
{
if (!_wcsicmp (szTmp, L"UAC")) // Used to indicate non-install elevation
break;
@@ -8432,9 +8441,9 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine) Silent = TRUE;
break;
case OptionTokenLib:
- if (GetArgumentValue (lpszCommandLineArgs, &i, nNoCommandLineArgs, SecurityTokenLibraryPath, sizeof (SecurityTokenLibraryPath)) == HAS_ARGUMENT)
+ if (GetArgumentValue (lpszCommandLineArgs, &i, nNoCommandLineArgs, SecurityTokenLibraryPath, ARRAYSIZE (SecurityTokenLibraryPath)) == HAS_ARGUMENT)
InitSecurityTokenLibrary(hwndDlg);
else
AbortProcess ("COMMAND_LINE_ERROR");
@@ -8453,9 +8462,9 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine) case OptionPkcs5:
{
wchar_t szTmp[32] = {0};
if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs,
- &i, nNoCommandLineArgs, szTmp, sizeof (szTmp)))
+ &i, nNoCommandLineArgs, szTmp, ARRAYSIZE (szTmp)))
{
if (_wcsicmp(szTmp, L"sha512") == 0 || _wcsicmp(szTmp, L"sha-512") == 0)
CmdVolumePkcs5 = SHA512;
else if (_wcsicmp(szTmp, L"whirlpool") == 0)
@@ -8479,9 +8488,9 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine) case OptionPim:
{
wchar_t szTmp[32] = {0};
if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs,
- &i, nNoCommandLineArgs, szTmp, sizeof (szTmp)))
+ &i, nNoCommandLineArgs, szTmp, ARRAYSIZE (szTmp)))
{
wchar_t* endPtr = NULL;
CmdVolumePim = (int) wcstol(szTmp, &endPtr, 0);
if (CmdVolumePim < 0 || endPtr == szTmp || *endPtr != L'\0')
@@ -8869,8 +8878,19 @@ static BOOL MountFavoriteVolumeBase (HWND hwnd, const FavoriteVolume &favorite, {
BOOL status = TRUE;
int drive;
drive = towupper (favorite.MountPoint[0]) - L'A';
+
+ if ((drive < MIN_MOUNTED_VOLUME_DRIVE_NUMBER) || (drive > MAX_MOUNTED_VOLUME_DRIVE_NUMBER))
+ {
+ if (!systemFavorites)
+ Error ("DRIVE_LETTER_UNAVAILABLE", MainDlg);
+ else if (ServiceMode && systemFavorites)
+ {
+ SystemFavoritesServiceLogError (wstring (L"The drive letter ") + (wchar_t) (drive + L'A') + wstring (L" used by favorite \"") + favorite.Path + L"\" is invalid.\nThis system favorite will not be mounted");
+ }
+ return FALSE;
+ }
mountOptions.ReadOnly = favorite.ReadOnly || userForcedReadOnly;
mountOptions.Removable = favorite.Removable;
if (favorite.UseLabelInExplorer && !favorite.Label.empty())
diff --git a/src/Setup/SelfExtract.c b/src/Setup/SelfExtract.c index 72698015..42326efc 100644 --- a/src/Setup/SelfExtract.c +++ b/src/Setup/SelfExtract.c @@ -175,9 +175,9 @@ static int CompressBuffer (char *out, char *in, int len) startupInfo.cb = sizeof (startupInfo);
startupInfo.hStdError = hChildStdoutWrite;
startupInfo.dwFlags |= STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
- StringCbCopyW (szGzipCmd, sizeof (szGzipCmd), L"gzip --best");
+ StringCchCopyW (szGzipCmd, ARRAYSIZE (szGzipCmd), L"gzip --best");
if (!CreateProcess (NULL, szGzipCmd, NULL, NULL, TRUE, 0, NULL, NULL, &startupInfo, &procInfo))
{
PkgError (L"Error: Cannot run gzip.\n\nBefore you can create a self-extracting VeraCrypt package, you need to have the open-source 'gzip' compression tool placed in any directory in the search path for executable files (for example, in 'C:\\Windows\\').\n\nNote: gzip can be freely downloaded e.g. from www.gzip.org");
CloseHandle(hChildStdoutWrite);
@@ -255,10 +255,10 @@ BOOL MakeSelfExtractingPackage (HWND hwndDlg, wchar_t *szDestDir) StringCbCatW (szDestDir, MAX_PATH, L"\\");
GetModuleFileName (NULL, inputFile, ARRAYSIZE (inputFile));
- StringCbCopyW (outputFile, sizeof(outputFile), szDestDir);
- StringCbCatW (outputFile, sizeof(outputFile), OutputPackageFile);
+ StringCchCopyW (outputFile, ARRAYSIZE(outputFile), szDestDir);
+ StringCchCatW (outputFile, ARRAYSIZE(outputFile), OutputPackageFile);
// Clone 'VeraCrypt Setup.exe' to create the base of the new self-extracting archive
if (!TCCopyFile (inputFile, outputFile))
@@ -377,8 +377,18 @@ BOOL MakeSelfExtractingPackage (HWND hwndDlg, wchar_t *szDestDir) }
// Compress all the files and meta data in the buffer to create a solid archive
+ // Test to make Coverity happy. It will always be false
+ if (uncompressedDataLen >= (INT_MAX - 524288))
+ {
+ if (_wremove (outputFile))
+ PkgError (L"Cannot allocate memory for compressed data.\nFailed also to delete package file");
+ else
+ PkgError (L"Cannot allocate memory for compressed data");
+ goto err;
+ }
+
compressedBuffer = malloc (uncompressedDataLen + 524288); // + 512K reserve
if (compressedBuffer == NULL)
{
if (_wremove (outputFile))
@@ -744,10 +754,10 @@ void __cdecl ExtractAllFilesThread (void *hwndDlg) wchar_t filePath [TC_MAX_PATH] = {0};
// Filename
StringCchCopyNW (fileName, ARRAYSIZE(fileName), Decompressed_Files[fileNo].fileName, Decompressed_Files[fileNo].fileNameLength);
- StringCbCopyW (filePath, sizeof(filePath), DestExtractPath);
- StringCbCatW (filePath, sizeof(filePath), fileName);
+ StringCchCopyW (filePath, ARRAYSIZE(filePath), DestExtractPath);
+ StringCchCatW (filePath, ARRAYSIZE(filePath), fileName);
StatusMessageParam (hwndDlg, "EXTRACTING_VERB", filePath);
// Write the file
diff --git a/src/Setup/Setup.c b/src/Setup/Setup.c index e781af81..02a361c5 100644 --- a/src/Setup/Setup.c +++ b/src/Setup/Setup.c @@ -711,9 +711,9 @@ BOOL DoFilesInstall (HWND hwndDlg, wchar_t *szDestDir) StringCbCatW (szDir, sizeof(szDir), L"Drivers\\");
}
else if (*szFiles[i] == L'W')
- GetWindowsDirectory (szDir, sizeof (szDir));
+ GetWindowsDirectory (szDir, ARRAYSIZE (szDir));
if (*szFiles[i] == L'I')
continue;
|