1
0
mirror of https://github.com/veracrypt/VeraCrypt.git synced 2025-11-11 11:08:02 -06:00

Windows:Fix various issues and warnings reported by static code analysis tool Coverity.

This commit is contained in:
Mounir IDRASSI
2016-02-07 02:07:38 +01:00
parent 229bd668f4
commit ae7ec4802a
22 changed files with 175 additions and 115 deletions

View File

@@ -691,7 +691,7 @@ namespace VeraCrypt
GetSystemDriveConfiguration(); GetSystemDriveConfiguration();
ProbeRealDriveSizeRequest request; 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)); CallDriver (TC_IOCTL_PROBE_REAL_DRIVE_SIZE, &request, sizeof (request), &request, sizeof (request));
DriveConfig.DrivePartition.Info.PartitionLength = request.RealDriveSize; DriveConfig.DrivePartition.Info.PartitionLength = request.RealDriveSize;
@@ -720,7 +720,7 @@ namespace VeraCrypt
partPath << L"\\Device\\Harddisk" << driveNumber << L"\\Partition" << partNumber; partPath << L"\\Device\\Harddisk" << driveNumber << L"\\Partition" << partNumber;
DISK_PARTITION_INFO_STRUCT diskPartInfo = {0}; 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 try
{ {
@@ -833,7 +833,7 @@ namespace VeraCrypt
memset (&openTestStruct, 0, sizeof (openTestStruct)); memset (&openTestStruct, 0, sizeof (openTestStruct));
DWORD dwResult; DWORD dwResult;
StringCbCopyW (&openTestStruct.wszFileName[0], sizeof(openTestStruct.wszFileName),devicePath); StringCchCopyW (&openTestStruct.wszFileName[0], ARRAYSIZE(openTestStruct.wszFileName),devicePath);
openTestStruct.bDetectTCBootLoader = TRUE; openTestStruct.bDetectTCBootLoader = TRUE;
@@ -935,7 +935,7 @@ namespace VeraCrypt
bool BootEncryption::SystemDriveIsDynamic () bool BootEncryption::SystemDriveIsDynamic ()
{ {
GetSystemDriveConfigurationRequest request; 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)); CallDriver (TC_IOCTL_GET_SYSTEM_DRIVE_CONFIG, &request, sizeof (request), &request, sizeof (request));
return request.DriveIsDynamic ? true : false; return request.DriveIsDynamic ? true : false;
@@ -1240,7 +1240,7 @@ namespace VeraCrypt
throw ParameterIncorrect (SRC_POS); throw ParameterIncorrect (SRC_POS);
GetSystemDriveConfigurationRequest request; GetSystemDriveConfigurationRequest request;
StringCbCopyW (request.DevicePath, sizeof (request.DevicePath), GetSystemDriveConfiguration().DeviceKernelPath.c_str()); StringCchCopyW (request.DevicePath, ARRAYSIZE (request.DevicePath), GetSystemDriveConfiguration().DeviceKernelPath.c_str());
try try
{ {
@@ -1973,7 +1973,7 @@ namespace VeraCrypt
DWORD size = (DWORD) (sizeof (regKeyBuf) - strSize); DWORD size = (DWORD) (sizeof (regKeyBuf) - strSize);
// SetupInstallFromInfSection() does not support prepending of values so we have to modify the registry directly // 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) if (RegQueryValueExA (regKey, filterReg.c_str(), NULL, NULL, regKeyBuf + strSize, &size) != ERROR_SUCCESS)
size = 1; size = 1;
@@ -2115,6 +2115,7 @@ namespace VeraCrypt
SC_HANDLE service = OpenService (scm, TC_SYSTEM_FAVORITES_SERVICE_NAME, SERVICE_ALL_ACCESS); SC_HANDLE service = OpenService (scm, TC_SYSTEM_FAVORITES_SERVICE_NAME, SERVICE_ALL_ACCESS);
if (service) if (service)
{ {
finally_do_arg (SC_HANDLE, service, { CloseServiceHandle (finally_arg); });
// ensure that its parameters are correct // ensure that its parameters are correct
throw_sys_if (!ChangeServiceConfig (service, throw_sys_if (!ChangeServiceConfig (service,
SERVICE_WIN32_OWN_PROCESS, SERVICE_WIN32_OWN_PROCESS,
@@ -2585,6 +2586,8 @@ namespace VeraCrypt
if (!systemPartitionOnly) if (!systemPartitionOnly)
{ {
DISK_GEOMETRY geometry = GetDriveGeometry (config.DriveNumber); DISK_GEOMETRY geometry = GetDriveGeometry (config.DriveNumber);
if ((geometry.BytesPerSector > 0) && (geometry.BytesPerSector < TC_MAX_VOLUME_SECTOR_SIZE))
{
Buffer sector (geometry.BytesPerSector); Buffer sector (geometry.BytesPerSector);
Device device (config.DevicePath); Device device (config.DevicePath);
@@ -2605,6 +2608,7 @@ namespace VeraCrypt
} }
} }
} }
}
BackupSystemLoader (); BackupSystemLoader ();
@@ -2641,7 +2645,7 @@ namespace VeraCrypt
void BootEncryption::RestrictPagingFilesToSystemPartition () void BootEncryption::RestrictPagingFilesToSystemPartition ()
{ {
wchar_t pagingFiles[128] = {0}; 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]; 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))); throw_sys_if (!WriteLocalMachineRegistryMultiString (L"System\\CurrentControlSet\\Control\\Session Manager\\Memory Management", L"PagingFiles", pagingFiles, (DWORD) (wcslen (pagingFiles) + 2) * sizeof (wchar_t)));

View File

@@ -173,7 +173,7 @@ int GetArgumentValue (wchar_t **lpszCommandLineArgs, int *nArgIdx,
{ {
/* Handles the case of space between parameter code /* Handles the case of space between parameter code
and value */ and value */
StringCbCopyW (lpszValue, nValueSize, lpszCommandLineArgs[*nArgIdx + 1]); StringCchCopyW (lpszValue, nValueSize, lpszCommandLineArgs[*nArgIdx + 1]);
lpszValue[nValueSize - 1] = 0; lpszValue[nValueSize - 1] = 0;
(*nArgIdx)++; (*nArgIdx)++;
return HAS_ARGUMENT; return HAS_ARGUMENT;

View File

@@ -232,7 +232,7 @@ void DumpCombo (HWND hComboBox, int bClear)
if (szTmp[0] != 0) if (szTmp[0] != 0)
{ {
wchar_t q[MAX_PATH * 2] = { 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); fwprintf (f, L"\n\t\t<volume>%s</volume>", q);
} }

View File

@@ -716,7 +716,7 @@ DWORD handleWin32Error (HWND hwndDlg, const char* srcPos)
pszDesc = (wchar_t*) lpMsgBuf; pszDesc = (wchar_t*) lpMsgBuf;
else else
{ {
StringCbPrintfW (szErrorValue, sizeof (szErrorValue), L"Error 0x%.8X", dwError); StringCchPrintfW (szErrorValue, ARRAYSIZE (szErrorValue), L"Error 0x%.8X", dwError);
pszDesc = szErrorValue; pszDesc = szErrorValue;
} }
@@ -853,7 +853,7 @@ std::wstring FitPathInGfxWidth (HWND hwnd, HFONT hFont, LONG width, const std::w
SelectObject (hdc, (HGDIOBJ) hFont); SelectObject (hdc, (HGDIOBJ) hFont);
wchar_t pathBuf[TC_MAX_PATH]; 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) if (DrawText (hdc, pathBuf, (int) path.size(), &rect, DT_CALCRECT | DT_MODIFYSTRING | DT_PATH_ELLIPSIS | DT_SINGLELINE) != 0)
newPath = pathBuf; newPath = pathBuf;
@@ -4898,6 +4898,8 @@ static BOOL PerformBenchmark(HWND hBenchDlg, HWND hwndDlg)
if (QueryPerformanceFrequency (&benchmarkPerformanceFrequency) == 0) if (QueryPerformanceFrequency (&benchmarkPerformanceFrequency) == 0)
{ {
if (ci)
crypto_close (ci);
MessageBoxW (hwndDlg, GetString ("ERR_PERF_COUNTER"), lpszTitle, ICON_HAND); MessageBoxW (hwndDlg, GetString ("ERR_PERF_COUNTER"), lpszTitle, ICON_HAND);
return FALSE; return FALSE;
} }
@@ -4905,6 +4907,8 @@ static BOOL PerformBenchmark(HWND hBenchDlg, HWND hwndDlg)
lpTestBuffer = (BYTE *) malloc(benchmarkBufferSize - (benchmarkBufferSize % 16)); lpTestBuffer = (BYTE *) malloc(benchmarkBufferSize - (benchmarkBufferSize % 16));
if (lpTestBuffer == NULL) if (lpTestBuffer == NULL)
{ {
if (ci)
crypto_close (ci);
MessageBoxW (hwndDlg, GetString ("ERR_MEM_ALLOC"), lpszTitle, ICON_HAND); MessageBoxW (hwndDlg, GetString ("ERR_MEM_ALLOC"), lpszTitle, ICON_HAND);
return FALSE; return FALSE;
} }
@@ -8132,7 +8136,7 @@ BOOL SaveBufferToFile (const char *inputBuffer, const wchar_t *destinationFile,
{ {
dst = CreateFile (destinationFile, dst = CreateFile (destinationFile,
GENERIC_WRITE, 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(); dwLastError = GetLastError();
if (dst == INVALID_HANDLE_VALUE) if (dst == INVALID_HANDLE_VALUE)
{ {
@@ -9372,7 +9376,7 @@ void RestoreDefaultKeyFilesParam (void)
KeyFileRemoveAll (&FirstKeyFile); KeyFileRemoveAll (&FirstKeyFile);
if (defaultKeyFilesParam.FirstKeyFile != NULL) if (defaultKeyFilesParam.FirstKeyFile != NULL)
{ {
FirstKeyFile = KeyFileCloneAll (defaultKeyFilesParam.FirstKeyFile); KeyFileCloneAll (defaultKeyFilesParam.FirstKeyFile, &FirstKeyFile);
KeyFilesEnable = defaultKeyFilesParam.EnableKeyFiles; KeyFilesEnable = defaultKeyFilesParam.EnableKeyFiles;
} }
else else
@@ -11295,7 +11299,7 @@ BOOL IsApplicationInstalled (const wchar_t *appName, BOOL b32bitApp)
const wchar_t *uninstallRegName = L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall"; const wchar_t *uninstallRegName = L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
BOOL installed = FALSE; BOOL installed = FALSE;
HKEY unistallKey; 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) if (res != ERROR_SUCCESS)
{ {
SetLastError (res); SetLastError (res);

View File

@@ -77,7 +77,7 @@ namespace VeraCrypt
void Show (HWND parent) const void Show (HWND parent) const
{ {
char szErrCode[16]; 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) + ")"; 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); MessageBoxA (parent, msgBody.c_str(), "VeraCrypt", MB_ICONERROR | MB_SETFOREGROUND);
} }
@@ -93,7 +93,7 @@ namespace VeraCrypt
void Show (HWND parent) const void Show (HWND parent) const
{ {
char szErrCode[16]; 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) + ")"; 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); MessageBoxA (parent, msgBody.c_str(), "VeraCrypt", MB_ICONERROR | MB_SETFOREGROUND);
} }

View File

@@ -138,7 +138,7 @@ int TCFormatVolume (volatile FORMAT_VOL_PARAMETERS *volParams)
if (volParams->bDevice) if (volParams->bDevice)
{ {
StringCbCopyW (deviceName, sizeof(deviceName), volParams->volumePath); StringCchCopyW (deviceName, ARRAYSIZE(deviceName), volParams->volumePath);
driveLetter = GetDiskDeviceDriveLetter (deviceName); driveLetter = GetDiskDeviceDriveLetter (deviceName);
} }
@@ -874,10 +874,10 @@ BOOL FormatFs (int driveNo, int clusterSize, int fsType)
switch (fsType) switch (fsType)
{ {
case FILESYS_NTFS: case FILESYS_NTFS:
StringCbCopyW (szFsFormat, sizeof (szFsFormat),L"NTFS"); StringCchCopyW (szFsFormat, ARRAYSIZE (szFsFormat),L"NTFS");
break; break;
case FILESYS_EXFAT: case FILESYS_EXFAT:
StringCbCopyW (szFsFormat, sizeof (szFsFormat),L"EXFAT"); StringCchCopyW (szFsFormat, ARRAYSIZE (szFsFormat),L"EXFAT");
break; break;
default: default:
return FALSE; return FALSE;
@@ -886,10 +886,10 @@ BOOL FormatFs (int driveNo, int clusterSize, int fsType)
if (GetSystemDirectory (dllPath, MAX_PATH)) if (GetSystemDirectory (dllPath, MAX_PATH))
{ {
StringCbCatW(dllPath, sizeof(dllPath), L"\\fmifs.dll"); StringCchCatW(dllPath, ARRAYSIZE(dllPath), L"\\fmifs.dll");
} }
else else
StringCbCopyW(dllPath, sizeof(dllPath), L"C:\\Windows\\System32\\fmifs.dll"); StringCchCopyW(dllPath, ARRAYSIZE(dllPath), L"C:\\Windows\\System32\\fmifs.dll");
hModule = LoadLibrary (dllPath); hModule = LoadLibrary (dllPath);
@@ -902,7 +902,7 @@ BOOL FormatFs (int driveNo, int clusterSize, int fsType)
return FALSE; return FALSE;
} }
StringCbCatW (dir, sizeof(dir), L":\\"); StringCchCatW (dir, ARRAYSIZE(dir), L":\\");
FormatExError = TRUE; FormatExError = TRUE;

View File

@@ -119,12 +119,16 @@ KeyFile *KeyFileClone (KeyFile *keyFile)
} }
KeyFile *KeyFileCloneAll (KeyFile *firstKeyFile) void KeyFileCloneAll (KeyFile *firstKeyFile, KeyFile **outputKeyFile)
{
if (outputKeyFile)
{ {
KeyFile *cloneFirstKeyFile = KeyFileClone (firstKeyFile); KeyFile *cloneFirstKeyFile = KeyFileClone (firstKeyFile);
KeyFile *kf; KeyFile *kf;
if (firstKeyFile == NULL) return NULL; KeyFileRemoveAll (outputKeyFile);
if (firstKeyFile)
{
kf = firstKeyFile->Next; kf = firstKeyFile->Next;
while (kf != NULL) while (kf != NULL)
{ {
@@ -132,7 +136,9 @@ KeyFile *KeyFileCloneAll (KeyFile *firstKeyFile)
kf = kf->Next; kf = kf->Next;
} }
return cloneFirstKeyFile; *outputKeyFile = cloneFirstKeyFile;
}
}
} }
@@ -451,7 +457,7 @@ BOOL CALLBACK KeyFilesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
param = (KeyFilesDlgParam *) lParam; param = (KeyFilesDlgParam *) lParam;
origParam = *(KeyFilesDlgParam *) lParam; origParam = *(KeyFilesDlgParam *) lParam;
param->FirstKeyFile = KeyFileCloneAll (param->FirstKeyFile); KeyFileCloneAll (param->FirstKeyFile, &param->FirstKeyFile);
LocalizeDialog (hwndDlg, "IDD_KEYFILES"); LocalizeDialog (hwndDlg, "IDD_KEYFILES");
DragAcceptFiles (hwndDlg, TRUE); DragAcceptFiles (hwndDlg, TRUE);
@@ -637,7 +643,7 @@ BOOL CALLBACK KeyFilesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
KeyFile *kf = (KeyFile *) malloc (sizeof (KeyFile)); KeyFile *kf = (KeyFile *) malloc (sizeof (KeyFile));
if (kf) if (kf)
{ {
DragQueryFile (hdrop, i++, kf->FileName, sizeof (kf->FileName)); DragQueryFile (hdrop, i++, kf->FileName, ARRAYSIZE (kf->FileName));
param->FirstKeyFile = KeyFileAdd (param->FirstKeyFile, kf); param->FirstKeyFile = KeyFileAdd (param->FirstKeyFile, kf);
LoadKeyList (hwndDlg, param->FirstKeyFile); LoadKeyList (hwndDlg, param->FirstKeyFile);
} }

View File

@@ -38,7 +38,7 @@ typedef struct
KeyFile *KeyFileAdd (KeyFile *firstKeyFile, KeyFile *keyFile); KeyFile *KeyFileAdd (KeyFile *firstKeyFile, KeyFile *keyFile);
void KeyFileRemoveAll (KeyFile **firstKeyFile); void KeyFileRemoveAll (KeyFile **firstKeyFile);
KeyFile *KeyFileClone (KeyFile *keyFile); 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 KeyFilesApply (HWND hwndDlg, Password *password, KeyFile *firstKeyFilem, const wchar_t* volumeFileName);
BOOL CALLBACK KeyFilesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); BOOL CALLBACK KeyFilesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);

View File

@@ -43,8 +43,8 @@ void VerifyPasswordAndUpdate (HWND hwndDlg, HWND hButton, HWND hPassword,
UNREFERENCED_PARAMETER (hwndDlg); /* Remove warning */ UNREFERENCED_PARAMETER (hwndDlg); /* Remove warning */
GetWindowText (hPassword, szTmp1, sizeof (szTmp1)); GetWindowText (hPassword, szTmp1, ARRAYSIZE (szTmp1));
GetWindowText (hVerify, szTmp2, sizeof (szTmp2)); GetWindowText (hVerify, szTmp2, ARRAYSIZE (szTmp2));
utf8Len1 = WideCharToMultiByte (CP_UTF8, 0, szTmp1, -1, szTmp1Utf8, MAX_PASSWORD + 1, NULL, NULL); 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); utf8Len2 = WideCharToMultiByte (CP_UTF8, 0, szTmp2, -1, szTmp2Utf8, MAX_PASSWORD + 1, NULL, NULL);

View File

@@ -78,23 +78,23 @@ BOOL UpdateProgressBarProc (__int64 byteOffset)
double perc = (double) (100.0 * (bProgressBarReverse ? ((double) (TotalSize - byteOffset)) : ((double) byteOffset)) / (TotalSize == 0 ? 0.0001 : ((double) TotalSize))); double perc = (double) (100.0 * (bProgressBarReverse ? ((double) (TotalSize - byteOffset)) : ((double) byteOffset)) / (TotalSize == 0 ? 0.0001 : ((double) TotalSize)));
if (perc > 99.999999999) if (perc > 99.999999999)
StringCbCopyW (text,sizeof(text), GetString ("PROCESSED_PORTION_100_PERCENT")); StringCchCopyW (text,ARRAYSIZE(text), GetString ("PROCESSED_PORTION_100_PERCENT"));
else 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 else
{ {
GetSizeString (bytesDone, text, sizeof(text)); GetSizeString (bytesDone, text, sizeof(text));
if (bytesDone < (unsigned __int64) BYTES_PER_MB * 1000000) 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) 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) 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 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); SetWindowTextW (GetDlgItem (hCurPage, IDC_BYTESWRITTEN), text);
@@ -102,7 +102,7 @@ BOOL UpdateProgressBarProc (__int64 byteOffset)
if (!bShowStatus) if (!bShowStatus)
{ {
GetSpeedString (bRWThroughput ? bytesPerSec*2 : bytesPerSec, speed, sizeof(speed)); GetSpeedString (bRWThroughput ? bytesPerSec*2 : bytesPerSec, speed, sizeof(speed));
StringCbCatW (speed, sizeof(speed), L" "); StringCchCatW (speed, ARRAYSIZE(speed), L" ");
SetWindowTextW (GetDlgItem (hCurPage, IDC_WRITESPEED), speed); SetWindowTextW (GetDlgItem (hCurPage, IDC_WRITESPEED), speed);
} }
@@ -111,15 +111,15 @@ BOOL UpdateProgressBarProc (__int64 byteOffset)
int64 sec = (int64) ((bProgressBarReverse ? byteOffset : (TotalSize - byteOffset)) / (bytesPerSec == 0 ? 0.001 : bytesPerSec)); int64 sec = (int64) ((bProgressBarReverse ? byteOffset : (TotalSize - byteOffset)) / (bytesPerSec == 0 ? 0.001 : bytesPerSec));
if (bytesPerSec == 0 || sec > 60 * 60 * 24 * 999) 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) 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) 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) 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 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); SetWindowTextW (GetDlgItem (hCurPage, IDC_TIMEREMAIN), text);
} }

View File

@@ -671,10 +671,10 @@ BOOL SlowPoll (void)
wchar_t dllPath[MAX_PATH]; wchar_t dllPath[MAX_PATH];
if (GetSystemDirectory (dllPath, MAX_PATH)) if (GetSystemDirectory (dllPath, MAX_PATH))
{ {
StringCbCatW(dllPath, sizeof(dllPath), L"\\NETAPI32.DLL"); StringCchCatW(dllPath, ARRAYSIZE(dllPath), L"\\NETAPI32.DLL");
} }
else else
StringCbCopyW(dllPath, sizeof(dllPath), L"C:\\Windows\\System32\\NETAPI32.DLL"); StringCchCopyW(dllPath, ARRAYSIZE(dllPath), L"C:\\Windows\\System32\\NETAPI32.DLL");
hNetAPI32 = LoadLibrary (dllPath); hNetAPI32 = LoadLibrary (dllPath);
if (hNetAPI32 != NULL) if (hNetAPI32 != NULL)
@@ -725,7 +725,7 @@ BOOL SlowPoll (void)
wchar_t szDevice[24]; wchar_t szDevice[24];
/* Check whether we can access this device */ /* 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, hDevice = CreateFile (szDevice, 0, FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, NULL); NULL, OPEN_EXISTING, 0, NULL);
if (hDevice == INVALID_HANDLE_VALUE) if (hDevice == INVALID_HANDLE_VALUE)

View File

@@ -1022,16 +1022,16 @@ int CreateVolumeHeaderInMemory (HWND hwndDlg, BOOL bBoot, char *header, int ea,
for (i = 0; i < j; i++) for (i = 0; i < j; i++)
{ {
wchar_t tmp2[8] = {0}; wchar_t tmp2[8] = {0};
StringCbPrintfW (tmp2, sizeof(tmp2), L"%02X", (int) (unsigned char) keyInfo.master_keydata[i + primaryKeyOffset]); StringCchPrintfW (tmp2, ARRAYSIZE(tmp2), L"%02X", (int) (unsigned char) keyInfo.master_keydata[i + primaryKeyOffset]);
StringCbCatW (MasterKeyGUIView, sizeof(MasterKeyGUIView), tmp2); StringCchCatW (MasterKeyGUIView, ARRAYSIZE(MasterKeyGUIView), tmp2);
} }
HeaderKeyGUIView[0] = 0; HeaderKeyGUIView[0] = 0;
for (i = 0; i < NBR_KEY_BYTES_TO_DISPLAY; i++) for (i = 0; i < NBR_KEY_BYTES_TO_DISPLAY; i++)
{ {
wchar_t tmp2[8]; wchar_t tmp2[8];
StringCbPrintfW (tmp2, sizeof(tmp2), L"%02X", (int) (unsigned char) dk[primaryKeyOffset + i]); StringCchPrintfW (tmp2, ARRAYSIZE(tmp2), L"%02X", (int) (unsigned char) dk[primaryKeyOffset + i]);
StringCbCatW (HeaderKeyGUIView, sizeof(HeaderKeyGUIView), tmp2); StringCchCatW (HeaderKeyGUIView, ARRAYSIZE(HeaderKeyGUIView), tmp2);
} }
if (dots3) if (dots3)

View File

@@ -568,6 +568,7 @@ void WhirlpoolTransform(uint64 *digest, const uint64 *block)
uint64 s[8]; // the cipher state uint64 s[8]; // the cipher state
uint64 k[8]; // the round key uint64 k[8]; // the round key
int r; 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 // Compute and apply K^0 to the cipher state
// Also apply part of the Miyaguchi-Preneel compression function // Also apply part of the Miyaguchi-Preneel compression function
@@ -627,7 +628,6 @@ void WhirlpoolTransform(uint64 *digest, const uint64 *block)
r=0; r=0;
while (1) while (1)
{ {
uint64 w0, w1, w2, w3, w4, w5, w6, w7; // temporary storage
uint32 t; uint32 t;
KSL(0, 4, 3, 2, 1, 0) KSL(0, 4, 3, 2, 1, 0)

View File

@@ -305,7 +305,7 @@ 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."); 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); hEntropyBar = GetDlgItem (hwndDlg, IDC_ENTROPY_BAR);
SendMessage (hEntropyBar, PBM_SETRANGE32, 0, maxEntropyLevel); SendMessage (hEntropyBar, PBM_SETRANGE32, 0, maxEntropyLevel);
SendMessage (hEntropyBar, PBM_SETSTEP, 1, 0); SendMessage (hEntropyBar, PBM_SETSTEP, 1, 0);

View File

@@ -759,7 +759,7 @@ BOOL CALLBACK ExtcvPasswordDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARA
KeyFile *kf = (KeyFile *) malloc (sizeof (KeyFile)); KeyFile *kf = (KeyFile *) malloc (sizeof (KeyFile));
if (kf) if (kf)
{ {
DragQueryFile (hdrop, i++, kf->FileName, sizeof (kf->FileName)); DragQueryFile (hdrop, i++, kf->FileName, ARRAYSIZE (kf->FileName));
FirstKeyFile = KeyFileAdd (FirstKeyFile, kf); FirstKeyFile = KeyFileAdd (FirstKeyFile, kf);
KeyFilesEnable = TRUE; KeyFilesEnable = TRUE;
} }

View File

@@ -414,7 +414,7 @@ int EncryptPartitionInPlaceBegin (volatile FORMAT_VOL_PARAMETERS *volParams, vol
dataAreaSize = GetVolumeDataAreaSize (volParams->hiddenVol, deviceSize); dataAreaSize = GetVolumeDataAreaSize (volParams->hiddenVol, deviceSize);
StringCbCopyW (deviceName, sizeof(deviceName), volParams->volumePath); StringCchCopyW (deviceName, ARRAYSIZE(deviceName), volParams->volumePath);
driveLetter = GetDiskDeviceDriveLetter (deviceName); driveLetter = GetDiskDeviceDriveLetter (deviceName);
@@ -1284,6 +1284,16 @@ int DecryptPartitionInPlace (volatile FORMAT_VOL_PARAMETERS *volParams, volatile
goto closing_seq; 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; sectorSize = driveGeometry.BytesPerSector;

Binary file not shown.

View File

@@ -389,7 +389,12 @@ BOOL CALLBACK HotkeysDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPar
DisplayHotkeyList(hwndDlg); 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; return 1;
} }

View File

@@ -280,8 +280,9 @@ extern "C" int UacChangePwd (wchar_t *lpszVolume, Password *oldPassword, int old
if (ComGetInstance (hwndDlg, &tc)) if (ComGetInstance (hwndDlg, &tc))
{ {
CComBSTR bstrVolume (lpszVolume);
WaitCursor (); 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 (); NormalCursor ();
} }
else else

View File

@@ -1552,7 +1552,15 @@ void LoadDriveLetters (HWND hwndDlg, HWND hTree, int drive)
GetSizeString (GetSysEncDeviceSize(TRUE), szTmpW, sizeof(szTmpW)); GetSizeString (GetSysEncDeviceSize(TRUE), szTmpW, sizeof(szTmpW));
ListSubItemSet (hTree, listItem.iItem, 2, szTmpW); ListSubItemSet (hTree, listItem.iItem, 2, szTmpW);
if (propSysEnc.ea >= EAGetFirst() && propSysEnc.ea <= EAGetCount())
{
EAGetName (szTmp, propSysEnc.ea, 1); EAGetName (szTmp, propSysEnc.ea, 1);
}
else
{
szTmp[0] = L'?';
szTmp[1] = 0;
}
listItem.iSubItem = 3; listItem.iSubItem = 3;
ListView_SetItem (hTree, &listItem); ListView_SetItem (hTree, &listItem);
@@ -3002,7 +3010,7 @@ BOOL CALLBACK PasswordDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
KeyFile *kf = (KeyFile *) malloc (sizeof (KeyFile)); KeyFile *kf = (KeyFile *) malloc (sizeof (KeyFile));
if (kf) if (kf)
{ {
DragQueryFile (hdrop, i++, kf->FileName, sizeof (kf->FileName)); DragQueryFile (hdrop, i++, kf->FileName, ARRAYSIZE (kf->FileName));
FirstKeyFile = KeyFileAdd (FirstKeyFile, kf); FirstKeyFile = KeyFileAdd (FirstKeyFile, kf);
KeyFilesEnable = TRUE; KeyFilesEnable = TRUE;
} }
@@ -3744,7 +3752,7 @@ BOOL CALLBACK VolumePropertiesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
// Encryption algorithm // Encryption algorithm
ListItemAdd (list, i, GetString ("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"?"); ListSubItemSet (list, i, 1, L"?");
return 1; return 1;
@@ -5849,13 +5857,13 @@ static BOOL CheckMountList (HWND hwndDlg, BOOL bForceTaskBarUpdate)
LoadDriveLetters (hwndDlg, GetDlgItem (MainDlg, IDC_DRIVELIST), 0); LoadDriveLetters (hwndDlg, GetDlgItem (MainDlg, IDC_DRIVELIST), 0);
NormalCursor (); 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; nSelectedDriveIndex = -1;
return FALSE; return FALSE;
} }
if (selDrive != -1) if (selDrive != ((wchar_t) 0xFFFF))
SelectItem (GetDlgItem (MainDlg, IDC_DRIVELIST),selDrive); SelectItem (GetDlgItem (MainDlg, IDC_DRIVELIST),selDrive);
} }
@@ -5900,12 +5908,12 @@ static BOOL CheckMountList (HWND hwndDlg, BOOL bForceTaskBarUpdate)
RecentBootEncStatus = newBootEncStatus; 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; nSelectedDriveIndex = -1;
} }
if (selDrive != -1) if (selDrive != ((wchar_t) 0xFFFF))
{ {
SelectItem (GetDlgItem (MainDlg, IDC_DRIVELIST),selDrive); SelectItem (GetDlgItem (MainDlg, IDC_DRIVELIST),selDrive);
} }
@@ -6069,10 +6077,10 @@ void DisplayDriveListContextMenu (HWND hwndDlg, LPARAM lParam)
{ {
pt.x += 2 + ::GetSystemMetrics(SM_CXICON); pt.x += 2 + ::GetSystemMetrics(SM_CXICON);
pt.y += 2; pt.y += 2;
}
ClientToScreen (hList, &pt); ClientToScreen (hList, &pt);
mPos = MAKELONG (pt.x, pt.y); mPos = MAKELONG (pt.x, pt.y);
} }
}
menuItem = TrackPopupMenu (popup, menuItem = TrackPopupMenu (popup,
TPM_RETURNCMD | TPM_LEFTBUTTON, TPM_RETURNCMD | TPM_LEFTBUTTON,
@@ -6277,8 +6285,8 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
if (FirstCmdKeyFile) if (FirstCmdKeyFile)
{ {
KeyFilesEnable = defaultKeyFilesParam.EnableKeyFiles = TRUE; KeyFilesEnable = defaultKeyFilesParam.EnableKeyFiles = TRUE;
FirstKeyFile = KeyFileCloneAll (FirstCmdKeyFile); KeyFileCloneAll (FirstCmdKeyFile, &FirstKeyFile);
defaultKeyFilesParam.FirstKeyFile = KeyFileCloneAll (FirstCmdKeyFile); KeyFileCloneAll (FirstCmdKeyFile, &defaultKeyFilesParam.FirstKeyFile);
} }
if (!MountAllDevices (hwndDlg, !Silent && !CmdVolumePasswordValid && IsPasswordCacheEmpty())) if (!MountAllDevices (hwndDlg, !Silent && !CmdVolumePasswordValid && IsPasswordCacheEmpty()))
@@ -6291,8 +6299,8 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
if (FirstCmdKeyFile) if (FirstCmdKeyFile)
{ {
KeyFilesEnable = defaultKeyFilesParam.EnableKeyFiles = TRUE; KeyFilesEnable = defaultKeyFilesParam.EnableKeyFiles = TRUE;
FirstKeyFile = KeyFileCloneAll (FirstCmdKeyFile); KeyFileCloneAll (FirstCmdKeyFile, &FirstKeyFile);
defaultKeyFilesParam.FirstKeyFile = KeyFileCloneAll (FirstCmdKeyFile); KeyFileCloneAll (FirstCmdKeyFile, &defaultKeyFilesParam.FirstKeyFile);
} }
if (!MountFavoriteVolumes (hwndDlg, FALSE, LogOn)) if (!MountFavoriteVolumes (hwndDlg, FALSE, LogOn))
@@ -6342,6 +6350,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
if (FirstCmdKeyFile) if (FirstCmdKeyFile)
{ {
KeyFileRemoveAll (&FirstKeyFile);
FirstKeyFile = FirstCmdKeyFile; FirstKeyFile = FirstCmdKeyFile;
KeyFilesEnable = TRUE; KeyFilesEnable = TRUE;
} }
@@ -7414,7 +7423,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
} }
else else
{ {
GetVolumePath (hwndDlg, volPath, sizeof (volPath)); GetVolumePath (hwndDlg, volPath, ARRAYSIZE (volPath));
WaitCursor (); WaitCursor ();
@@ -8018,7 +8027,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
case WM_DROPFILES: case WM_DROPFILES:
{ {
HDROP hdrop = (HDROP) wParam; HDROP hdrop = (HDROP) wParam;
DragQueryFile (hdrop, 0, szFileName, sizeof szFileName); DragQueryFile (hdrop, 0, szFileName, ARRAYSIZE (szFileName));
DragFinish (hdrop); DragFinish (hdrop);
AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, bHistory); AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, bHistory);
@@ -8173,7 +8182,7 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine)
bAuto = TRUE; bAuto = TRUE;
if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs,
&i, nNoCommandLineArgs, szTmp, sizeof (szTmp))) &i, nNoCommandLineArgs, szTmp, ARRAYSIZE (szTmp)))
{ {
if (!_wcsicmp (szTmp, L"devices")) if (!_wcsicmp (szTmp, L"devices"))
bAutoMountDevices = TRUE; bAutoMountDevices = TRUE;
@@ -8198,7 +8207,7 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine)
bCmdTryEmptyPasswordWhenKeyfileUsedValid = TRUE; bCmdTryEmptyPasswordWhenKeyfileUsedValid = TRUE;
if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, &i, nNoCommandLineArgs, if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, &i, nNoCommandLineArgs,
szTmp, sizeof (szTmp))) szTmp, ARRAYSIZE (szTmp)))
{ {
if (!_wcsicmp(szTmp,L"n") || !_wcsicmp(szTmp,L"no")) if (!_wcsicmp(szTmp,L"n") || !_wcsicmp(szTmp,L"no"))
bCmdTryEmptyPasswordWhenKeyfileUsed = FALSE; bCmdTryEmptyPasswordWhenKeyfileUsed = FALSE;
@@ -8217,7 +8226,7 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine)
bIncludePimInCache = FALSE; bIncludePimInCache = FALSE;
if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, &i, nNoCommandLineArgs, if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, &i, nNoCommandLineArgs,
szTmp, sizeof (szTmp))) szTmp, ARRAYSIZE (szTmp)))
{ {
if (!_wcsicmp(szTmp,L"n") || !_wcsicmp(szTmp,L"no")) if (!_wcsicmp(szTmp,L"n") || !_wcsicmp(szTmp,L"no"))
bCacheInDriver = FALSE; bCacheInDriver = FALSE;
@@ -8242,7 +8251,7 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine)
case CommandDismount: case CommandDismount:
if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, &i, nNoCommandLineArgs, if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, &i, nNoCommandLineArgs,
szDriveLetter, sizeof (szDriveLetter))) szDriveLetter, ARRAYSIZE (szDriveLetter)))
{ {
if ( (wcslen(szDriveLetter) == 1) if ( (wcslen(szDriveLetter) == 1)
|| (wcslen(szDriveLetter) == 2 && szDriveLetter[1] == L':') || (wcslen(szDriveLetter) == 2 && szDriveLetter[1] == L':')
@@ -8272,14 +8281,14 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine)
case OptionKeyfile: case OptionKeyfile:
if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, &i, if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, &i,
nNoCommandLineArgs, tmpPath, sizeof (tmpPath))) nNoCommandLineArgs, tmpPath, ARRAYSIZE (tmpPath)))
{ {
KeyFile *kf; KeyFile *kf;
RelativePath2Absolute (tmpPath); RelativePath2Absolute (tmpPath);
kf = (KeyFile *) malloc (sizeof (KeyFile)); kf = (KeyFile *) malloc (sizeof (KeyFile));
if (kf) if (kf)
{ {
StringCbCopyW (kf->FileName, sizeof(kf->FileName), tmpPath); StringCchCopyW (kf->FileName, ARRAYSIZE(kf->FileName), tmpPath);
FirstCmdKeyFile = KeyFileAdd (FirstCmdKeyFile, kf); FirstCmdKeyFile = KeyFileAdd (FirstCmdKeyFile, kf);
} }
} }
@@ -8290,7 +8299,7 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine)
case OptionLetter: case OptionLetter:
if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, &i, nNoCommandLineArgs, if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, &i, nNoCommandLineArgs,
szDriveLetter, sizeof (szDriveLetter))) szDriveLetter, ARRAYSIZE (szDriveLetter)))
{ {
if ( (wcslen(szDriveLetter) == 1) if ( (wcslen(szDriveLetter) == 1)
|| (wcslen(szDriveLetter) == 2 && szDriveLetter[1] == L':') || (wcslen(szDriveLetter) == 2 && szDriveLetter[1] == L':')
@@ -8315,7 +8324,7 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine)
bHistory = bHistoryCmdLine = TRUE; bHistory = bHistoryCmdLine = TRUE;
if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, &i, nNoCommandLineArgs, if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, &i, nNoCommandLineArgs,
szTmp, sizeof (szTmp))) szTmp, ARRAYSIZE (szTmp)))
{ {
if (!_wcsicmp(szTmp,L"n") || !_wcsicmp(szTmp,L"no")) if (!_wcsicmp(szTmp,L"n") || !_wcsicmp(szTmp,L"no"))
bHistory = FALSE; bHistory = FALSE;
@@ -8331,7 +8340,7 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine)
{ {
wchar_t szTmp[64] = {0}; wchar_t szTmp[64] = {0};
if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs,
&i, nNoCommandLineArgs, szTmp, sizeof (szTmp))) &i, nNoCommandLineArgs, szTmp, ARRAYSIZE (szTmp)))
{ {
if (!_wcsicmp (szTmp, L"ro") || !_wcsicmp (szTmp, L"readonly")) if (!_wcsicmp (szTmp, L"ro") || !_wcsicmp (szTmp, L"readonly"))
mountOptions.ReadOnly = TRUE; mountOptions.ReadOnly = TRUE;
@@ -8370,7 +8379,7 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine)
{ {
wchar_t szTmp[MAX_PASSWORD + 1]; wchar_t szTmp[MAX_PASSWORD + 1];
if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, &i, nNoCommandLineArgs, 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); int iLen = WideCharToMultiByte (CP_UTF8, 0, szTmp, -1, (char*) CmdVolumePassword.Text, MAX_PASSWORD + 1, NULL, NULL);
burn (szTmp, sizeof (szTmp)); burn (szTmp, sizeof (szTmp));
@@ -8389,7 +8398,7 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine)
case OptionVolume: case OptionVolume:
if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, &i, if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, &i,
nNoCommandLineArgs, szFileName, sizeof (szFileName))) nNoCommandLineArgs, szFileName, ARRAYSIZE (szFileName)))
{ {
RelativePath2Absolute (szFileName); RelativePath2Absolute (szFileName);
AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, bHistory); AddComboItem (GetDlgItem (hwndDlg, IDC_VOLUME), szFileName, bHistory);
@@ -8404,7 +8413,7 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine)
wchar_t szTmp[32] = {0}; wchar_t szTmp[32] = {0};
if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, 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 if (!_wcsicmp (szTmp, L"UAC")) // Used to indicate non-install elevation
break; break;
@@ -8433,7 +8442,7 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine)
break; break;
case OptionTokenLib: case OptionTokenLib:
if (GetArgumentValue (lpszCommandLineArgs, &i, nNoCommandLineArgs, SecurityTokenLibraryPath, sizeof (SecurityTokenLibraryPath)) == HAS_ARGUMENT) if (GetArgumentValue (lpszCommandLineArgs, &i, nNoCommandLineArgs, SecurityTokenLibraryPath, ARRAYSIZE (SecurityTokenLibraryPath)) == HAS_ARGUMENT)
InitSecurityTokenLibrary(hwndDlg); InitSecurityTokenLibrary(hwndDlg);
else else
AbortProcess ("COMMAND_LINE_ERROR"); AbortProcess ("COMMAND_LINE_ERROR");
@@ -8454,7 +8463,7 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine)
{ {
wchar_t szTmp[32] = {0}; wchar_t szTmp[32] = {0};
if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, 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) if (_wcsicmp(szTmp, L"sha512") == 0 || _wcsicmp(szTmp, L"sha-512") == 0)
CmdVolumePkcs5 = SHA512; CmdVolumePkcs5 = SHA512;
@@ -8480,7 +8489,7 @@ void ExtractCommandLine (HWND hwndDlg, wchar_t *lpszCommandLine)
{ {
wchar_t szTmp[32] = {0}; wchar_t szTmp[32] = {0};
if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs, if (HAS_ARGUMENT == GetArgumentValue (lpszCommandLineArgs,
&i, nNoCommandLineArgs, szTmp, sizeof (szTmp))) &i, nNoCommandLineArgs, szTmp, ARRAYSIZE (szTmp)))
{ {
wchar_t* endPtr = NULL; wchar_t* endPtr = NULL;
CmdVolumePim = (int) wcstol(szTmp, &endPtr, 0); CmdVolumePim = (int) wcstol(szTmp, &endPtr, 0);
@@ -8871,6 +8880,17 @@ static BOOL MountFavoriteVolumeBase (HWND hwnd, const FavoriteVolume &favorite,
int drive; int drive;
drive = towupper (favorite.MountPoint[0]) - L'A'; 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.ReadOnly = favorite.ReadOnly || userForcedReadOnly;
mountOptions.Removable = favorite.Removable; mountOptions.Removable = favorite.Removable;
if (favorite.UseLabelInExplorer && !favorite.Label.empty()) if (favorite.UseLabelInExplorer && !favorite.Label.empty())

View File

@@ -176,7 +176,7 @@ static int CompressBuffer (char *out, char *in, int len)
startupInfo.hStdError = hChildStdoutWrite; startupInfo.hStdError = hChildStdoutWrite;
startupInfo.dwFlags |= STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; 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)) 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"); 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");
@@ -256,8 +256,8 @@ BOOL MakeSelfExtractingPackage (HWND hwndDlg, wchar_t *szDestDir)
GetModuleFileName (NULL, inputFile, ARRAYSIZE (inputFile)); GetModuleFileName (NULL, inputFile, ARRAYSIZE (inputFile));
StringCbCopyW (outputFile, sizeof(outputFile), szDestDir); StringCchCopyW (outputFile, ARRAYSIZE(outputFile), szDestDir);
StringCbCatW (outputFile, sizeof(outputFile), OutputPackageFile); StringCchCatW (outputFile, ARRAYSIZE(outputFile), OutputPackageFile);
// Clone 'VeraCrypt Setup.exe' to create the base of the new self-extracting archive // Clone 'VeraCrypt Setup.exe' to create the base of the new self-extracting archive
@@ -378,6 +378,16 @@ BOOL MakeSelfExtractingPackage (HWND hwndDlg, wchar_t *szDestDir)
// Compress all the files and meta data in the buffer to create a solid archive // 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 compressedBuffer = malloc (uncompressedDataLen + 524288); // + 512K reserve
if (compressedBuffer == NULL) if (compressedBuffer == NULL)
{ {
@@ -745,8 +755,8 @@ void __cdecl ExtractAllFilesThread (void *hwndDlg)
// Filename // Filename
StringCchCopyNW (fileName, ARRAYSIZE(fileName), Decompressed_Files[fileNo].fileName, Decompressed_Files[fileNo].fileNameLength); StringCchCopyNW (fileName, ARRAYSIZE(fileName), Decompressed_Files[fileNo].fileName, Decompressed_Files[fileNo].fileNameLength);
StringCbCopyW (filePath, sizeof(filePath), DestExtractPath); StringCchCopyW (filePath, ARRAYSIZE(filePath), DestExtractPath);
StringCbCatW (filePath, sizeof(filePath), fileName); StringCchCatW (filePath, ARRAYSIZE(filePath), fileName);
StatusMessageParam (hwndDlg, "EXTRACTING_VERB", filePath); StatusMessageParam (hwndDlg, "EXTRACTING_VERB", filePath);

View File

@@ -712,7 +712,7 @@ BOOL DoFilesInstall (HWND hwndDlg, wchar_t *szDestDir)
StringCbCatW (szDir, sizeof(szDir), L"Drivers\\"); StringCbCatW (szDir, sizeof(szDir), L"Drivers\\");
} }
else if (*szFiles[i] == L'W') else if (*szFiles[i] == L'W')
GetWindowsDirectory (szDir, sizeof (szDir)); GetWindowsDirectory (szDir, ARRAYSIZE (szDir));
if (*szFiles[i] == L'I') if (*szFiles[i] == L'I')
continue; continue;