diff options
Diffstat (limited to 'src/Common')
-rw-r--r-- | src/Common/BootEncryption.cpp | 32 | ||||
-rw-r--r-- | src/Common/Cmdline.c | 11 | ||||
-rw-r--r-- | src/Common/Format.c | 14 | ||||
-rw-r--r-- | src/Common/Keyfiles.c | 109 | ||||
-rw-r--r-- | src/Common/Language.c | 50 | ||||
-rw-r--r-- | src/Common/Progress.c | 32 | ||||
-rw-r--r-- | src/Common/Random.c | 7 | ||||
-rw-r--r-- | src/Common/Tcdefs.h | 2 | ||||
-rw-r--r-- | src/Common/Volumes.c | 14 |
9 files changed, 165 insertions, 106 deletions
diff --git a/src/Common/BootEncryption.cpp b/src/Common/BootEncryption.cpp index 1a467eed..0fec2878 100644 --- a/src/Common/BootEncryption.cpp +++ b/src/Common/BootEncryption.cpp | |||
@@ -32,6 +32,8 @@ | |||
32 | #include "Mount/MainCom.h" | 32 | #include "Mount/MainCom.h" |
33 | #endif | 33 | #endif |
34 | 34 | ||
35 | #include <Strsafe.h> | ||
36 | |||
35 | namespace VeraCrypt | 37 | namespace VeraCrypt |
36 | { | 38 | { |
37 | #if !defined (SETUP) | 39 | #if !defined (SETUP) |
@@ -604,7 +606,7 @@ namespace VeraCrypt | |||
604 | GetSystemDriveConfiguration(); | 606 | GetSystemDriveConfiguration(); |
605 | 607 | ||
606 | ProbeRealDriveSizeRequest request; | 608 | ProbeRealDriveSizeRequest request; |
607 | _snwprintf (request.DeviceName, array_capacity (request.DeviceName), L"%hs", DriveConfig.DrivePartition.DevicePath.c_str()); | 609 | StringCbPrintfW (request.DeviceName, sizeof (request.DeviceName), L"%hs", DriveConfig.DrivePartition.DevicePath.c_str()); |
608 | 610 | ||
609 | CallDriver (TC_IOCTL_PROBE_REAL_DRIVE_SIZE, &request, sizeof (request), &request, sizeof (request)); | 611 | CallDriver (TC_IOCTL_PROBE_REAL_DRIVE_SIZE, &request, sizeof (request), &request, sizeof (request)); |
610 | DriveConfig.DrivePartition.Info.PartitionLength = request.RealDriveSize; | 612 | DriveConfig.DrivePartition.Info.PartitionLength = request.RealDriveSize; |
@@ -633,7 +635,7 @@ namespace VeraCrypt | |||
633 | partPath << "\\Device\\Harddisk" << driveNumber << "\\Partition" << partNumber; | 635 | partPath << "\\Device\\Harddisk" << driveNumber << "\\Partition" << partNumber; |
634 | 636 | ||
635 | DISK_PARTITION_INFO_STRUCT diskPartInfo; | 637 | DISK_PARTITION_INFO_STRUCT diskPartInfo; |
636 | _snwprintf (diskPartInfo.deviceName, array_capacity (diskPartInfo.deviceName), L"%hs", partPath.str().c_str()); | 638 | StringCbPrintfW (diskPartInfo.deviceName, sizeof (diskPartInfo.deviceName), L"%hs", partPath.str().c_str()); |
637 | 639 | ||
638 | try | 640 | try |
639 | { | 641 | { |
@@ -663,7 +665,7 @@ namespace VeraCrypt | |||
663 | 665 | ||
664 | // Volume ID | 666 | // Volume ID |
665 | wchar_t volumePath[TC_MAX_PATH]; | 667 | wchar_t volumePath[TC_MAX_PATH]; |
666 | if (ResolveSymbolicLink ((wchar_t *) ws.str().c_str(), volumePath)) | 668 | if (ResolveSymbolicLink ((wchar_t *) ws.str().c_str(), volumePath, sizeof(volumePath))) |
667 | { | 669 | { |
668 | wchar_t volumeName[TC_MAX_PATH]; | 670 | wchar_t volumeName[TC_MAX_PATH]; |
669 | HANDLE fh = FindFirstVolumeW (volumeName, array_capacity (volumeName)); | 671 | HANDLE fh = FindFirstVolumeW (volumeName, array_capacity (volumeName)); |
@@ -742,8 +744,8 @@ namespace VeraCrypt | |||
742 | memset (&openTestStruct, 0, sizeof (openTestStruct)); | 744 | memset (&openTestStruct, 0, sizeof (openTestStruct)); |
743 | DWORD dwResult; | 745 | DWORD dwResult; |
744 | 746 | ||
745 | strcpy ((char *) &openTestStruct.wszFileName[0], devicePath); | 747 | StringCbCopyA ((char *) &openTestStruct.wszFileName[0], sizeof(openTestStruct.wszFileName),devicePath); |
746 | ToUNICODE ((char *) &openTestStruct.wszFileName[0]); | 748 | ToUNICODE ((char *) &openTestStruct.wszFileName[0], sizeof(openTestStruct.wszFileName)); |
747 | 749 | ||
748 | openTestStruct.bDetectTCBootLoader = TRUE; | 750 | openTestStruct.bDetectTCBootLoader = TRUE; |
749 | 751 | ||
@@ -844,7 +846,7 @@ namespace VeraCrypt | |||
844 | bool BootEncryption::SystemDriveIsDynamic () | 846 | bool BootEncryption::SystemDriveIsDynamic () |
845 | { | 847 | { |
846 | GetSystemDriveConfigurationRequest request; | 848 | GetSystemDriveConfigurationRequest request; |
847 | _snwprintf (request.DevicePath, array_capacity (request.DevicePath), L"%hs", GetSystemDriveConfiguration().DeviceKernelPath.c_str()); | 849 | StringCbPrintfW (request.DevicePath, sizeof (request.DevicePath), L"%hs", GetSystemDriveConfiguration().DeviceKernelPath.c_str()); |
848 | 850 | ||
849 | CallDriver (TC_IOCTL_GET_SYSTEM_DRIVE_CONFIG, &request, sizeof (request), &request, sizeof (request)); | 851 | CallDriver (TC_IOCTL_GET_SYSTEM_DRIVE_CONFIG, &request, sizeof (request), &request, sizeof (request)); |
850 | return request.DriveIsDynamic ? true : false; | 852 | return request.DriveIsDynamic ? true : false; |
@@ -1095,7 +1097,7 @@ namespace VeraCrypt | |||
1095 | throw ParameterIncorrect (SRC_POS); | 1097 | throw ParameterIncorrect (SRC_POS); |
1096 | 1098 | ||
1097 | GetSystemDriveConfigurationRequest request; | 1099 | GetSystemDriveConfigurationRequest request; |
1098 | _snwprintf (request.DevicePath, array_capacity (request.DevicePath), L"%hs", GetSystemDriveConfiguration().DeviceKernelPath.c_str()); | 1100 | StringCbPrintfW (request.DevicePath, sizeof (request.DevicePath), L"%hs", GetSystemDriveConfiguration().DeviceKernelPath.c_str()); |
1099 | 1101 | ||
1100 | try | 1102 | try |
1101 | { | 1103 | { |
@@ -1402,8 +1404,10 @@ namespace VeraCrypt | |||
1402 | memset (image, 0, RescueIsoImageSize); | 1404 | memset (image, 0, RescueIsoImageSize); |
1403 | 1405 | ||
1404 | // Primary volume descriptor | 1406 | // Primary volume descriptor |
1405 | strcpy ((char *)image + 0x8000, "\001CD001\001"); | 1407 | const char* szPrimVolDesc = "\001CD001\001"; |
1406 | strcpy ((char *)image + 0x7fff + 41, "VeraCrypt Rescue Disk "); | 1408 | const char* szPrimVolLabel = "VeraCrypt Rescue Disk "; |
1409 | memcpy (image + 0x8000, szPrimVolDesc, strlen(szPrimVolDesc) + 1); | ||
1410 | memcpy (image + 0x7fff + 41, szPrimVolLabel, strlen(szPrimVolLabel) + 1); | ||
1407 | *(uint32 *) (image + 0x7fff + 81) = RescueIsoImageSize / 2048; | 1411 | *(uint32 *) (image + 0x7fff + 81) = RescueIsoImageSize / 2048; |
1408 | *(uint32 *) (image + 0x7fff + 85) = BE32 (RescueIsoImageSize / 2048); | 1412 | *(uint32 *) (image + 0x7fff + 85) = BE32 (RescueIsoImageSize / 2048); |
1409 | image[0x7fff + 121] = 1; | 1413 | image[0x7fff + 121] = 1; |
@@ -1420,11 +1424,13 @@ namespace VeraCrypt | |||
1420 | image[0x7fff + 159] = 0x18; | 1424 | image[0x7fff + 159] = 0x18; |
1421 | 1425 | ||
1422 | // Boot record volume descriptor | 1426 | // Boot record volume descriptor |
1423 | strcpy ((char *)image + 0x8801, "CD001\001EL TORITO SPECIFICATION"); | 1427 | const char* szBootRecDesc = "CD001\001EL TORITO SPECIFICATION"; |
1428 | memcpy (image + 0x8801, szBootRecDesc, strlen(szBootRecDesc) + 1); | ||
1424 | image[0x8800 + 0x47] = 0x19; | 1429 | image[0x8800 + 0x47] = 0x19; |
1425 | 1430 | ||
1426 | // Volume descriptor set terminator | 1431 | // Volume descriptor set terminator |
1427 | strcpy ((char *)image + 0x9000, "\377CD001\001"); | 1432 | const char* szVolDescTerm = "\377CD001\001"; |
1433 | memcpy (image + 0x9000, szVolDescTerm, strlen(szVolDescTerm) + 1); | ||
1428 | 1434 | ||
1429 | // Path table | 1435 | // Path table |
1430 | image[0xA000 + 0] = 1; | 1436 | image[0xA000 + 0] = 1; |
@@ -1722,7 +1728,7 @@ namespace VeraCrypt | |||
1722 | DWORD size = sizeof (regKeyBuf) - strSize; | 1728 | DWORD size = sizeof (regKeyBuf) - strSize; |
1723 | 1729 | ||
1724 | // SetupInstallFromInfSection() does not support prepending of values so we have to modify the registry directly | 1730 | // SetupInstallFromInfSection() does not support prepending of values so we have to modify the registry directly |
1725 | strncpy ((char *) regKeyBuf, filter.c_str(), sizeof (regKeyBuf)); | 1731 | StringCbCopyA ((char *) regKeyBuf, sizeof(regKeyBuf), filter.c_str()); |
1726 | 1732 | ||
1727 | if (RegQueryValueEx (regKey, filterReg.c_str(), NULL, NULL, regKeyBuf + strSize, &size) != ERROR_SUCCESS) | 1733 | if (RegQueryValueEx (regKey, filterReg.c_str(), NULL, NULL, regKeyBuf + strSize, &size) != ERROR_SUCCESS) |
1728 | size = 1; | 1734 | size = 1; |
@@ -2318,7 +2324,7 @@ namespace VeraCrypt | |||
2318 | void BootEncryption::RestrictPagingFilesToSystemPartition () | 2324 | void BootEncryption::RestrictPagingFilesToSystemPartition () |
2319 | { | 2325 | { |
2320 | char pagingFiles[128]; | 2326 | char pagingFiles[128]; |
2321 | strncpy (pagingFiles, "X:\\pagefile.sys 0 0", sizeof (pagingFiles)); | 2327 | StringCbCopyA (pagingFiles, sizeof(pagingFiles), "X:\\pagefile.sys 0 0"); |
2322 | pagingFiles[0] = GetWindowsDirectory()[0]; | 2328 | pagingFiles[0] = GetWindowsDirectory()[0]; |
2323 | 2329 | ||
2324 | throw_sys_if (!WriteLocalMachineRegistryMultiString ("System\\CurrentControlSet\\Control\\Session Manager\\Memory Management", "PagingFiles", pagingFiles, strlen (pagingFiles) + 2)); | 2330 | throw_sys_if (!WriteLocalMachineRegistryMultiString ("System\\CurrentControlSet\\Control\\Session Manager\\Memory Management", "PagingFiles", pagingFiles, strlen (pagingFiles) + 2)); |
diff --git a/src/Common/Cmdline.c b/src/Common/Cmdline.c index 35507c2b..f1f9a8fc 100644 --- a/src/Common/Cmdline.c +++ b/src/Common/Cmdline.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include "Apidrvr.h" | 20 | #include "Apidrvr.h" |
21 | #include "Dlgcode.h" | 21 | #include "Dlgcode.h" |
22 | #include "Language.h" | 22 | #include "Language.h" |
23 | #include <Strsafe.h> | ||
23 | 24 | ||
24 | /* Except in response to the WM_INITDIALOG message, the dialog box procedure | 25 | /* Except in response to the WM_INITDIALOG message, the dialog box procedure |
25 | should return nonzero if it processes the message, and zero if it does | 26 | should return nonzero if it processes the message, and zero if it does |
@@ -44,13 +45,13 @@ BOOL CALLBACK CommandHelpDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM | |||
44 | 45 | ||
45 | *tmp = 0; | 46 | *tmp = 0; |
46 | 47 | ||
47 | strcpy (tmp, "Command line options:\n\n"); | 48 | StringCbCopyA (tmp, 8192, "Command line options:\n\n"); |
48 | for (i = 0; i < as->arg_cnt; i ++) | 49 | for (i = 0; i < as->arg_cnt; i ++) |
49 | { | 50 | { |
50 | if (!as->args[i].Internal) | 51 | if (!as->args[i].Internal) |
51 | { | 52 | { |
52 | sprintf(tmp2, "%s\t%s\n", as->args[i].short_name, as->args[i].long_name); | 53 | StringCchPrintf(tmp2, MAX_PATH * 2, "%s\t%s\n", as->args[i].short_name, as->args[i].long_name); |
53 | strcat(tmp,tmp2); | 54 | StringCchCat(tmp, 8192, tmp2); |
54 | } | 55 | } |
55 | } | 56 | } |
56 | 57 | ||
@@ -220,7 +221,7 @@ int GetArgumentValue (char **lpszCommandLineArgs, int nArgPos, int *nArgIdx, | |||
220 | { | 221 | { |
221 | /* Handles the case of no space between parameter code and | 222 | /* Handles the case of no space between parameter code and |
222 | value */ | 223 | value */ |
223 | strncpy (lpszValue, &lpszCommandLineArgs[*nArgIdx][nArgPos], nValueSize); | 224 | StringCbCopyA (lpszValue, nValueSize, &lpszCommandLineArgs[*nArgIdx][nArgPos]); |
224 | lpszValue[nValueSize - 1] = 0; | 225 | lpszValue[nValueSize - 1] = 0; |
225 | return HAS_ARGUMENT; | 226 | return HAS_ARGUMENT; |
226 | } | 227 | } |
@@ -231,7 +232,7 @@ int GetArgumentValue (char **lpszCommandLineArgs, int nArgPos, int *nArgIdx, | |||
231 | { | 232 | { |
232 | /* Handles the case of space between parameter code | 233 | /* Handles the case of space between parameter code |
233 | and value */ | 234 | and value */ |
234 | strncpy (lpszValue, &lpszCommandLineArgs[*nArgIdx + 1][x], nValueSize); | 235 | StringCbCopyA (lpszValue, nValueSize, &lpszCommandLineArgs[*nArgIdx + 1][x]); |
235 | lpszValue[nValueSize - 1] = 0; | 236 | lpszValue[nValueSize - 1] = 0; |
236 | (*nArgIdx)++; | 237 | (*nArgIdx)++; |
237 | return HAS_ARGUMENT; | 238 | return HAS_ARGUMENT; |
diff --git a/src/Common/Format.c b/src/Common/Format.c index 25f20acd..ad6be026 100644 --- a/src/Common/Format.c +++ b/src/Common/Format.c | |||
@@ -29,6 +29,8 @@ | |||
29 | #include "Format/FormatCom.h" | 29 | #include "Format/FormatCom.h" |
30 | #include "Format/Tcformat.h" | 30 | #include "Format/Tcformat.h" |
31 | 31 | ||
32 | #include <Strsafe.h> | ||
33 | |||
32 | int FormatWriteBufferSize = 1024 * 1024; | 34 | int FormatWriteBufferSize = 1024 * 1024; |
33 | static uint32 FormatSectorSize = 0; | 35 | static uint32 FormatSectorSize = 0; |
34 | 36 | ||
@@ -129,8 +131,8 @@ int TCFormatVolume (volatile FORMAT_VOL_PARAMETERS *volParams) | |||
129 | 131 | ||
130 | if (volParams->bDevice) | 132 | if (volParams->bDevice) |
131 | { | 133 | { |
132 | strcpy ((char *)deviceName, volParams->volumePath); | 134 | StringCbCopyA ((char *)deviceName, sizeof(deviceName), volParams->volumePath); |
133 | ToUNICODE ((char *)deviceName); | 135 | ToUNICODE ((char *)deviceName, sizeof(deviceName)); |
134 | 136 | ||
135 | driveLetter = GetDiskDeviceDriveLetter (deviceName); | 137 | driveLetter = GetDiskDeviceDriveLetter (deviceName); |
136 | } | 138 | } |
@@ -170,7 +172,7 @@ begin_format: | |||
170 | DWORD dwResult; | 172 | DWORD dwResult; |
171 | int nPass; | 173 | int nPass; |
172 | 174 | ||
173 | if (FakeDosNameForDevice (volParams->volumePath, dosDev, devName, FALSE) != 0) | 175 | if (FakeDosNameForDevice (volParams->volumePath, dosDev, sizeof(dosDev), devName, sizeof(devName), FALSE) != 0) |
174 | return ERR_OS_ERROR; | 176 | return ERR_OS_ERROR; |
175 | 177 | ||
176 | if (IsDeviceMounted (devName)) | 178 | if (IsDeviceMounted (devName)) |
@@ -803,10 +805,10 @@ BOOL FormatNtfs (int driveNo, int clusterSize) | |||
803 | 805 | ||
804 | if (GetSystemDirectory (dllPath, MAX_PATH)) | 806 | if (GetSystemDirectory (dllPath, MAX_PATH)) |
805 | { | 807 | { |
806 | strcat(dllPath, "\\fmifs.dll"); | 808 | StringCbCatA(dllPath, sizeof(dllPath), "\\fmifs.dll"); |
807 | } | 809 | } |
808 | else | 810 | else |
809 | strcpy(dllPath, "C:\\Windows\\System32\\fmifs.dll"); | 811 | StringCbCopyA(dllPath, sizeof(dllPath), "C:\\Windows\\System32\\fmifs.dll"); |
810 | 812 | ||
811 | hModule = LoadLibrary (dllPath); | 813 | hModule = LoadLibrary (dllPath); |
812 | 814 | ||
@@ -819,7 +821,7 @@ BOOL FormatNtfs (int driveNo, int clusterSize) | |||
819 | return FALSE; | 821 | return FALSE; |
820 | } | 822 | } |
821 | 823 | ||
822 | wcscat (dir, L":\\"); | 824 | StringCbCatW (dir, sizeof(dir), L":\\"); |
823 | 825 | ||
824 | FormatExResult = FALSE; | 826 | FormatExResult = FALSE; |
825 | 827 | ||
diff --git a/src/Common/Keyfiles.c b/src/Common/Keyfiles.c index e7e55ca5..4a6baf46 100644 --- a/src/Common/Keyfiles.c +++ b/src/Common/Keyfiles.c | |||
@@ -23,11 +23,12 @@ | |||
23 | #include "Platform/Finally.h" | 23 | #include "Platform/Finally.h" |
24 | #include "Platform/ForEach.h" | 24 | #include "Platform/ForEach.h" |
25 | 25 | ||
26 | #include <Strsafe.h> | ||
27 | |||
26 | using namespace VeraCrypt; | 28 | using namespace VeraCrypt; |
27 | 29 | ||
28 | #define stat _stat | 30 | #define stat _stat |
29 | #define S_IFDIR _S_IFDIR | 31 | #define S_IFDIR _S_IFDIR |
30 | #define snprintf _snprintf | ||
31 | 32 | ||
32 | 33 | ||
33 | BOOL HiddenFilesPresentInKeyfilePath = FALSE; | 34 | BOOL HiddenFilesPresentInKeyfilePath = FALSE; |
@@ -97,13 +98,16 @@ void KeyFileRemoveAll (KeyFile **firstKeyFile) | |||
97 | 98 | ||
98 | KeyFile *KeyFileClone (KeyFile *keyFile) | 99 | KeyFile *KeyFileClone (KeyFile *keyFile) |
99 | { | 100 | { |
100 | KeyFile *clone; | 101 | KeyFile *clone = NULL; |
101 | 102 | ||
102 | if (keyFile == NULL) return NULL; | 103 | if (keyFile == NULL) return NULL; |
103 | 104 | ||
104 | clone = (KeyFile *) malloc (sizeof (KeyFile)); | 105 | clone = (KeyFile *) malloc (sizeof (KeyFile)); |
105 | strcpy (clone->FileName, keyFile->FileName); | 106 | if (clone) |
106 | clone->Next = NULL; | 107 | { |
108 | StringCbCopyA (clone->FileName, sizeof(clone->FileName), keyFile->FileName); | ||
109 | clone->Next = NULL; | ||
110 | } | ||
107 | return clone; | 111 | return clone; |
108 | } | 112 | } |
109 | 113 | ||
@@ -298,7 +302,7 @@ BOOL KeyFilesApply (Password *password, KeyFile *firstKeyFile) | |||
298 | /* Find and process all keyfiles in the directory */ | 302 | /* Find and process all keyfiles in the directory */ |
299 | int keyfileCount = 0; | 303 | int keyfileCount = 0; |
300 | 304 | ||
301 | snprintf (searchPath, sizeof (searchPath), "%s\\*.*", kf->FileName); | 305 | StringCbPrintfA (searchPath, sizeof (searchPath), "%s\\*.*", kf->FileName); |
302 | if ((searchHandle = _findfirst (searchPath, &fBuf)) == -1) | 306 | if ((searchHandle = _findfirst (searchPath, &fBuf)) == -1) |
303 | { | 307 | { |
304 | handleWin32Error (MainDlg); | 308 | handleWin32Error (MainDlg); |
@@ -311,7 +315,7 @@ BOOL KeyFilesApply (Password *password, KeyFile *firstKeyFile) | |||
311 | { | 315 | { |
312 | WIN32_FILE_ATTRIBUTE_DATA fileAttributes; | 316 | WIN32_FILE_ATTRIBUTE_DATA fileAttributes; |
313 | 317 | ||
314 | snprintf (kfSub->FileName, sizeof(kfSub->FileName), "%s%c%s", kf->FileName, | 318 | StringCbPrintfA (kfSub->FileName, sizeof(kfSub->FileName), "%s%c%s", kf->FileName, |
315 | '\\', | 319 | '\\', |
316 | fBuf.name | 320 | fBuf.name |
317 | ); | 321 | ); |
@@ -462,18 +466,21 @@ BOOL CALLBACK KeyFilesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa | |||
462 | if (lw == IDC_KEYADD) | 466 | if (lw == IDC_KEYADD) |
463 | { | 467 | { |
464 | KeyFile *kf = (KeyFile *) malloc (sizeof (KeyFile)); | 468 | KeyFile *kf = (KeyFile *) malloc (sizeof (KeyFile)); |
465 | if (SelectMultipleFiles (hwndDlg, "SELECT_KEYFILE", kf->FileName, bHistory)) | 469 | if (kf) |
466 | { | 470 | { |
467 | do | 471 | if (SelectMultipleFiles (hwndDlg, "SELECT_KEYFILE", kf->FileName, sizeof(kf->FileName),bHistory)) |
468 | { | 472 | { |
469 | param->FirstKeyFile = KeyFileAdd (param->FirstKeyFile, kf); | 473 | do |
470 | LoadKeyList (hwndDlg, param->FirstKeyFile); | 474 | { |
475 | param->FirstKeyFile = KeyFileAdd (param->FirstKeyFile, kf); | ||
476 | LoadKeyList (hwndDlg, param->FirstKeyFile); | ||
471 | 477 | ||
472 | kf = (KeyFile *) malloc (sizeof (KeyFile)); | 478 | kf = (KeyFile *) malloc (sizeof (KeyFile)); |
473 | } while (SelectMultipleFilesNext (kf->FileName)); | 479 | } while (SelectMultipleFilesNext (kf->FileName, sizeof(kf->FileName))); |
474 | } | 480 | } |
475 | 481 | ||
476 | free (kf); | 482 | free (kf); |
483 | } | ||
477 | return 1; | 484 | return 1; |
478 | } | 485 | } |
479 | 486 | ||
@@ -501,10 +508,13 @@ BOOL CALLBACK KeyFilesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa | |||
501 | foreach (const SecurityTokenKeyfilePath &keyPath, selectedTokenKeyfiles) | 508 | foreach (const SecurityTokenKeyfilePath &keyPath, selectedTokenKeyfiles) |
502 | { | 509 | { |
503 | KeyFile *kf = (KeyFile *) malloc (sizeof (KeyFile)); | 510 | KeyFile *kf = (KeyFile *) malloc (sizeof (KeyFile)); |
504 | strcpy_s (kf->FileName, sizeof (kf->FileName), WideToSingleString (keyPath).c_str()); | 511 | if (kf) |
512 | { | ||
513 | strcpy_s (kf->FileName, sizeof (kf->FileName), WideToSingleString (keyPath).c_str()); | ||
505 | 514 | ||
506 | param->FirstKeyFile = KeyFileAdd (param->FirstKeyFile, kf); | 515 | param->FirstKeyFile = KeyFileAdd (param->FirstKeyFile, kf); |
507 | LoadKeyList (hwndDlg, param->FirstKeyFile); | 516 | LoadKeyList (hwndDlg, param->FirstKeyFile); |
517 | } | ||
508 | } | 518 | } |
509 | } | 519 | } |
510 | 520 | ||
@@ -574,9 +584,12 @@ BOOL CALLBACK KeyFilesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa | |||
574 | while (count-- > 0) | 584 | while (count-- > 0) |
575 | { | 585 | { |
576 | KeyFile *kf = (KeyFile *) malloc (sizeof (KeyFile)); | 586 | KeyFile *kf = (KeyFile *) malloc (sizeof (KeyFile)); |
577 | DragQueryFile (hdrop, i++, kf->FileName, sizeof (kf->FileName)); | 587 | if (kf) |
578 | param->FirstKeyFile = KeyFileAdd (param->FirstKeyFile, kf); | 588 | { |
579 | LoadKeyList (hwndDlg, param->FirstKeyFile); | 589 | DragQueryFile (hdrop, i++, kf->FileName, sizeof (kf->FileName)); |
590 | param->FirstKeyFile = KeyFileAdd (param->FirstKeyFile, kf); | ||
591 | LoadKeyList (hwndDlg, param->FirstKeyFile); | ||
592 | } | ||
580 | } | 593 | } |
581 | 594 | ||
582 | DragFinish (hdrop); | 595 | DragFinish (hdrop); |
@@ -614,6 +627,8 @@ BOOL CALLBACK KeyFilesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa | |||
614 | BOOL KeyfilesPopupMenu (HWND hwndDlg, POINT popupPosition, KeyFilesDlgParam *param) | 627 | BOOL KeyfilesPopupMenu (HWND hwndDlg, POINT popupPosition, KeyFilesDlgParam *param) |
615 | { | 628 | { |
616 | HMENU popup = CreatePopupMenu (); | 629 | HMENU popup = CreatePopupMenu (); |
630 | if (!popup) | ||
631 | return FALSE; | ||
617 | int sel; | 632 | int sel; |
618 | BOOL status = FALSE; | 633 | BOOL status = FALSE; |
619 | 634 | ||
@@ -628,35 +643,40 @@ BOOL KeyfilesPopupMenu (HWND hwndDlg, POINT popupPosition, KeyFilesDlgParam *par | |||
628 | case IDM_KEYFILES_POPUP_ADD_FILES: | 643 | case IDM_KEYFILES_POPUP_ADD_FILES: |
629 | { | 644 | { |
630 | KeyFile *kf = (KeyFile *) malloc (sizeof (KeyFile)); | 645 | KeyFile *kf = (KeyFile *) malloc (sizeof (KeyFile)); |
631 | if (SelectMultipleFiles (hwndDlg, "SELECT_KEYFILE", kf->FileName, bHistory)) | 646 | if (kf) |
632 | { | 647 | { |
633 | do | 648 | if (SelectMultipleFiles (hwndDlg, "SELECT_KEYFILE", kf->FileName, sizeof(kf->FileName),bHistory)) |
634 | { | 649 | { |
635 | param->FirstKeyFile = KeyFileAdd (param->FirstKeyFile, kf); | 650 | do |
636 | kf = (KeyFile *) malloc (sizeof (KeyFile)); | 651 | { |
637 | } while (SelectMultipleFilesNext (kf->FileName)); | 652 | param->FirstKeyFile = KeyFileAdd (param->FirstKeyFile, kf); |
653 | kf = (KeyFile *) malloc (sizeof (KeyFile)); | ||
654 | } while (SelectMultipleFilesNext (kf->FileName, sizeof(kf->FileName))); | ||
638 | 655 | ||
639 | param->EnableKeyFiles = TRUE; | 656 | param->EnableKeyFiles = TRUE; |
640 | status = TRUE; | 657 | status = TRUE; |
641 | } | 658 | } |
642 | 659 | ||
643 | free (kf); | 660 | free (kf); |
661 | } | ||
644 | } | 662 | } |
645 | break; | 663 | break; |
646 | 664 | ||
647 | case IDM_KEYFILES_POPUP_ADD_DIR: | 665 | case IDM_KEYFILES_POPUP_ADD_DIR: |
648 | { | 666 | { |
649 | KeyFile *kf = (KeyFile *) malloc (sizeof (KeyFile)); | 667 | KeyFile *kf = (KeyFile *) malloc (sizeof (KeyFile)); |
650 | 668 | if (kf) | |
651 | if (BrowseDirectories (hwndDlg,"SELECT_KEYFILE_PATH", kf->FileName)) | ||
652 | { | 669 | { |
653 | param->FirstKeyFile = KeyFileAdd (param->FirstKeyFile, kf); | 670 | if (BrowseDirectories (hwndDlg,"SELECT_KEYFILE_PATH", kf->FileName)) |
654 | param->EnableKeyFiles = TRUE; | 671 | { |
655 | status = TRUE; | 672 | param->FirstKeyFile = KeyFileAdd (param->FirstKeyFile, kf); |
656 | } | 673 | param->EnableKeyFiles = TRUE; |
657 | else | 674 | status = TRUE; |
658 | { | 675 | } |
659 | free (kf); | 676 | else |
677 | { | ||
678 | free (kf); | ||
679 | } | ||
660 | } | 680 | } |
661 | } | 681 | } |
662 | break; | 682 | break; |
@@ -669,11 +689,14 @@ BOOL KeyfilesPopupMenu (HWND hwndDlg, POINT popupPosition, KeyFilesDlgParam *par | |||
669 | foreach (const SecurityTokenKeyfilePath &keyPath, selectedTokenKeyfiles) | 689 | foreach (const SecurityTokenKeyfilePath &keyPath, selectedTokenKeyfiles) |
670 | { | 690 | { |
671 | KeyFile *kf = (KeyFile *) malloc (sizeof (KeyFile)); | 691 | KeyFile *kf = (KeyFile *) malloc (sizeof (KeyFile)); |
672 | strcpy_s (kf->FileName, sizeof (kf->FileName), WideToSingleString (keyPath).c_str()); | 692 | if (kf) |
673 | 693 | { | |
674 | param->FirstKeyFile = KeyFileAdd (param->FirstKeyFile, kf); | 694 | strcpy_s (kf->FileName, sizeof (kf->FileName), WideToSingleString (keyPath).c_str()); |
675 | param->EnableKeyFiles = TRUE; | 695 | |
676 | status = TRUE; | 696 | param->FirstKeyFile = KeyFileAdd (param->FirstKeyFile, kf); |
697 | param->EnableKeyFiles = TRUE; | ||
698 | status = TRUE; | ||
699 | } | ||
677 | } | 700 | } |
678 | } | 701 | } |
679 | } | 702 | } |
diff --git a/src/Common/Language.c b/src/Common/Language.c index b146f820..3ec95dba 100644 --- a/src/Common/Language.c +++ b/src/Common/Language.c | |||
@@ -26,6 +26,8 @@ | |||
26 | #include "../Setup/Resource.h" | 26 | #include "../Setup/Resource.h" |
27 | #endif | 27 | #endif |
28 | 28 | ||
29 | #include <Strsafe.h> | ||
30 | |||
29 | BOOL LocalizationActive; | 31 | BOOL LocalizationActive; |
30 | int LocalizationSerialNo; | 32 | int LocalizationSerialNo; |
31 | 33 | ||
@@ -68,8 +70,9 @@ static char *MapNextLanguageFile () | |||
68 | GetModuleFileNameW (NULL, f, sizeof (f) / sizeof (f[0])); | 70 | GetModuleFileNameW (NULL, f, sizeof (f) / sizeof (f[0])); |
69 | t = wcsrchr (f, L'\\'); | 71 | t = wcsrchr (f, L'\\'); |
70 | if (t == NULL) return NULL; | 72 | if (t == NULL) return NULL; |
71 | 73 | ||
72 | wcscpy (t, L"\\Language*.xml"); | 74 | *t = 0; |
75 | StringCbCatW (f, sizeof(f), L"\\Language*.xml"); | ||
73 | 76 | ||
74 | LanguageFileFindHandle = FindFirstFileW (f, &find); | 77 | LanguageFileFindHandle = FindFirstFileW (f, &find); |
75 | } | 78 | } |
@@ -88,14 +91,29 @@ static char *MapNextLanguageFile () | |||
88 | 91 | ||
89 | GetModuleFileNameW (NULL, f, sizeof (f) / sizeof(f[0])); | 92 | GetModuleFileNameW (NULL, f, sizeof (f) / sizeof(f[0])); |
90 | t = wcsrchr (f, L'\\'); | 93 | t = wcsrchr (f, L'\\'); |
91 | wcscpy (t + 1, find.cFileName); | 94 | if (t == NULL) |
95 | { | ||
96 | free(LanguageFileBuffer); | ||
97 | return NULL; | ||
98 | } | ||
99 | |||
100 | t[1] = 0; | ||
101 | StringCbCatW (f, sizeof(f),find.cFileName); | ||
92 | 102 | ||
93 | file = CreateFileW (f, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); | 103 | file = CreateFileW (f, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); |
94 | if (file == INVALID_HANDLE_VALUE) return NULL; | 104 | if (file == INVALID_HANDLE_VALUE) |
105 | { | ||
106 | free(LanguageFileBuffer); | ||
107 | return NULL; | ||
108 | } | ||
95 | 109 | ||
96 | ReadFile (file, LanguageFileBuffer, find.nFileSizeLow, &read, NULL); | 110 | ReadFile (file, LanguageFileBuffer, find.nFileSizeLow, &read, NULL); |
97 | CloseHandle (file); | 111 | CloseHandle (file); |
98 | if (read != find.nFileSizeLow) return NULL; | 112 | if (read != find.nFileSizeLow) |
113 | { | ||
114 | free(LanguageFileBuffer); | ||
115 | return NULL; | ||
116 | } | ||
99 | 117 | ||
100 | return LanguageFileBuffer; | 118 | return LanguageFileBuffer; |
101 | } | 119 | } |
@@ -130,7 +148,7 @@ BOOL LoadLanguageFile () | |||
130 | ClearDictionaryPool (); | 148 | ClearDictionaryPool (); |
131 | 149 | ||
132 | if (PreferredLangId[0] != 0) | 150 | if (PreferredLangId[0] != 0) |
133 | strcpy (langId, PreferredLangId); | 151 | StringCbCopyA (langId, sizeof(langId), PreferredLangId); |
134 | 152 | ||
135 | // Parse all available language files until preferred language is found | 153 | // Parse all available language files until preferred language is found |
136 | for (res = MapFirstLanguageFile (); res != NULL; res = MapNextLanguageFile ()) | 154 | for (res = MapFirstLanguageFile (); res != NULL; res = MapNextLanguageFile ()) |
@@ -147,7 +165,7 @@ BOOL LoadLanguageFile () | |||
147 | if (defaultLangParsed && strcmp (attr, VERSION_STRING) && strcmp (attr, "DEBUG")) | 165 | if (defaultLangParsed && strcmp (attr, VERSION_STRING) && strcmp (attr, "DEBUG")) |
148 | { | 166 | { |
149 | wchar_t m[2048]; | 167 | wchar_t m[2048]; |
150 | swprintf (m, L"The installed language pack is incompatible with this version of VeraCrypt (the language pack is for VeraCrypt %hs). A newer version may be available at www.idrix.fr.\n\nTo prevent this message from being displayed, do any of the following:\n\n- Select 'Settings' > 'Language'; then select 'English' and click 'OK'.\n\n- Remove or replace the language pack with a compatible version (the language pack may reside e.g. in 'C:\\Program Files\\VeraCrypt' or '%%LOCALAPPDATA%%\\VirtualStore\\Program Files\\VeraCrypt', etc.)", attr); | 168 | StringCbPrintfW (m, sizeof(m), L"The installed language pack is incompatible with this version of VeraCrypt (the language pack is for VeraCrypt %hs). A newer version may be available at www.idrix.fr.\n\nTo prevent this message from being displayed, do any of the following:\n\n- Select 'Settings' > 'Language'; then select 'English' and click 'OK'.\n\n- Remove or replace the language pack with a compatible version (the language pack may reside e.g. in 'C:\\Program Files\\VeraCrypt' or '%%LOCALAPPDATA%%\\VirtualStore\\Program Files\\VeraCrypt', etc.)", attr); |
151 | MessageBoxW (NULL, m, L"VeraCrypt", MB_ICONERROR); | 169 | MessageBoxW (NULL, m, L"VeraCrypt", MB_ICONERROR); |
152 | continue; | 170 | continue; |
153 | } | 171 | } |
@@ -189,7 +207,7 @@ BOOL LoadLanguageFile () | |||
189 | XmlGetAttributeText (xml, "size", attr, sizeof (attr)); | 207 | XmlGetAttributeText (xml, "size", attr, sizeof (attr)); |
190 | sscanf (attr, "%d", &font.Size); | 208 | sscanf (attr, "%d", &font.Size); |
191 | 209 | ||
192 | strcpy (attr, "font_"); | 210 | StringCbCopyA (attr, sizeof(attr), "font_"); |
193 | XmlGetAttributeText (xml, "class", attr + 5, sizeof (attr) - 5); | 211 | XmlGetAttributeText (xml, "class", attr + 5, sizeof (attr) - 5); |
194 | AddDictionaryEntry ( | 212 | AddDictionaryEntry ( |
195 | AddPoolData ((void *) attr, strlen (attr) + 1), 0, | 213 | AddPoolData ((void *) attr, strlen (attr) + 1), 0, |
@@ -375,13 +393,13 @@ BOOL CALLBACK LanguageDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa | |||
375 | // Language pack version | 393 | // Language pack version |
376 | if (!ActiveLangPackVersion[0] || memcmp (ActiveLangPackVersion, "0.0.0", 5) == 0) | 394 | if (!ActiveLangPackVersion[0] || memcmp (ActiveLangPackVersion, "0.0.0", 5) == 0) |
377 | { | 395 | { |
378 | swprintf (szVers, GetString("LANG_PACK_VERSION"), L"--"); | 396 | StringCbPrintfW (szVers, sizeof(szVers), GetString("LANG_PACK_VERSION"), L"--"); |
379 | } | 397 | } |
380 | else | 398 | else |
381 | { | 399 | { |
382 | nLen = MultiByteToWideChar (CP_UTF8, 0, ActiveLangPackVersion, -1, wversion, sizeof (wversion) / sizeof(wversion[0])); | 400 | nLen = MultiByteToWideChar (CP_UTF8, 0, ActiveLangPackVersion, -1, wversion, sizeof (wversion) / sizeof(wversion[0])); |
383 | if (nLen != 0 && nLen != ERROR_NO_UNICODE_TRANSLATION) | 401 | if (nLen != 0 && nLen != ERROR_NO_UNICODE_TRANSLATION) |
384 | swprintf (szVers, GetString("LANG_PACK_VERSION"), wversion); | 402 | StringCbPrintfW (szVers, sizeof(szVers),GetString("LANG_PACK_VERSION"), wversion); |
385 | } | 403 | } |
386 | SetWindowTextW (GetDlgItem (hwndDlg, IDC_LANGPACK_VERSION), szVers); | 404 | SetWindowTextW (GetDlgItem (hwndDlg, IDC_LANGPACK_VERSION), szVers); |
387 | 405 | ||
@@ -394,7 +412,7 @@ BOOL CALLBACK LanguageDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa | |||
394 | } | 412 | } |
395 | } | 413 | } |
396 | 414 | ||
397 | strcpy (lastLangId, attr); | 415 | StringCbCopyA (lastLangId, sizeof(lastLangId),attr); |
398 | langCount++; | 416 | langCount++; |
399 | } | 417 | } |
400 | } | 418 | } |
@@ -410,7 +428,7 @@ BOOL CALLBACK LanguageDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa | |||
410 | EndDialog (hwndDlg, IDCANCEL); | 428 | EndDialog (hwndDlg, IDCANCEL); |
411 | 429 | ||
412 | if (langCount == 2) | 430 | if (langCount == 2) |
413 | strcpy (PreferredLangId, lastLangId); | 431 | StringCbCopyA (PreferredLangId, sizeof(PreferredLangId), lastLangId); |
414 | 432 | ||
415 | EndDialog (hwndDlg, IDOK); | 433 | EndDialog (hwndDlg, IDOK); |
416 | } | 434 | } |
@@ -446,7 +464,7 @@ BOOL CALLBACK LanguageDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa | |||
446 | } | 464 | } |
447 | 465 | ||
448 | if (SendDlgItemMessage (hwndDlg, IDC_LANGLIST, LB_GETCOUNT, 0, 0) > 1) | 466 | if (SendDlgItemMessage (hwndDlg, IDC_LANGLIST, LB_GETCOUNT, 0, 0) > 1) |
449 | strcpy (PreferredLangId, l); | 467 | StringCbCopyA (PreferredLangId, sizeof(PreferredLangId), l); |
450 | } | 468 | } |
451 | } | 469 | } |
452 | 470 | ||
@@ -465,7 +483,7 @@ BOOL CALLBACK LanguageDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa | |||
465 | char tmpstr [256]; | 483 | char tmpstr [256]; |
466 | 484 | ||
467 | if (strlen (ActiveLangPackVersion) > 0 && strlen (GetPreferredLangId()) > 0) | 485 | if (strlen (ActiveLangPackVersion) > 0 && strlen (GetPreferredLangId()) > 0) |
468 | sprintf (tmpstr, "&langpackversion=%s&lang=%s", ActiveLangPackVersion, GetPreferredLangId()); | 486 | StringCbPrintfA (tmpstr, sizeof(tmpstr), "&langpackversion=%s&lang=%s", ActiveLangPackVersion, GetPreferredLangId()); |
469 | else | 487 | else |
470 | tmpstr[0] = 0; | 488 | tmpstr[0] = 0; |
471 | 489 | ||
@@ -488,7 +506,7 @@ char *GetPreferredLangId () | |||
488 | 506 | ||
489 | void SetPreferredLangId (char *langId) | 507 | void SetPreferredLangId (char *langId) |
490 | { | 508 | { |
491 | strncpy (PreferredLangId, langId, 5); | 509 | StringCbCopyA (PreferredLangId, sizeof(PreferredLangId), langId); |
492 | } | 510 | } |
493 | 511 | ||
494 | 512 | ||
@@ -503,7 +521,7 @@ wchar_t *GetString (const char *stringId) | |||
503 | WCHAR *str = (WCHAR *) GetDictionaryValue (stringId); | 521 | WCHAR *str = (WCHAR *) GetDictionaryValue (stringId); |
504 | if (str != NULL) return str; | 522 | if (str != NULL) return str; |
505 | 523 | ||
506 | wsprintfW (UnknownString, UNKNOWN_STRING_ID L"%hs" UNKNOWN_STRING_ID, stringId); | 524 | StringCbPrintfW (UnknownString, sizeof(UnknownString), UNKNOWN_STRING_ID L"%hs" UNKNOWN_STRING_ID, stringId); |
507 | return UnknownString; | 525 | return UnknownString; |
508 | } | 526 | } |
509 | 527 | ||
diff --git a/src/Common/Progress.c b/src/Common/Progress.c index afa6f645..89697a62 100644 --- a/src/Common/Progress.c +++ b/src/Common/Progress.c | |||
@@ -17,6 +17,8 @@ | |||
17 | #include "../Format/FormatCom.h" | 17 | #include "../Format/FormatCom.h" |
18 | #include "../Format/resource.h" | 18 | #include "../Format/resource.h" |
19 | 19 | ||
20 | #include <Strsafe.h> | ||
21 | |||
20 | static ULONG prevTime, startTime; | 22 | static ULONG prevTime, startTime; |
21 | static __int64 TotalSize; | 23 | static __int64 TotalSize; |
22 | static __int64 resumedPointBytesDone; | 24 | static __int64 resumedPointBytesDone; |
@@ -74,31 +76,31 @@ BOOL UpdateProgressBarProc (__int64 byteOffset) | |||
74 | double perc = (double) (100.0 * (bProgressBarReverse ? ((double) (TotalSize - byteOffset)) : ((double) byteOffset)) / (TotalSize == 0 ? 0.0001 : ((double) TotalSize))); | 76 | double perc = (double) (100.0 * (bProgressBarReverse ? ((double) (TotalSize - byteOffset)) : ((double) byteOffset)) / (TotalSize == 0 ? 0.0001 : ((double) TotalSize))); |
75 | 77 | ||
76 | if (perc > 99.999999999) | 78 | if (perc > 99.999999999) |
77 | wcscpy (text, GetString ("PROCESSED_PORTION_100_PERCENT")); | 79 | StringCbCopyW (text,sizeof(text), GetString ("PROCESSED_PORTION_100_PERCENT")); |
78 | else | 80 | else |
79 | _snwprintf (text, sizeof text/2, GetString ("PROCESSED_PORTION_X_PERCENT"), perc); | 81 | StringCbPrintfW (text, sizeof text, GetString ("PROCESSED_PORTION_X_PERCENT"), perc); |
80 | 82 | ||
81 | wcscat (speed, L" "); | 83 | StringCbCatW (speed, sizeof(speed), L" "); |
82 | } | 84 | } |
83 | else | 85 | else |
84 | { | 86 | { |
85 | GetSizeString (bytesDone, text); | 87 | GetSizeString (bytesDone, text, sizeof(text)); |
86 | if (bytesDone < (unsigned __int64) BYTES_PER_MB * 1000000) | 88 | if (bytesDone < (unsigned __int64) BYTES_PER_MB * 1000000) |
87 | swprintf(text, L"%I64d %s ", bytesDone / BYTES_PER_MB, GetString ("MB")); | 89 | StringCbPrintfW(text, sizeof(text), L"%I64d %s ", bytesDone / BYTES_PER_MB, GetString ("MB")); |
88 | else if (bytesDone < (unsigned __int64) BYTES_PER_GB * 1000000) | 90 | else if (bytesDone < (unsigned __int64) BYTES_PER_GB * 1000000) |
89 | swprintf(text, L"%I64d %s ", bytesDone / BYTES_PER_GB, GetString ("GB")); | 91 | StringCbPrintfW(text, sizeof(text), L"%I64d %s ", bytesDone / BYTES_PER_GB, GetString ("GB")); |
90 | else if (bytesDone < (unsigned __int64) BYTES_PER_TB * 1000000) | 92 | else if (bytesDone < (unsigned __int64) BYTES_PER_TB * 1000000) |
91 | swprintf(text, L"%I64d %s ", bytesDone / BYTES_PER_TB, GetString ("TB")); | 93 | StringCbPrintfW(text, sizeof(text), L"%I64d %s ", bytesDone / BYTES_PER_TB, GetString ("TB")); |
92 | else | 94 | else |
93 | swprintf(text, L"%I64d %s ", bytesDone / BYTES_PER_PB, GetString ("PB")); | 95 | StringCbPrintfW(text, sizeof(text), L"%I64d %s ", bytesDone / BYTES_PER_PB, GetString ("PB")); |
94 | } | 96 | } |
95 | 97 | ||
96 | SetWindowTextW (GetDlgItem (hCurPage, IDC_BYTESWRITTEN), text); | 98 | SetWindowTextW (GetDlgItem (hCurPage, IDC_BYTESWRITTEN), text); |
97 | 99 | ||
98 | if (!bShowStatus) | 100 | if (!bShowStatus) |
99 | { | 101 | { |
100 | GetSpeedString (bRWThroughput ? bytesPerSec*2 : bytesPerSec, speed); | 102 | GetSpeedString (bRWThroughput ? bytesPerSec*2 : bytesPerSec, speed, sizeof(speed)); |
101 | wcscat (speed, L" "); | 103 | StringCbCatW (speed, sizeof(speed), L" "); |
102 | SetWindowTextW (GetDlgItem (hCurPage, IDC_WRITESPEED), speed); | 104 | SetWindowTextW (GetDlgItem (hCurPage, IDC_WRITESPEED), speed); |
103 | } | 105 | } |
104 | 106 | ||
@@ -107,15 +109,15 @@ BOOL UpdateProgressBarProc (__int64 byteOffset) | |||
107 | int64 sec = (int64) ((bProgressBarReverse ? byteOffset : (TotalSize - byteOffset)) / (bytesPerSec == 0 ? 0.001 : bytesPerSec)); | 109 | int64 sec = (int64) ((bProgressBarReverse ? byteOffset : (TotalSize - byteOffset)) / (bytesPerSec == 0 ? 0.001 : bytesPerSec)); |
108 | 110 | ||
109 | if (bytesPerSec == 0 || sec > 60 * 60 * 24 * 999) | 111 | if (bytesPerSec == 0 || sec > 60 * 60 * 24 * 999) |
110 | swprintf (text, L"%s ", GetString ("NOT_APPLICABLE_OR_NOT_AVAILABLE")); | 112 | StringCbPrintfW (text, sizeof(text), L"%s ", GetString ("NOT_APPLICABLE_OR_NOT_AVAILABLE")); |
111 | else if (sec >= 60 * 60 * 24 * 2) | 113 | else if (sec >= 60 * 60 * 24 * 2) |
112 | swprintf (text, L"%I64d %s ", sec / (60 * 24 * 60), days); | 114 | StringCbPrintfW (text, sizeof(text), L"%I64d %s ", sec / (60 * 24 * 60), days); |
113 | else if (sec >= 120 * 60) | 115 | else if (sec >= 120 * 60) |
114 | swprintf (text, L"%I64d %s ", sec / (60 * 60), hours); | 116 | StringCbPrintfW (text, sizeof(text), L"%I64d %s ", sec / (60 * 60), hours); |
115 | else if (sec >= 120) | 117 | else if (sec >= 120) |
116 | swprintf (text, L"%I64d %s ", sec / 60, minutes); | 118 | StringCbPrintfW (text, sizeof(text), L"%I64d %s ", sec / 60, minutes); |
117 | else | 119 | else |
118 | swprintf (text, L"%I64d %s ", sec, seconds); | 120 | StringCbPrintfW (text, sizeof(text), L"%I64d %s ", sec, seconds); |
119 | 121 | ||
120 | SetWindowTextW (GetDlgItem (hCurPage, IDC_TIMEREMAIN), text); | 122 | SetWindowTextW (GetDlgItem (hCurPage, IDC_TIMEREMAIN), text); |
121 | } | 123 | } |
diff --git a/src/Common/Random.c b/src/Common/Random.c index c897e3b7..445e8f24 100644 --- a/src/Common/Random.c +++ b/src/Common/Random.c | |||
@@ -12,6 +12,7 @@ | |||
12 | #include "Tcdefs.h" | 12 | #include "Tcdefs.h" |
13 | #include "Crc.h" | 13 | #include "Crc.h" |
14 | #include "Random.h" | 14 | #include "Random.h" |
15 | #include <Strsafe.h> | ||
15 | 16 | ||
16 | static unsigned __int8 buffer[RNG_POOL_SIZE]; | 17 | static unsigned __int8 buffer[RNG_POOL_SIZE]; |
17 | static unsigned char *pRandPool = NULL; | 18 | static unsigned char *pRandPool = NULL; |
@@ -576,10 +577,10 @@ BOOL SlowPoll (void) | |||
576 | char dllPath[MAX_PATH]; | 577 | char dllPath[MAX_PATH]; |
577 | if (GetSystemDirectory (dllPath, MAX_PATH)) | 578 | if (GetSystemDirectory (dllPath, MAX_PATH)) |
578 | { | 579 | { |
579 | strcat(dllPath, "\\NETAPI32.DLL"); | 580 | StringCbCatA(dllPath, sizeof(dllPath), "\\NETAPI32.DLL"); |
580 | } | 581 | } |
581 | else | 582 | else |
582 | strcpy(dllPath, "C:\\Windows\\System32\\NETAPI32.DLL"); | 583 | StringCbCopyA(dllPath, sizeof(dllPath), "C:\\Windows\\System32\\NETAPI32.DLL"); |
583 | 584 | ||
584 | hNetAPI32 = LoadLibrary (dllPath); | 585 | hNetAPI32 = LoadLibrary (dllPath); |
585 | if (hNetAPI32 != NULL) | 586 | if (hNetAPI32 != NULL) |
@@ -630,7 +631,7 @@ BOOL SlowPoll (void) | |||
630 | char szDevice[24]; | 631 | char szDevice[24]; |
631 | 632 | ||
632 | /* Check whether we can access this device */ | 633 | /* Check whether we can access this device */ |
633 | sprintf (szDevice, "\\\\.\\PhysicalDrive%d", nDrive); | 634 | StringCbPrintfA (szDevice, sizeof(szDevice), "\\\\.\\PhysicalDrive%d", nDrive); |
634 | hDevice = CreateFile (szDevice, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, | 635 | hDevice = CreateFile (szDevice, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, |
635 | NULL, OPEN_EXISTING, 0, NULL); | 636 | NULL, OPEN_EXISTING, 0, NULL); |
636 | if (hDevice == INVALID_HANDLE_VALUE) | 637 | if (hDevice == INVALID_HANDLE_VALUE) |
diff --git a/src/Common/Tcdefs.h b/src/Common/Tcdefs.h index 0bf41d79..423eed27 100644 --- a/src/Common/Tcdefs.h +++ b/src/Common/Tcdefs.h | |||
@@ -197,7 +197,7 @@ typedef int BOOL; | |||
197 | # ifdef DEVICE_DRIVER | 197 | # ifdef DEVICE_DRIVER |
198 | # define trace_msg Dump | 198 | # define trace_msg Dump |
199 | # elif defined (_WIN32) | 199 | # elif defined (_WIN32) |
200 | # define trace_msg(...) do { char msg[2048]; _snprintf (msg, sizeof (msg), __VA_ARGS__); OutputDebugString (msg); } while (0) | 200 | # define trace_msg(...) do { char msg[2048]; StringCbPrintfA (msg, sizeof (msg), __VA_ARGS__); OutputDebugString (msg); } while (0) |
201 | # endif | 201 | # endif |
202 | # define trace_point trace_msg (__FUNCTION__ ":" TC_TO_STRING(__LINE__) "\n") | 202 | # define trace_point trace_msg (__FUNCTION__ ":" TC_TO_STRING(__LINE__) "\n") |
203 | # else | 203 | # else |
diff --git a/src/Common/Volumes.c b/src/Common/Volumes.c index 506a4d04..15ee8fe6 100644 --- a/src/Common/Volumes.c +++ b/src/Common/Volumes.c | |||
@@ -33,6 +33,9 @@ | |||
33 | #include "Volumes.h" | 33 | #include "Volumes.h" |
34 | #include "Pkcs5.h" | 34 | #include "Pkcs5.h" |
35 | 35 | ||
36 | #ifdef _WIN32 | ||
37 | #include <Strsafe.h> | ||
38 | #endif | ||
36 | 39 | ||
37 | /* Volume header v5 structure (used since TrueCrypt 7.0): */ | 40 | /* Volume header v5 structure (used since TrueCrypt 7.0): */ |
38 | // | 41 | // |
@@ -187,6 +190,9 @@ int ReadVolumeHeader (BOOL bBoot, char *encryptedHeader, Password *password, PCR | |||
187 | } | 190 | } |
188 | else | 191 | else |
189 | { | 192 | { |
193 | if (!retInfo) | ||
194 | return ERR_PARAMETER_INCORRECT; | ||
195 | |||
190 | cryptoInfo = *retInfo = crypto_open (); | 196 | cryptoInfo = *retInfo = crypto_open (); |
191 | if (cryptoInfo == NULL) | 197 | if (cryptoInfo == NULL) |
192 | return ERR_OUTOFMEMORY; | 198 | return ERR_OUTOFMEMORY; |
@@ -934,16 +940,16 @@ int CreateVolumeHeaderInMemory (BOOL bBoot, char *header, int ea, int mode, Pass | |||
934 | for (i = 0; i < j; i++) | 940 | for (i = 0; i < j; i++) |
935 | { | 941 | { |
936 | char tmp2[8] = {0}; | 942 | char tmp2[8] = {0}; |
937 | sprintf (tmp2, "%02X", (int) (unsigned char) keyInfo.master_keydata[i + primaryKeyOffset]); | 943 | StringCbPrintfA (tmp2, sizeof(tmp2), "%02X", (int) (unsigned char) keyInfo.master_keydata[i + primaryKeyOffset]); |
938 | strcat (MasterKeyGUIView, tmp2); | 944 | StringCbCatA (MasterKeyGUIView, sizeof(MasterKeyGUIView), tmp2); |
939 | } | 945 | } |
940 | 946 | ||
941 | HeaderKeyGUIView[0] = 0; | 947 | HeaderKeyGUIView[0] = 0; |
942 | for (i = 0; i < NBR_KEY_BYTES_TO_DISPLAY; i++) | 948 | for (i = 0; i < NBR_KEY_BYTES_TO_DISPLAY; i++) |
943 | { | 949 | { |
944 | char tmp2[8]; | 950 | char tmp2[8]; |
945 | sprintf (tmp2, "%02X", (int) (unsigned char) dk[primaryKeyOffset + i]); | 951 | StringCbPrintfA (tmp2, sizeof(tmp2), "%02X", (int) (unsigned char) dk[primaryKeyOffset + i]); |
946 | strcat (HeaderKeyGUIView, tmp2); | 952 | StringCbCatA (HeaderKeyGUIView, sizeof(HeaderKeyGUIView), tmp2); |
947 | } | 953 | } |
948 | 954 | ||
949 | if (dots3) | 955 | if (dots3) |