VeraCrypt
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2014-07-14 17:41:09 +0200
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2014-11-08 23:21:27 +0100
commitc220db01281564bf5b50575ee7e24b38e45f5050 (patch)
tree5e66aa935ec029ca2bac6fa282f4c18710fc2d0d
parentc01f392a7ba1d5cdd4aa182eeb273cf41717d94f (diff)
downloadVeraCrypt-c220db01281564bf5b50575ee7e24b38e45f5050.tar.gz
VeraCrypt-c220db01281564bf5b50575ee7e24b38e45f5050.zip
Static Code Analysis : Generalize the use of Safe String functions. Add some NULL pointer checks. Avoid false-positive detection in AppendMenu (MF_SEPARATOR) calls by setting the last parameter to "" instead of NULL.
-rw-r--r--src/Common/BootEncryption.cpp32
-rw-r--r--src/Common/Cmdline.c11
-rw-r--r--src/Common/Format.c14
-rw-r--r--src/Common/Keyfiles.c109
-rw-r--r--src/Common/Language.c50
-rw-r--r--src/Common/Progress.c32
-rw-r--r--src/Common/Random.c7
-rw-r--r--src/Common/Tcdefs.h2
-rw-r--r--src/Common/Volumes.c14
-rw-r--r--src/Format/InPlace.c34
-rw-r--r--src/Format/Tcformat.c188
-rw-r--r--src/Mount/Favorites.cpp4
-rw-r--r--src/Mount/Hotkeys.c94
-rw-r--r--src/Mount/Mount.c290
-rw-r--r--src/Mount/Mount.h4
15 files changed, 490 insertions, 395 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
35namespace VeraCrypt 37namespace 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
32int FormatWriteBufferSize = 1024 * 1024; 34int FormatWriteBufferSize = 1024 * 1024;
33static uint32 FormatSectorSize = 0; 35static 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
26using namespace VeraCrypt; 28using 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
33BOOL HiddenFilesPresentInKeyfilePath = FALSE; 34BOOL HiddenFilesPresentInKeyfilePath = FALSE;
@@ -97,13 +98,16 @@ void KeyFileRemoveAll (KeyFile **firstKeyFile)
97 98
98KeyFile *KeyFileClone (KeyFile *keyFile) 99KeyFile *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
614BOOL KeyfilesPopupMenu (HWND hwndDlg, POINT popupPosition, KeyFilesDlgParam *param) 627BOOL 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
29BOOL LocalizationActive; 31BOOL LocalizationActive;
30int LocalizationSerialNo; 32int 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
489void SetPreferredLangId (char *langId) 507void 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
20static ULONG prevTime, startTime; 22static ULONG prevTime, startTime;
21static __int64 TotalSize; 23static __int64 TotalSize;
22static __int64 resumedPointBytesDone; 24static __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
16static unsigned __int8 buffer[RNG_POOL_SIZE]; 17static unsigned __int8 buffer[RNG_POOL_SIZE];
17static unsigned char *pRandPool = NULL; 18static 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)
diff --git a/src/Format/InPlace.c b/src/Format/InPlace.c
index c3d09fb3..228e2e5f 100644
--- a/src/Format/InPlace.c
+++ b/src/Format/InPlace.c
@@ -34,6 +34,8 @@ IMPORTANT: Due to this issue, functions in this file must not directly interact
34 34
35#include "InPlace.h" 35#include "InPlace.h"
36 36
37#include <Strsafe.h>
38
37using namespace std; 39using namespace std;
38using namespace VeraCrypt; 40using namespace VeraCrypt;
39 41
@@ -151,15 +153,15 @@ BOOL CheckRequirementsForNonSysInPlaceEnc (const char *devicePath, BOOL silent)
151 153
152 /* Access to the partition */ 154 /* Access to the partition */
153 155
154 strcpy ((char *) devPath, devicePath); 156 StringCbCopyA ((char *) devPath, sizeof(devPath), devicePath);
155 ToUNICODE ((char *) devPath); 157 ToUNICODE ((char *) devPath, sizeof(devPath));
156 158
157 driveLetterNo = GetDiskDeviceDriveLetter (devPath); 159 driveLetterNo = GetDiskDeviceDriveLetter (devPath);
158 160
159 if (driveLetterNo >= 0) 161 if (driveLetterNo >= 0)
160 szRootPath[0] = (char) driveLetterNo + 'A'; 162 szRootPath[0] = (char) driveLetterNo + 'A';
161 163
162 if (FakeDosNameForDevice (devicePath, dosDev, devName, FALSE) != 0) 164 if (FakeDosNameForDevice (devicePath, dosDev, sizeof(dosDev), devName, sizeof(devName),FALSE) != 0)
163 { 165 {
164 if (!silent) 166 if (!silent)
165 { 167 {
@@ -348,13 +350,13 @@ int EncryptPartitionInPlaceBegin (volatile FORMAT_VOL_PARAMETERS *volParams, vol
348 350
349 dataAreaSize = GetVolumeDataAreaSize (volParams->hiddenVol, deviceSize); 351 dataAreaSize = GetVolumeDataAreaSize (volParams->hiddenVol, deviceSize);
350 352
351 strcpy ((char *)deviceName, volParams->volumePath); 353 StringCbCopyA ((char *)deviceName, sizeof(deviceName), volParams->volumePath);
352 ToUNICODE ((char *)deviceName); 354 ToUNICODE ((char *)deviceName, sizeof(deviceName));
353 355
354 driveLetter = GetDiskDeviceDriveLetter (deviceName); 356 driveLetter = GetDiskDeviceDriveLetter (deviceName);
355 357
356 358
357 if (FakeDosNameForDevice (volParams->volumePath, dosDev, devName, FALSE) != 0) 359 if (FakeDosNameForDevice (volParams->volumePath, dosDev, sizeof(dosDev),devName, sizeof(devName),FALSE) != 0)
358 { 360 {
359 nStatus = ERR_OS_ERROR; 361 nStatus = ERR_OS_ERROR;
360 goto closing_seq; 362 goto closing_seq;
@@ -710,10 +712,10 @@ int EncryptPartitionInPlaceResume (HANDLE dev,
710 712
711 if (dev == INVALID_HANDLE_VALUE) 713 if (dev == INVALID_HANDLE_VALUE)
712 { 714 {
713 strcpy ((char *)deviceName, devicePath); 715 StringCbCopyA ((char *)deviceName, sizeof(deviceName), devicePath);
714 ToUNICODE ((char *)deviceName); 716 ToUNICODE ((char *)deviceName, sizeof(deviceName));
715 717
716 if (FakeDosNameForDevice (devicePath, dosDev, devName, FALSE) != 0) 718 if (FakeDosNameForDevice (devicePath, dosDev, sizeof(dosDev),devName, sizeof(devName),FALSE) != 0)
717 { 719 {
718 nStatus = ERR_OS_ERROR; 720 nStatus = ERR_OS_ERROR;
719 goto closing_seq; 721 goto closing_seq;
@@ -1085,9 +1087,9 @@ closing_seq:
1085 wchar_t msg[30000] = {0}; 1087 wchar_t msg[30000] = {0};
1086 wchar_t sizeStr[500] = {0}; 1088 wchar_t sizeStr[500] = {0};
1087 1089
1088 GetSizeString (zeroedSectorCount * sectorSize, sizeStr); 1090 GetSizeString (zeroedSectorCount * sectorSize, sizeStr, sizeof(sizeStr));
1089 1091
1090 wsprintfW (msg, 1092 StringCbPrintfW (msg, sizeof(msg),
1091 GetString ("ZEROED_BAD_SECTOR_COUNT"), 1093 GetString ("ZEROED_BAD_SECTOR_COUNT"),
1092 zeroedSectorCount, 1094 zeroedSectorCount,
1093 sizeStr); 1095 sizeStr);
@@ -1369,10 +1371,10 @@ void ShowInPlaceEncErrMsgWAltSteps (char *iniStrId, BOOL bErr)
1369{ 1371{
1370 wchar_t msg[30000]; 1372 wchar_t msg[30000];
1371 1373
1372 wcscpy (msg, GetString (iniStrId)); 1374 StringCbCopyW (msg, sizeof(msg), GetString (iniStrId));
1373 1375
1374 wcscat (msg, L"\n\n\n"); 1376 StringCbCatW (msg, sizeof(msg), L"\n\n\n");
1375 wcscat (msg, GetString ("INPLACE_ENC_ALTERNATIVE_STEPS")); 1377 StringCbCatW (msg, sizeof(msg), GetString ("INPLACE_ENC_ALTERNATIVE_STEPS"));
1376 1378
1377 if (bErr) 1379 if (bErr)
1378 ErrorDirect (msg); 1380 ErrorDirect (msg);
@@ -1414,7 +1416,7 @@ BOOL SaveNonSysInPlaceEncSettings (int delta, WipeAlgorithmId newWipeAlgorithm)
1414 { 1416 {
1415 if (newWipeAlgorithm != TC_WIPE_NONE) 1417 if (newWipeAlgorithm != TC_WIPE_NONE)
1416 { 1418 {
1417 sprintf (str, "%d", (int) newWipeAlgorithm); 1419 StringCbPrintfA (str, sizeof(str), "%d", (int) newWipeAlgorithm);
1418 1420
1419 SaveBufferToFile (str, GetConfigPath (TC_APPD_FILENAME_NONSYS_INPLACE_ENC_WIPE), strlen(str), FALSE); 1421 SaveBufferToFile (str, GetConfigPath (TC_APPD_FILENAME_NONSYS_INPLACE_ENC_WIPE), strlen(str), FALSE);
1420 } 1422 }
@@ -1423,7 +1425,7 @@ BOOL SaveNonSysInPlaceEncSettings (int delta, WipeAlgorithmId newWipeAlgorithm)
1423 remove (GetConfigPath (TC_APPD_FILENAME_NONSYS_INPLACE_ENC_WIPE)); 1425 remove (GetConfigPath (TC_APPD_FILENAME_NONSYS_INPLACE_ENC_WIPE));
1424 } 1426 }
1425 1427
1426 sprintf (str, "%d", count); 1428 StringCbPrintfA (str, sizeof(str), "%d", count);
1427 1429
1428 return SaveBufferToFile (str, GetConfigPath (TC_APPD_FILENAME_NONSYS_INPLACE_ENC), strlen(str), FALSE); 1430 return SaveBufferToFile (str, GetConfigPath (TC_APPD_FILENAME_NONSYS_INPLACE_ENC), strlen(str), FALSE);
1429 } 1431 }
diff --git a/src/Format/Tcformat.c b/src/Format/Tcformat.c
index 0074a169..d0b247fa 100644
--- a/src/Format/Tcformat.c
+++ b/src/Format/Tcformat.c
@@ -48,6 +48,8 @@
48#include "Wipe.h" 48#include "Wipe.h"
49#include "Xml.h" 49#include "Xml.h"
50 50
51#include <Strsafe.h>
52
51using namespace VeraCrypt; 53using namespace VeraCrypt;
52 54
53enum wizard_pages 55enum wizard_pages
@@ -1217,7 +1219,7 @@ void ComboSelChangeEA (HWND hwndDlg)
1217 switch (cnt) // Number of ciphers in the cascade 1219 switch (cnt) // Number of ciphers in the cascade
1218 { 1220 {
1219 case 2: 1221 case 2:
1220 swprintf (auxLine, GetString ("TWO_LAYER_CASCADE_HELP"), 1222 StringCbPrintfW (auxLine, sizeof(auxLine), GetString ("TWO_LAYER_CASCADE_HELP"),
1221 CipherGetName (cipherIDs[1]), 1223 CipherGetName (cipherIDs[1]),
1222 CipherGetKeySize (cipherIDs[1])*8, 1224 CipherGetKeySize (cipherIDs[1])*8,
1223 CipherGetName (cipherIDs[0]), 1225 CipherGetName (cipherIDs[0]),
@@ -1225,7 +1227,7 @@ void ComboSelChangeEA (HWND hwndDlg)
1225 break; 1227 break;
1226 1228
1227 case 3: 1229 case 3:
1228 swprintf (auxLine, GetString ("THREE_LAYER_CASCADE_HELP"), 1230 StringCbPrintfW (auxLine, sizeof(auxLine), GetString ("THREE_LAYER_CASCADE_HELP"),
1229 CipherGetName (cipherIDs[2]), 1231 CipherGetName (cipherIDs[2]),
1230 CipherGetKeySize (cipherIDs[2])*8, 1232 CipherGetKeySize (cipherIDs[2])*8,
1231 CipherGetName (cipherIDs[1]), 1233 CipherGetName (cipherIDs[1]),
@@ -1235,7 +1237,7 @@ void ComboSelChangeEA (HWND hwndDlg)
1235 break; 1237 break;
1236 } 1238 }
1237 1239
1238 wcscpy_s (hyperLink, sizeof(hyperLink) / 2, GetString ("IDC_LINK_MORE_INFO_ABOUT_CIPHER")); 1240 StringCbCopyW (hyperLink, sizeof(hyperLink), GetString ("IDC_LINK_MORE_INFO_ABOUT_CIPHER"));
1239 1241
1240 SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), auxLine); 1242 SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), auxLine);
1241 } 1243 }
@@ -1454,11 +1456,11 @@ static void UpdateSysEncProgressBar (void)
1454 // Status 1456 // Status
1455 1457
1456 if (locBootEncStatus.TransformWaitingForIdle) 1458 if (locBootEncStatus.TransformWaitingForIdle)
1457 wcscpy (tmpStr, GetString ("PROGRESS_STATUS_WAITING")); 1459 StringCbCopyW (tmpStr, sizeof(tmpStr), GetString ("PROGRESS_STATUS_WAITING"));
1458 else 1460 else
1459 wcscpy (tmpStr, GetString (SystemEncryptionStatus == SYSENC_STATUS_DECRYPTING ? "PROGRESS_STATUS_DECRYPTING" : "PROGRESS_STATUS_ENCRYPTING")); 1461 StringCbCopyW (tmpStr, sizeof(tmpStr), GetString (SystemEncryptionStatus == SYSENC_STATUS_DECRYPTING ? "PROGRESS_STATUS_DECRYPTING" : "PROGRESS_STATUS_ENCRYPTING"));
1460 1462
1461 wcscat (tmpStr, L" "); 1463 StringCbCatW (tmpStr, sizeof(tmpStr), L" ");
1462 1464
1463 SetWindowTextW (GetDlgItem (hCurPage, IDC_WRITESPEED), tmpStr); 1465 SetWindowTextW (GetDlgItem (hCurPage, IDC_WRITESPEED), tmpStr);
1464 } 1466 }
@@ -1518,17 +1520,17 @@ static void UpdateSysEncControls (void)
1518 { 1520 {
1519 wchar_t tmpStr[100]; 1521 wchar_t tmpStr[100];
1520 1522
1521 wcscpy (tmpStr, GetString ((SysDriveOrPartitionFullyEncrypted (TRUE) || !locBootEncStatus.DriveMounted) ? 1523 StringCbCopyW (tmpStr, sizeof(tmpStr), GetString ((SysDriveOrPartitionFullyEncrypted (TRUE) || !locBootEncStatus.DriveMounted) ?
1522 "PROGRESS_STATUS_FINISHED" : "PROGRESS_STATUS_PAUSED")); 1524 "PROGRESS_STATUS_FINISHED" : "PROGRESS_STATUS_PAUSED"));
1523 wcscat (tmpStr, L" "); 1525 StringCbCatW (tmpStr, sizeof(tmpStr), L" ");
1524 1526
1525 // Status 1527 // Status
1526 SetWindowTextW (GetDlgItem (hCurPage, IDC_WRITESPEED), tmpStr); 1528 SetWindowTextW (GetDlgItem (hCurPage, IDC_WRITESPEED), tmpStr);
1527 1529
1528 if (SysDriveOrPartitionFullyEncrypted (TRUE) || SystemEncryptionStatus == SYSENC_STATUS_NONE) 1530 if (SysDriveOrPartitionFullyEncrypted (TRUE) || SystemEncryptionStatus == SYSENC_STATUS_NONE)
1529 { 1531 {
1530 wcscpy (tmpStr, GetString ("PROCESSED_PORTION_100_PERCENT")); 1532 StringCbCopyW (tmpStr, sizeof(tmpStr), GetString ("PROCESSED_PORTION_100_PERCENT"));
1531 wcscat (tmpStr, L" "); 1533 StringCbCatW (tmpStr, sizeof(tmpStr), L" ");
1532 1534
1533 SetWindowTextW (GetDlgItem (hCurPage, IDC_BYTESWRITTEN), tmpStr); 1535 SetWindowTextW (GetDlgItem (hCurPage, IDC_BYTESWRITTEN), tmpStr);
1534 } 1536 }
@@ -1699,9 +1701,9 @@ static BOOL GetDevicePathForHiddenOS (void)
1699 1701
1700 try 1702 try
1701 { 1703 {
1702 strncpy (szFileName, BootEncObj->GetPartitionForHiddenOS().DevicePath.c_str(), sizeof(szFileName) - 1); 1704 StringCbCopyA (szFileName, sizeof(szFileName), BootEncObj->GetPartitionForHiddenOS().DevicePath.c_str());
1703 1705
1704 CreateFullVolumePath (szDiskFile, szFileName, &tmpbDevice); 1706 CreateFullVolumePath (szDiskFile, sizeof(szDiskFile), szFileName, &tmpbDevice);
1705 } 1707 }
1706 catch (Exception &e) 1708 catch (Exception &e)
1707 { 1709 {
@@ -1804,29 +1806,29 @@ void ShowNonSysInPlaceEncUIStatus (void)
1804 switch (NonSysInplaceEncStatus) 1806 switch (NonSysInplaceEncStatus)
1805 { 1807 {
1806 case NONSYS_INPLACE_ENC_STATUS_PAUSED: 1808 case NONSYS_INPLACE_ENC_STATUS_PAUSED:
1807 wcscpy (nonSysInplaceEncUIStatus, GetString ("PROGRESS_STATUS_PAUSED")); 1809 StringCbCopyW (nonSysInplaceEncUIStatus, sizeof(nonSysInplaceEncUIStatus), GetString ("PROGRESS_STATUS_PAUSED"));
1808 break; 1810 break;
1809 case NONSYS_INPLACE_ENC_STATUS_PREPARING: 1811 case NONSYS_INPLACE_ENC_STATUS_PREPARING:
1810 wcscpy (nonSysInplaceEncUIStatus, GetString ("PROGRESS_STATUS_PREPARING")); 1812 StringCbCopyW (nonSysInplaceEncUIStatus, sizeof(nonSysInplaceEncUIStatus), GetString ("PROGRESS_STATUS_PREPARING"));
1811 break; 1813 break;
1812 case NONSYS_INPLACE_ENC_STATUS_RESIZING: 1814 case NONSYS_INPLACE_ENC_STATUS_RESIZING:
1813 wcscpy (nonSysInplaceEncUIStatus, GetString ("PROGRESS_STATUS_RESIZING")); 1815 StringCbCopyW (nonSysInplaceEncUIStatus, sizeof(nonSysInplaceEncUIStatus), GetString ("PROGRESS_STATUS_RESIZING"));
1814 break; 1816 break;
1815 case NONSYS_INPLACE_ENC_STATUS_ENCRYPTING: 1817 case NONSYS_INPLACE_ENC_STATUS_ENCRYPTING:
1816 wcscpy (nonSysInplaceEncUIStatus, GetString ("PROGRESS_STATUS_ENCRYPTING")); 1818 StringCbCopyW (nonSysInplaceEncUIStatus, sizeof(nonSysInplaceEncUIStatus), GetString ("PROGRESS_STATUS_ENCRYPTING"));
1817 break; 1819 break;
1818 case NONSYS_INPLACE_ENC_STATUS_FINALIZING: 1820 case NONSYS_INPLACE_ENC_STATUS_FINALIZING:
1819 wcscpy (nonSysInplaceEncUIStatus, GetString ("PROGRESS_STATUS_FINALIZING")); 1821 StringCbCopyW (nonSysInplaceEncUIStatus, sizeof(nonSysInplaceEncUIStatus), GetString ("PROGRESS_STATUS_FINALIZING"));
1820 break; 1822 break;
1821 case NONSYS_INPLACE_ENC_STATUS_FINISHED: 1823 case NONSYS_INPLACE_ENC_STATUS_FINISHED:
1822 wcscpy (nonSysInplaceEncUIStatus, GetString ("PROGRESS_STATUS_FINISHED")); 1824 StringCbCopyW (nonSysInplaceEncUIStatus, sizeof(nonSysInplaceEncUIStatus), GetString ("PROGRESS_STATUS_FINISHED"));
1823 break; 1825 break;
1824 case NONSYS_INPLACE_ENC_STATUS_ERROR: 1826 case NONSYS_INPLACE_ENC_STATUS_ERROR:
1825 wcscpy (nonSysInplaceEncUIStatus, GetString ("PROGRESS_STATUS_ERROR")); 1827 StringCbCopyW (nonSysInplaceEncUIStatus, sizeof(nonSysInplaceEncUIStatus), GetString ("PROGRESS_STATUS_ERROR"));
1826 break; 1828 break;
1827 } 1829 }
1828 1830
1829 wcscat (nonSysInplaceEncUIStatus, L" "); 1831 StringCbCatW (nonSysInplaceEncUIStatus, sizeof(nonSysInplaceEncUIStatus), L" ");
1830 1832
1831 SetWindowTextW (GetDlgItem (hCurPage, IDC_WRITESPEED), nonSysInplaceEncUIStatus); 1833 SetWindowTextW (GetDlgItem (hCurPage, IDC_WRITESPEED), nonSysInplaceEncUIStatus);
1832} 1834}
@@ -1974,10 +1976,10 @@ void DisplayRandPool (HWND hPoolDisplay, BOOL bShow)
1974 { 1976 {
1975 tmpByte = randPool[row * RANDPOOL_DISPLAY_COLUMNS + col]; 1977 tmpByte = randPool[row * RANDPOOL_DISPLAY_COLUMNS + col];
1976 1978
1977 sprintf ((char *) tmp, bRandPoolDispAscii ? ((tmpByte >= 32 && tmpByte < 255 && tmpByte != '&') ? " %c " : " . ") : "%02X ", tmpByte); 1979 StringCbPrintfA ((char *) tmp, sizeof(tmp), bRandPoolDispAscii ? ((tmpByte >= 32 && tmpByte < 255 && tmpByte != '&') ? " %c " : " . ") : "%02X ", tmpByte);
1978 strcat ((char *) outRandPoolDispBuffer, (char *) tmp); 1980 StringCbCatA ((char *) outRandPoolDispBuffer, sizeof(outRandPoolDispBuffer), (char *) tmp);
1979 } 1981 }
1980 strcat ((char *) outRandPoolDispBuffer, "\n"); 1982 StringCbCatA ((char *) outRandPoolDispBuffer, sizeof(outRandPoolDispBuffer), "\n");
1981 } 1983 }
1982 SetWindowText (hPoolDisplay, (char *) outRandPoolDispBuffer); 1984 SetWindowText (hPoolDisplay, (char *) outRandPoolDispBuffer);
1983 1985
@@ -2300,7 +2302,7 @@ static void __cdecl volTransformThreadFunction (void *hwndDlgArg)
2300 2302
2301 if (! ((bHiddenVol && !bHiddenVolHost) && errno != EACCES)) // Only ask ask for permission to overwrite an existing volume if we're not creating a hidden volume 2303 if (! ((bHiddenVol && !bHiddenVolHost) && errno != EACCES)) // Only ask ask for permission to overwrite an existing volume if we're not creating a hidden volume
2302 { 2304 {
2303 _snwprintf (szTmp, sizeof szTmp / 2, 2305 StringCbPrintfW (szTmp, sizeof szTmp,
2304 GetString (errno == EACCES ? "READONLYPROMPT" : "OVERWRITEPROMPT"), 2306 GetString (errno == EACCES ? "READONLYPROMPT" : "OVERWRITEPROMPT"),
2305 szDiskFile); 2307 szDiskFile);
2306 2308
@@ -2463,7 +2465,7 @@ static void __cdecl volTransformThreadFunction (void *hwndDlgArg)
2463 } 2465 }
2464 else if (!(bHiddenVolHost && hiddenVolHostDriveNo < 0)) // If the error was not that the hidden volume host could not be mounted (this error has already been reported to the user) 2466 else if (!(bHiddenVolHost && hiddenVolHostDriveNo < 0)) // If the error was not that the hidden volume host could not be mounted (this error has already been reported to the user)
2465 { 2467 {
2466 swprintf (szMsg, GetString ("CREATE_FAILED"), szDiskFile); 2468 StringCbPrintfW (szMsg, sizeof(szMsg), GetString ("CREATE_FAILED"), szDiskFile);
2467 MessageBoxW (hwndDlg, szMsg, lpszTitle, ICON_HAND); 2469 MessageBoxW (hwndDlg, szMsg, lpszTitle, ICON_HAND);
2468 } 2470 }
2469 2471
@@ -2904,11 +2906,11 @@ int PrintFreeSpace (HWND hwndTextBox, char *lpszDrive, PLARGE_INTEGER lDiskFree)
2904 2906
2905 if (bHiddenVol && !bHiddenVolHost) // If it's a hidden volume 2907 if (bHiddenVol && !bHiddenVolHost) // If it's a hidden volume
2906 { 2908 {
2907 _snwprintf (szTmp2, sizeof szTmp2 / 2, GetString (nResourceString), ((double) lDiskFree->QuadPart) / nMultiplier); 2909 StringCbPrintfW (szTmp2, sizeof szTmp2, GetString (nResourceString), ((double) lDiskFree->QuadPart) / nMultiplier);
2908 SetWindowTextW (GetDlgItem (hwndTextBox, IDC_SIZEBOX), szTmp2); 2910 SetWindowTextW (GetDlgItem (hwndTextBox, IDC_SIZEBOX), szTmp2);
2909 } 2911 }
2910 else 2912 else
2911 _snwprintf (szTmp2, sizeof szTmp2 / 2, GetString (nResourceString), lpszDrive, ((double) lDiskFree->QuadPart) / nMultiplier); 2913 StringCbPrintfW (szTmp2, sizeof szTmp2, GetString (nResourceString), lpszDrive, ((double) lDiskFree->QuadPart) / nMultiplier);
2912 2914
2913 SetWindowTextW (hwndTextBox, szTmp2); 2915 SetWindowTextW (hwndTextBox, szTmp2);
2914 2916
@@ -2925,7 +2927,7 @@ void DisplaySizingErrorText (HWND hwndTextBox)
2925 if (translateWin32Error (szTmp, sizeof (szTmp) / sizeof(szTmp[0]))) 2927 if (translateWin32Error (szTmp, sizeof (szTmp) / sizeof(szTmp[0])))
2926 { 2928 {
2927 wchar_t szTmp2[1024]; 2929 wchar_t szTmp2[1024];
2928 wsprintfW (szTmp2, L"%s\n%s", GetString ("CANNOT_CALC_SPACE"), szTmp); 2930 StringCbPrintfW (szTmp2, sizeof(szTmp2), L"%s\n%s", GetString ("CANNOT_CALC_SPACE"), szTmp);
2929 SetWindowTextW (hwndTextBox, szTmp2); 2931 SetWindowTextW (hwndTextBox, szTmp2);
2930 } 2932 }
2931 else 2933 else
@@ -3152,8 +3154,8 @@ static BOOL FinalPreTransformPrompts (void)
3152 int driveNo; 3154 int driveNo;
3153 WCHAR deviceName[MAX_PATH]; 3155 WCHAR deviceName[MAX_PATH];
3154 3156
3155 strcpy ((char *)deviceName, szFileName); 3157 StringCbCopyA ((char *)deviceName, sizeof(deviceName), szFileName);
3156 ToUNICODE ((char *)deviceName); 3158 ToUNICODE ((char *)deviceName, sizeof(deviceName));
3157 3159
3158 driveNo = GetDiskDeviceDriveLetter (deviceName); 3160 driveNo = GetDiskDeviceDriveLetter (deviceName);
3159 3161
@@ -3171,7 +3173,7 @@ static BOOL FinalPreTransformPrompts (void)
3171 if (!GetDriveLabel (driveNo, volumeLabel, sizeof (volumeLabel))) 3173 if (!GetDriveLabel (driveNo, volumeLabel, sizeof (volumeLabel)))
3172 volumeLabel[0] = 0; 3174 volumeLabel[0] = 0;
3173 3175
3174 swprintf_s (drive, sizeof (drive)/2, volumeLabel[0] ? L" (%hc: '%s')" : L" (%hc:%s)", 'A' + driveNo, volumeLabel[0] ? volumeLabel : L""); 3176 StringCbPrintfW (drive, sizeof (drive), volumeLabel[0] ? L" (%hc: '%s')" : L" (%hc:%s)", 'A' + driveNo, volumeLabel[0] ? volumeLabel : L"");
3175 } 3177 }
3176 else 3178 else
3177 { 3179 {
@@ -3180,9 +3182,9 @@ static BOOL FinalPreTransformPrompts (void)
3180 } 3182 }
3181 3183
3182 if (bHiddenOS && bHiddenVolHost) 3184 if (bHiddenOS && bHiddenVolHost)
3183 swprintf (szTmp, GetString ("OVERWRITEPROMPT_DEVICE_HIDDEN_OS_PARTITION"), szFileName, drive); 3185 StringCbPrintfW (szTmp, sizeof(szTmp), GetString ("OVERWRITEPROMPT_DEVICE_HIDDEN_OS_PARTITION"), szFileName, drive);
3184 else 3186 else
3185 swprintf (szTmp, GetString (bInPlaceEncNonSys ? "NONSYS_INPLACE_ENC_CONFIRM" : "OVERWRITEPROMPT_DEVICE"), type, szFileName, drive); 3187 StringCbPrintfW (szTmp, sizeof(szTmp), GetString (bInPlaceEncNonSys ? "NONSYS_INPLACE_ENC_CONFIRM" : "OVERWRITEPROMPT_DEVICE"), type, szFileName, drive);
3186 3188
3187 3189
3188 x = MessageBoxW (MainDlg, szTmp, lpszTitle, YES_NO | MB_ICONWARNING | (bInPlaceEncNonSys ? MB_DEFBUTTON1 : MB_DEFBUTTON2)); 3190 x = MessageBoxW (MainDlg, szTmp, lpszTitle, YES_NO | MB_ICONWARNING | (bInPlaceEncNonSys ? MB_DEFBUTTON1 : MB_DEFBUTTON2));
@@ -3208,27 +3210,27 @@ static BOOL FinalPreTransformPrompts (void)
3208 wchar_t tmpMcOption1 [500]; 3210 wchar_t tmpMcOption1 [500];
3209 wchar_t tmpMcOptionCancel [50]; 3211 wchar_t tmpMcOptionCancel [50];
3210 3212
3211 wcscpy (tmpMcMsg, GetString("OVERWRITEPROMPT_DEVICE_SECOND_WARNING_LOTS_OF_DATA")); 3213 StringCbCopyW (tmpMcMsg, sizeof(tmpMcMsg), GetString("OVERWRITEPROMPT_DEVICE_SECOND_WARNING_LOTS_OF_DATA"));
3212 wcscpy (tmpMcOption1, GetString("ERASE_FILES_BY_CREATING_VOLUME")); 3214 StringCbCopyW (tmpMcOption1, sizeof(tmpMcOption1), GetString("ERASE_FILES_BY_CREATING_VOLUME"));
3213 wcscpy (tmpMcOptionCancel, GetString("CANCEL")); 3215 StringCbCopyW (tmpMcOptionCancel, sizeof(tmpMcOptionCancel), GetString("CANCEL"));
3214 3216
3215 wcscat (tmpMcMsg, L"\n\n"); 3217 StringCbCatW (tmpMcMsg, sizeof(tmpMcMsg), L"\n\n");
3216 wcscat (tmpMcMsg, GetString("DRIVE_LETTER_ITEM")); 3218 StringCbCatW (tmpMcMsg, sizeof(tmpMcMsg), GetString("DRIVE_LETTER_ITEM"));
3217 swprintf_s (szTmp, sizeof (szTmp)/2, L"%hc:", 'A' + driveNo); 3219 StringCbPrintfW (szTmp, sizeof (szTmp), L"%hc:", 'A' + driveNo);
3218 wcscat (tmpMcMsg, szTmp); 3220 StringCbCatW (tmpMcMsg, sizeof(tmpMcMsg), szTmp);
3219 3221
3220 wcscat (tmpMcMsg, L"\n"); 3222 StringCbCatW (tmpMcMsg, sizeof(tmpMcMsg), L"\n");
3221 wcscat (tmpMcMsg, GetString("LABEL_ITEM")); 3223 StringCbCatW (tmpMcMsg, sizeof(tmpMcMsg), GetString("LABEL_ITEM"));
3222 wcscat (tmpMcMsg, volumeLabel[0] != 0 ? volumeLabel : GetString("NOT_APPLICABLE_OR_NOT_AVAILABLE")); 3224 StringCbCatW (tmpMcMsg, sizeof(tmpMcMsg), volumeLabel[0] != 0 ? volumeLabel : GetString("NOT_APPLICABLE_OR_NOT_AVAILABLE"));
3223 3225
3224 wcscat (tmpMcMsg, L"\n"); 3226 StringCbCatW (tmpMcMsg, sizeof(tmpMcMsg), L"\n");
3225 wcscat (tmpMcMsg, GetString("SIZE_ITEM")); 3227 StringCbCatW (tmpMcMsg, sizeof(tmpMcMsg), GetString("SIZE_ITEM"));
3226 GetSizeString (nVolumeSize, szTmp); 3228 GetSizeString (nVolumeSize, szTmp, sizeof(szTmp));
3227 wcscat (tmpMcMsg, szTmp); 3229 StringCbCatW (tmpMcMsg, sizeof(tmpMcMsg), szTmp);
3228 3230
3229 wcscat (tmpMcMsg, L"\n"); 3231 StringCbCatW (tmpMcMsg, sizeof(tmpMcMsg), L"\n");
3230 wcscat (tmpMcMsg, GetString("PATH_ITEM")); 3232 StringCbCatW (tmpMcMsg, sizeof(tmpMcMsg), GetString("PATH_ITEM"));
3231 wcscat (tmpMcMsg, deviceName); 3233 StringCbCatW (tmpMcMsg, sizeof(tmpMcMsg), deviceName);
3232 3234
3233 wchar_t *tmpStr[] = {L"", tmpMcMsg, tmpMcOption1, tmpMcOptionCancel, 0}; 3235 wchar_t *tmpStr[] = {L"", tmpMcMsg, tmpMcOption1, tmpMcOptionCancel, 0};
3234 switch (AskMultiChoice ((void **) tmpStr, TRUE)) 3236 switch (AskMultiChoice ((void **) tmpStr, TRUE))
@@ -3258,8 +3260,8 @@ void HandleOldAssignedDriveLetter (void)
3258 WCHAR deviceName[MAX_PATH]; 3260 WCHAR deviceName[MAX_PATH];
3259 int driveLetter = -1; 3261 int driveLetter = -1;
3260 3262
3261 strcpy ((char *)deviceName, szDiskFile); 3263 StringCbCopyA ((char *)deviceName, sizeof(deviceName), szDiskFile);
3262 ToUNICODE ((char *)deviceName); 3264 ToUNICODE ((char *)deviceName, sizeof(deviceName));
3263 driveLetter = GetDiskDeviceDriveLetter (deviceName); 3265 driveLetter = GetDiskDeviceDriveLetter (deviceName);
3264 3266
3265 if (!bHiddenVolHost 3267 if (!bHiddenVolHost
@@ -3269,7 +3271,7 @@ void HandleOldAssignedDriveLetter (void)
3269 char rootPath[] = { (char) driveLetter + 'A', ':', '\\', 0 }; 3271 char rootPath[] = { (char) driveLetter + 'A', ':', '\\', 0 };
3270 wchar_t szTmp[8192]; 3272 wchar_t szTmp[8192];
3271 3273
3272 swprintf (szTmp, GetString ("AFTER_FORMAT_DRIVE_LETTER_WARN"), rootPath[0], rootPath[0], rootPath[0], rootPath[0]); 3274 StringCbPrintfW (szTmp, sizeof(szTmp), GetString ("AFTER_FORMAT_DRIVE_LETTER_WARN"), rootPath[0], rootPath[0], rootPath[0], rootPath[0]);
3273 MessageBoxW (MainDlg, szTmp, lpszTitle, MB_ICONWARNING); 3275 MessageBoxW (MainDlg, szTmp, lpszTitle, MB_ICONWARNING);
3274 } 3276 }
3275 } 3277 }
@@ -3302,7 +3304,7 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
3302 case WM_INITDIALOG: 3304 case WM_INITDIALOG:
3303 LocalizeDialog (hwndDlg, "IDD_VOL_CREATION_WIZARD_DLG"); 3305 LocalizeDialog (hwndDlg, "IDD_VOL_CREATION_WIZARD_DLG");
3304 3306
3305 sprintf (PageDebugId, "FORMAT_PAGE_%d", nCurPageNo); 3307 StringCbPrintfA (PageDebugId, sizeof(PageDebugId), "FORMAT_PAGE_%d", nCurPageNo);
3306 LastDialogId = PageDebugId; 3308 LastDialogId = PageDebugId;
3307 3309
3308 switch (nCurPageNo) 3310 switch (nCurPageNo)
@@ -3760,16 +3762,16 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
3760 3762
3761 if (bHiddenVolHost) 3763 if (bHiddenVolHost)
3762 { 3764 {
3763 wcsncpy (str, GetString ("SIZE_HELP_HIDDEN_HOST_VOL"), sizeof (str) / 2); 3765 StringCbCopyW (str, sizeof(str), GetString ("SIZE_HELP_HIDDEN_HOST_VOL"));
3764 } 3766 }
3765 else 3767 else
3766 { 3768 {
3767 wcsncpy (str, GetString (bHiddenVol ? "SIZE_HELP_HIDDEN_VOL" : "SIZE_HELP"), sizeof (str) / 2); 3769 StringCbCopyW (str, sizeof(str), GetString (bHiddenVol ? "SIZE_HELP_HIDDEN_VOL" : "SIZE_HELP"));
3768 } 3770 }
3769 3771
3770 if (bDevice && !(bHiddenVol && !bHiddenVolHost)) // If raw device but not a hidden volume 3772 if (bDevice && !(bHiddenVol && !bHiddenVolHost)) // If raw device but not a hidden volume
3771 { 3773 {
3772 _snwprintf (str, sizeof str / 2, L"%s%s", 3774 StringCbPrintfW (str, sizeof str, L"%s%s",
3773 GetString ((bHiddenOS && bHiddenVol) ? "SIZE_PARTITION_HIDDEN_SYSENC_HELP" : "SIZE_PARTITION_HELP"), 3775 GetString ((bHiddenOS && bHiddenVol) ? "SIZE_PARTITION_HIDDEN_SYSENC_HELP" : "SIZE_PARTITION_HELP"),
3774 (bHiddenVolHost && !bHiddenOS) ? GetString ("SIZE_PARTITION_HIDDEN_VOL_HELP") : L""); 3776 (bHiddenVolHost && !bHiddenOS) ? GetString ("SIZE_PARTITION_HIDDEN_VOL_HELP") : L"");
3775 } 3777 }
@@ -3823,7 +3825,7 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
3823 if (nUIVolumeSize != 0) 3825 if (nUIVolumeSize != 0)
3824 { 3826 {
3825 char szTmp[32]; 3827 char szTmp[32];
3826 sprintf (szTmp, "%I64u", nUIVolumeSize); 3828 StringCbPrintfA (szTmp, sizeof(szTmp), "%I64u", nUIVolumeSize);
3827 SetWindowText (GetDlgItem (hwndDlg, IDC_SIZEBOX), szTmp); 3829 SetWindowText (GetDlgItem (hwndDlg, IDC_SIZEBOX), szTmp);
3828 } 3830 }
3829 3831
@@ -3882,7 +3884,7 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
3882 ToBootPwdField (hwndDlg, IDC_PASSWORD); 3884 ToBootPwdField (hwndDlg, IDC_PASSWORD);
3883 ToBootPwdField (hwndDlg, IDC_VERIFY); 3885 ToBootPwdField (hwndDlg, IDC_VERIFY);
3884 3886
3885 sprintf (OrigKeyboardLayout, "%08X", (DWORD) GetKeyboardLayout (NULL) & 0xFFFF); 3887 StringCbPrintfA (OrigKeyboardLayout, sizeof(OrigKeyboardLayout), "%08X", (DWORD) GetKeyboardLayout (NULL) & 0xFFFF);
3886 3888
3887 if ((DWORD) GetKeyboardLayout (NULL) != 0x00000409 && (DWORD) GetKeyboardLayout (NULL) != 0x04090409) 3889 if ((DWORD) GetKeyboardLayout (NULL) != 0x00000409 && (DWORD) GetKeyboardLayout (NULL) != 0x04090409)
3888 { 3890 {
@@ -3909,17 +3911,17 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
3909 3911
3910 if (bHiddenVolHost) 3912 if (bHiddenVolHost)
3911 { 3913 {
3912 wcsncpy (str, GetString (bHiddenOS ? "PASSWORD_SYSENC_OUTERVOL_HELP" : "PASSWORD_HIDDENVOL_HOST_HELP"), sizeof (str) / 2); 3914 StringCbCopyW (str, sizeof(str), GetString (bHiddenOS ? "PASSWORD_SYSENC_OUTERVOL_HELP" : "PASSWORD_HIDDENVOL_HOST_HELP"));
3913 } 3915 }
3914 else if (bHiddenVol) 3916 else if (bHiddenVol)
3915 { 3917 {
3916 _snwprintf (str, sizeof str / 2, L"%s%s", 3918 StringCbPrintfW (str, sizeof str, L"%s%s",
3917 GetString (bHiddenOS ? "PASSWORD_HIDDEN_OS_HELP" : "PASSWORD_HIDDENVOL_HELP"), 3919 GetString (bHiddenOS ? "PASSWORD_HIDDEN_OS_HELP" : "PASSWORD_HIDDENVOL_HELP"),
3918 GetString ("PASSWORD_HELP")); 3920 GetString ("PASSWORD_HELP"));
3919 } 3921 }
3920 else 3922 else
3921 { 3923 {
3922 wcsncpy (str, GetString ("PASSWORD_HELP"), sizeof (str) / 2); 3924 StringCbCopyW (str, sizeof(str), GetString ("PASSWORD_HELP"));
3923 } 3925 }
3924 3926
3925 SendMessage (GetDlgItem (hwndDlg, IDC_PASSWORD), EM_LIMITTEXT, MAX_PASSWORD, 0); 3927 SendMessage (GetDlgItem (hwndDlg, IDC_PASSWORD), EM_LIMITTEXT, MAX_PASSWORD, 0);
@@ -3966,22 +3968,22 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
3966 Init2RadButtonPageYesNo (nNeedToStoreFilesOver4GB); 3968 Init2RadButtonPageYesNo (nNeedToStoreFilesOver4GB);
3967 SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("FILESYS_PAGE_TITLE")); 3969 SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("FILESYS_PAGE_TITLE"));
3968 3970
3969 wcscpy (szTmp, GetString ("FILESYS_PAGE_HELP_QUESTION")); 3971 StringCbCopyW (szTmp, sizeof(szTmp), GetString ("FILESYS_PAGE_HELP_QUESTION"));
3970 3972
3971 if (bHiddenVolHost) 3973 if (bHiddenVolHost)
3972 wcscat (szTmp, L"\n\n"); 3974 StringCbCatW (szTmp, sizeof(szTmp), L"\n\n");
3973 else 3975 else
3974 { 3976 {
3975 wcscat (szTmp, L"\n\n\n"); 3977 StringCbCatW (szTmp, sizeof(szTmp), L"\n\n\n");
3976 wcscat (szTmp, GetString ("NOTE_BEGINNING")); 3978 StringCbCatW (szTmp, sizeof(szTmp), GetString ("NOTE_BEGINNING"));
3977 } 3979 }
3978 3980
3979 wcscat (szTmp, GetString ("FILESYS_PAGE_HELP_EXPLANATION")); 3981 StringCbCatW (szTmp, sizeof(szTmp), GetString ("FILESYS_PAGE_HELP_EXPLANATION"));
3980 3982
3981 if (bHiddenVolHost) 3983 if (bHiddenVolHost)
3982 { 3984 {
3983 wcscat (szTmp, L" "); 3985 StringCbCatW (szTmp, sizeof(szTmp), L" ");
3984 wcscat (szTmp, GetString ("FILESYS_PAGE_HELP_EXPLANATION_HIDVOL")); 3986 StringCbCatW (szTmp, sizeof(szTmp), GetString ("FILESYS_PAGE_HELP_EXPLANATION_HIDVOL"));
3985 } 3987 }
3986 3988
3987 SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), szTmp); 3989 SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), szTmp);
@@ -4049,7 +4051,7 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
4049 SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT")); 4051 SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_NEXT), GetString ("NEXT"));
4050 SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV")); 4052 SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_PREV), GetString ("PREV"));
4051 4053
4052 _snwprintf (szTmp, sizeof szTmp / 2, 4054 StringCbPrintfW (szTmp, sizeof szTmp,
4053 GetString (bDontVerifyRescueDisk ? "RESCUE_DISK_BURN_INFO_NO_CHECK" : "RESCUE_DISK_BURN_INFO"), 4055 GetString (bDontVerifyRescueDisk ? "RESCUE_DISK_BURN_INFO_NO_CHECK" : "RESCUE_DISK_BURN_INFO"),
4054 szRescueDiskISO, IsWindowsIsoBurnerAvailable() ? L"" : GetString ("RESCUE_DISK_BURN_INFO_NONWIN_ISO_BURNER")); 4056 szRescueDiskISO, IsWindowsIsoBurnerAvailable() ? L"" : GetString ("RESCUE_DISK_BURN_INFO_NONWIN_ISO_BURNER"));
4055 4057
@@ -4129,7 +4131,7 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
4129 4131
4130 try 4132 try
4131 { 4133 {
4132 wsprintfW (finalMsg, 4134 StringCbPrintfW (finalMsg, sizeof(finalMsg),
4133 GetString ("SYS_ENCRYPTION_PRETEST_INFO"), 4135 GetString ("SYS_ENCRYPTION_PRETEST_INFO"),
4134 BootEncObj->GetSystemDriveConfiguration().DriveNumber); 4136 BootEncObj->GetSystemDriveConfiguration().DriveNumber);
4135 } 4137 }
@@ -4493,12 +4495,12 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
4493 // -50% reserve for filesystem "peculiarities" 4495 // -50% reserve for filesystem "peculiarities"
4494 maxRecomOuterVolFillSize /= 2; 4496 maxRecomOuterVolFillSize /= 2;
4495 4497
4496 swprintf (szMaxRecomOuterVolFillSize, L"%I64d %s", maxRecomOuterVolFillSize / BYTES_PER_MB, GetString ("MB")); 4498 StringCbPrintfW (szMaxRecomOuterVolFillSize, sizeof(szMaxRecomOuterVolFillSize), L"%I64d %s", maxRecomOuterVolFillSize / BYTES_PER_MB, GetString ("MB"));
4497 4499
4498 swprintf (msg, GetString ("HIDVOL_HOST_FILLING_HELP_SYSENC"), hiddenVolHostDriveNo + 'A', szMaxRecomOuterVolFillSize); 4500 StringCbPrintfW (msg, sizeof(msg), GetString ("HIDVOL_HOST_FILLING_HELP_SYSENC"), hiddenVolHostDriveNo + 'A', szMaxRecomOuterVolFillSize);
4499 } 4501 }
4500 else 4502 else
4501 swprintf (msg, GetString ("HIDVOL_HOST_FILLING_HELP"), hiddenVolHostDriveNo + 'A'); 4503 StringCbPrintfW (msg, sizeof(msg), GetString ("HIDVOL_HOST_FILLING_HELP"), hiddenVolHostDriveNo + 'A');
4502 4504
4503 SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), msg); 4505 SetWindowTextW (GetDlgItem (hwndDlg, IDC_BOX_HELP), msg);
4504 SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("HIDVOL_HOST_FILLING_TITLE")); 4506 SetWindowTextW (GetDlgItem (GetParent (hwndDlg), IDC_BOX_TITLE), GetString ("HIDVOL_HOST_FILLING_TITLE"));
@@ -4738,9 +4740,9 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
4738 4740
4739 bWarnOuterVolSuitableFileSys = FALSE; // Do not show this warning anymore (this also prevents potential endless repetition due to some race conditions) 4741 bWarnOuterVolSuitableFileSys = FALSE; // Do not show this warning anymore (this also prevents potential endless repetition due to some race conditions)
4740 4742
4741 wcscpy (szTmp, GetString ("FILESYS_PAGE_HELP_EXPLANATION_HIDVOL")); 4743 StringCbCopyW (szTmp, sizeof(szTmp), GetString ("FILESYS_PAGE_HELP_EXPLANATION_HIDVOL"));
4742 wcscat (szTmp, L"\n\n"); 4744 StringCbCatW (szTmp, sizeof(szTmp), L"\n\n");
4743 wcscat (szTmp, GetString ("FILESYS_PAGE_HELP_EXPLANATION_HIDVOL_CONFIRM")); 4745 StringCbCatW (szTmp, sizeof(szTmp), GetString ("FILESYS_PAGE_HELP_EXPLANATION_HIDVOL_CONFIRM"));
4744 4746
4745 if (MessageBoxW (MainDlg, szTmp, lpszTitle, MB_ICONWARNING | MB_YESNO | MB_DEFBUTTON2) == IDNO) 4747 if (MessageBoxW (MainDlg, szTmp, lpszTitle, MB_ICONWARNING | MB_YESNO | MB_DEFBUTTON2) == IDNO)
4746 { 4748 {
@@ -4834,8 +4836,8 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
4834 4836
4835 SetFocus (GetDlgItem (MainDlg, IDC_NEXT)); 4837 SetFocus (GetDlgItem (MainDlg, IDC_NEXT));
4836 4838
4837 strcpy (szFileName, DeferredNonSysInPlaceEncDevices [selPartitionItemId].Path.c_str()); 4839 StringCbCopyA (szFileName, sizeof(szFileName), DeferredNonSysInPlaceEncDevices [selPartitionItemId].Path.c_str());
4838 CreateFullVolumePath (szDiskFile, szFileName, &tmpbDevice); 4840 CreateFullVolumePath (szDiskFile, sizeof(szDiskFile), szFileName, &tmpbDevice);
4839 4841
4840 nVolumeSize = GetDeviceSize (szDiskFile); 4842 nVolumeSize = GetDeviceSize (szDiskFile);
4841 if (nVolumeSize == -1) 4843 if (nVolumeSize == -1)
@@ -5298,7 +5300,7 @@ BOOL CALLBACK PageDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
5298 if (!BrowseFiles (hwndDlg, "OPEN_TITLE", tmpszRescueDiskISO, FALSE, TRUE, NULL)) 5300 if (!BrowseFiles (hwndDlg, "OPEN_TITLE", tmpszRescueDiskISO, FALSE, TRUE, NULL))
5299 return 1; 5301 return 1;
5300 5302
5301 strcpy (szRescueDiskISO, tmpszRescueDiskISO); 5303 StringCbCopyA (szRescueDiskISO, sizeof(szRescueDiskISO), tmpszRescueDiskISO);
5302 5304
5303 SetDlgItemText (hwndDlg, IDC_RESCUE_DISK_ISO_PATH, szRescueDiskISO); 5305 SetDlgItemText (hwndDlg, IDC_RESCUE_DISK_ISO_PATH, szRescueDiskISO);
5304 EnableWindow (GetDlgItem (MainDlg, IDC_NEXT), (GetWindowTextLength (GetDlgItem (hwndDlg, IDC_RESCUE_DISK_ISO_PATH)) > 1)); 5306 EnableWindow (GetDlgItem (MainDlg, IDC_NEXT), (GetWindowTextLength (GetDlgItem (hwndDlg, IDC_RESCUE_DISK_ISO_PATH)) > 1));
@@ -5431,7 +5433,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
5431 } 5433 }
5432 5434
5433 SHGetFolderPath (NULL, CSIDL_MYDOCUMENTS, NULL, 0, szRescueDiskISO); 5435 SHGetFolderPath (NULL, CSIDL_MYDOCUMENTS, NULL, 0, szRescueDiskISO);
5434 strcat (szRescueDiskISO, "\\VeraCrypt Rescue Disk.iso"); 5436 StringCbCatA (szRescueDiskISO, sizeof(szRescueDiskISO), "\\VeraCrypt Rescue Disk.iso");
5435 5437
5436 if (IsOSAtLeast (WIN_VISTA)) 5438 if (IsOSAtLeast (WIN_VISTA))
5437 { 5439 {
@@ -5485,8 +5487,8 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
5485 for (i = 0; i < sizeof (tmp); i++) 5487 for (i = 0; i < sizeof (tmp); i++)
5486 { 5488 {
5487 char tmp3[8]; 5489 char tmp3[8];
5488 sprintf (tmp3, "%02X", (int) (unsigned char) tmp[i]); 5490 StringCbPrintfA (tmp3, sizeof(tmp3), "%02X", (int) (unsigned char) tmp[i]);
5489 strcat (tmp2, tmp3); 5491 StringCbCatA (tmp2, sizeof(tmp2), tmp3);
5490 } 5492 }
5491 5493
5492 tmp2[32] = 0; 5494 tmp2[32] = 0;
@@ -5703,9 +5705,9 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
5703 bKeyboardLayoutChanged = TRUE; 5705 bKeyboardLayoutChanged = TRUE;
5704 5706
5705 wchar_t szTmp [4096]; 5707 wchar_t szTmp [4096];
5706 wcscpy (szTmp, GetString ("KEYB_LAYOUT_CHANGE_PREVENTED")); 5708 StringCbCopyW (szTmp, sizeof(szTmp), GetString ("KEYB_LAYOUT_CHANGE_PREVENTED"));
5707 wcscat (szTmp, L"\n\n"); 5709 StringCbCatW (szTmp, sizeof(szTmp), L"\n\n");
5708 wcscat (szTmp, GetString ("KEYB_LAYOUT_SYS_ENC_EXPLANATION")); 5710 StringCbCatW (szTmp, sizeof(szTmp), GetString ("KEYB_LAYOUT_SYS_ENC_EXPLANATION"));
5709 MessageBoxW (MainDlg, szTmp, lpszTitle, MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST); 5711 MessageBoxW (MainDlg, szTmp, lpszTitle, MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST);
5710 } 5712 }
5711 5713
@@ -5718,9 +5720,9 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
5718 bKeybLayoutAltKeyWarningShown = TRUE; 5720 bKeybLayoutAltKeyWarningShown = TRUE;
5719 5721
5720 wchar_t szTmp [4096]; 5722 wchar_t szTmp [4096];
5721 wcscpy (szTmp, GetString ("ALT_KEY_CHARS_NOT_FOR_SYS_ENCRYPTION")); 5723 StringCbCopyW (szTmp, sizeof(szTmp), GetString ("ALT_KEY_CHARS_NOT_FOR_SYS_ENCRYPTION"));
5722 wcscat (szTmp, L"\n\n"); 5724 StringCbCatW (szTmp, sizeof(szTmp), L"\n\n");
5723 wcscat (szTmp, GetString ("KEYB_LAYOUT_SYS_ENC_EXPLANATION")); 5725 StringCbCatW (szTmp, sizeof(szTmp), GetString ("KEYB_LAYOUT_SYS_ENC_EXPLANATION"));
5724 MessageBoxW (MainDlg, szTmp, lpszTitle, MB_ICONINFORMATION | MB_SETFOREGROUND | MB_TOPMOST); 5726 MessageBoxW (MainDlg, szTmp, lpszTitle, MB_ICONINFORMATION | MB_SETFOREGROUND | MB_TOPMOST);
5725 } 5727 }
5726 } 5728 }
@@ -6413,7 +6415,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
6413 6415
6414 GetWindowText (GetDlgItem (hCurPage, IDC_COMBO_BOX), szFileName, sizeof (szFileName)); 6416 GetWindowText (GetDlgItem (hCurPage, IDC_COMBO_BOX), szFileName, sizeof (szFileName));
6415 RelativePath2Absolute (szFileName); 6417 RelativePath2Absolute (szFileName);
6416 CreateFullVolumePath (szDiskFile, szFileName, &tmpbDevice); 6418 CreateFullVolumePath (szDiskFile, sizeof(szDiskFile), szFileName, &tmpbDevice);
6417 6419
6418 if (tmpbDevice != bDevice) 6420 if (tmpbDevice != bDevice)
6419 { 6421 {
@@ -6885,7 +6887,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
6885 } 6887 }
6886 else if (DeferredNonSysInPlaceEncDevices.size() == 1) 6888 else if (DeferredNonSysInPlaceEncDevices.size() == 1)
6887 { 6889 {
6888 CreateFullVolumePath (szDiskFile, DeferredNonSysInPlaceEncDevices.front().Path.c_str(), &tmpbDevice); 6890 CreateFullVolumePath (szDiskFile, sizeof(szDiskFile), DeferredNonSysInPlaceEncDevices.front().Path.c_str(), &tmpbDevice);
6889 6891
6890 nVolumeSize = GetDeviceSize (szDiskFile); 6892 nVolumeSize = GetDeviceSize (szDiskFile);
6891 if (nVolumeSize == -1) 6893 if (nVolumeSize == -1)
@@ -7042,7 +7044,7 @@ retryCDDriveCheck:
7042 { 7044 {
7043 wchar_t szTmp[8000]; 7045 wchar_t szTmp[8000];
7044 7046
7045 swprintf (szTmp, GetString ("RESCUE_DISK_CHECK_FAILED"), 7047 StringCbPrintfW (szTmp, sizeof(szTmp), GetString ("RESCUE_DISK_CHECK_FAILED"),
7046 IsWindowsIsoBurnerAvailable () ? L"" : GetString ("RESCUE_DISK_CHECK_FAILED_SENTENCE_APPENDIX")); 7048 IsWindowsIsoBurnerAvailable () ? L"" : GetString ("RESCUE_DISK_CHECK_FAILED_SENTENCE_APPENDIX"));
7047 7049
7048 ErrorDirect (szTmp); 7050 ErrorDirect (szTmp);
@@ -7592,7 +7594,7 @@ ovf_end:
7592 BOOL tmpbDevice; 7594 BOOL tmpbDevice;
7593 7595
7594 GetWindowText (GetDlgItem (hCurPage, IDC_COMBO_BOX), szFileName, sizeof (szFileName)); 7596 GetWindowText (GetDlgItem (hCurPage, IDC_COMBO_BOX), szFileName, sizeof (szFileName));
7595 CreateFullVolumePath (szDiskFile, szFileName, &tmpbDevice); 7597 CreateFullVolumePath (szDiskFile, sizeof(szDiskFile), szFileName, &tmpbDevice);
7596 7598
7597 if (tmpbDevice == bDevice) 7599 if (tmpbDevice == bDevice)
7598 { 7600 {
diff --git a/src/Mount/Favorites.cpp b/src/Mount/Favorites.cpp
index 06c1aa32..93d9c648 100644
--- a/src/Mount/Favorites.cpp
+++ b/src/Mount/Favorites.cpp
@@ -56,7 +56,7 @@ namespace VeraCrypt
56 string volumeDevPath = favorite.Path; 56 string volumeDevPath = favorite.Path;
57 57
58 wchar_t resolvedVolumeDevPath[TC_MAX_PATH]; 58 wchar_t resolvedVolumeDevPath[TC_MAX_PATH];
59 if (ResolveSymbolicLink (SingleStringToWide (volumeDevPath).c_str(), resolvedVolumeDevPath)) 59 if (ResolveSymbolicLink (SingleStringToWide (volumeDevPath).c_str(), resolvedVolumeDevPath, sizeof(resolvedVolumeDevPath)))
60 volumeDevPath = WideToSingleString (resolvedVolumeDevPath); 60 volumeDevPath = WideToSingleString (resolvedVolumeDevPath);
61 61
62 char volumeName[TC_MAX_PATH]; 62 char volumeName[TC_MAX_PATH];
@@ -414,7 +414,7 @@ namespace VeraCrypt
414 if (FavoriteVolumes.empty()) 414 if (FavoriteVolumes.empty())
415 return; 415 return;
416 416
417 AppendMenu (FavoriteVolumesMenu, MF_SEPARATOR, 0, NULL); 417 AppendMenu (FavoriteVolumesMenu, MF_SEPARATOR, 0, "");
418 418
419 int i = 0; 419 int i = 0;
420 foreach (const FavoriteVolume &favorite, FavoriteVolumes) 420 foreach (const FavoriteVolume &favorite, FavoriteVolumes)
diff --git a/src/Mount/Hotkeys.c b/src/Mount/Hotkeys.c
index 96f9abcd..c0829602 100644
--- a/src/Mount/Hotkeys.c
+++ b/src/Mount/Hotkeys.c
@@ -13,6 +13,8 @@
13#include "Mount.h" 13#include "Mount.h"
14#include "Resource.h" 14#include "Resource.h"
15 15
16#include <Strsafe.h>
17
16#define MAX_KEY_COMB_NAME_LEN 260 18#define MAX_KEY_COMB_NAME_LEN 260
17 19
18TCHOTKEY Hotkeys [NBR_HOTKEYS]; 20TCHOTKEY Hotkeys [NBR_HOTKEYS];
@@ -46,56 +48,56 @@ BOOL GetKeyName (UINT vKey, wchar_t *keyName)
46 if (vKey >= 0x30 && vKey <= 0x5a) 48 if (vKey >= 0x30 && vKey <= 0x5a)
47 { 49 {
48 // ASCII characters 50 // ASCII characters
49 wsprintfW (keyName, L"%hc", (char) vKey); 51 StringCbPrintfW (keyName, MAX_KEY_COMB_NAME_LEN, L"%hc", (char) vKey);
50 } 52 }
51 else if (vKey >= 0xE9 && vKey <= 0xF5) 53 else if (vKey >= 0xE9 && vKey <= 0xF5)
52 { 54 {
53 // OEM-specific 55 // OEM-specific
54 wsprintfW (keyName, L"OEM-%d", vKey); 56 StringCbPrintfW (keyName, MAX_KEY_COMB_NAME_LEN, L"OEM-%d", vKey);
55 } 57 }
56 else if (vKey >= VK_F1 && vKey <= VK_F24) 58 else if (vKey >= VK_F1 && vKey <= VK_F24)
57 { 59 {
58 // F1-F24 60 // F1-F24
59 wsprintfW (keyName, L"F%d", vKey - VK_F1 + 1); 61 StringCbPrintfW (keyName, MAX_KEY_COMB_NAME_LEN, L"F%d", vKey - VK_F1 + 1);
60 } 62 }
61 else if (vKey >= VK_NUMPAD0 && vKey <= VK_NUMPAD9) 63 else if (vKey >= VK_NUMPAD0 && vKey <= VK_NUMPAD9)
62 { 64 {
63 // Numpad numbers 65 // Numpad numbers
64 wsprintfW (keyName, L"%s %d", GetString ("VK_NUMPAD"), vKey - VK_NUMPAD0); 66 StringCbPrintfW (keyName, MAX_KEY_COMB_NAME_LEN, L"%s %d", GetString ("VK_NUMPAD"), vKey - VK_NUMPAD0);
65 } 67 }
66 else 68 else
67 { 69 {
68 switch (vKey) 70 switch (vKey)
69 { 71 {
70 case VK_MULTIPLY: wsprintfW (keyName, L"%s *", GetString ("VK_NUMPAD")); break; 72 case VK_MULTIPLY: StringCbPrintfW (keyName, MAX_KEY_COMB_NAME_LEN, L"%s *", GetString ("VK_NUMPAD")); break;
71 case VK_ADD: wsprintfW (keyName, L"%s +", GetString ("VK_NUMPAD")); break; 73 case VK_ADD: StringCbPrintfW (keyName, MAX_KEY_COMB_NAME_LEN, L"%s +", GetString ("VK_NUMPAD")); break;
72 case VK_SEPARATOR: wsprintfW (keyName, L"%s Separator", GetString ("VK_NUMPAD")); break; 74 case VK_SEPARATOR: StringCbPrintfW (keyName, MAX_KEY_COMB_NAME_LEN, L"%s Separator", GetString ("VK_NUMPAD")); break;
73 case VK_SUBTRACT: wsprintfW (keyName, L"%s -", GetString ("VK_NUMPAD")); break; 75 case VK_SUBTRACT: StringCbPrintfW (keyName, MAX_KEY_COMB_NAME_LEN, L"%s -", GetString ("VK_NUMPAD")); break;
74 case VK_DECIMAL: wsprintfW (keyName, L"%s .", GetString ("VK_NUMPAD")); break; 76 case VK_DECIMAL: StringCbPrintfW (keyName, MAX_KEY_COMB_NAME_LEN, L"%s .", GetString ("VK_NUMPAD")); break;
75 case VK_DIVIDE: wsprintfW (keyName, L"%s /", GetString ("VK_NUMPAD")); break; 77 case VK_DIVIDE: StringCbPrintfW (keyName, MAX_KEY_COMB_NAME_LEN, L"%s /", GetString ("VK_NUMPAD")); break;
76 case VK_OEM_1: wcscpy (keyName, L"OEM 1 (';')"); break; 78 case VK_OEM_1: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"OEM 1 (';')"); break;
77 case VK_OEM_PLUS: wcscpy (keyName, L"+"); break; 79 case VK_OEM_PLUS: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"+"); break;
78 case VK_OEM_COMMA: wcscpy (keyName, L","); break; 80 case VK_OEM_COMMA: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L","); break;
79 case VK_OEM_MINUS: wcscpy (keyName, L"-"); break; 81 case VK_OEM_MINUS: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"-"); break;
80 case VK_OEM_PERIOD: wcscpy (keyName, L"."); break; 82 case VK_OEM_PERIOD: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"."); break;
81 case VK_OEM_2: wcscpy (keyName, L"OEM 2 ('/')"); break; 83 case VK_OEM_2: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"OEM 2 ('/')"); break;
82 case VK_OEM_3: wcscpy (keyName, L"OEM 3 (`)"); break; 84 case VK_OEM_3: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"OEM 3 (`)"); break;
83 case VK_OEM_4: wcscpy (keyName, L"OEM 4 ('[')"); break; 85 case VK_OEM_4: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"OEM 4 ('[')"); break;
84 case VK_OEM_5: wcscpy (keyName, L"OEM 5 ('\\')"); break; 86 case VK_OEM_5: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"OEM 5 ('\\')"); break;
85 case VK_OEM_6: wcscpy (keyName, L"OEM 6 (']')"); break; 87 case VK_OEM_6: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"OEM 6 (']')"); break;
86 case VK_OEM_7: wcscpy (keyName, L"OEM 7 (')"); break; 88 case VK_OEM_7: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"OEM 7 (')"); break;
87 case VK_OEM_8: wcscpy (keyName, L"OEM 8"); break; 89 case VK_OEM_8: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"OEM 8"); break;
88 case VK_OEM_AX: wcscpy (keyName, L"OEM AX"); break; 90 case VK_OEM_AX: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"OEM AX"); break;
89 case VK_OEM_102: wcscpy (keyName, L"OEM 102"); break; 91 case VK_OEM_102: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"OEM 102"); break;
90 case VK_ICO_HELP: wcscpy (keyName, L"ICO_HELP"); break; 92 case VK_ICO_HELP: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"ICO_HELP"); break;
91 case VK_ICO_00: wcscpy (keyName, L"ICO_00"); break; 93 case VK_ICO_00: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"ICO_00"); break;
92 case VK_ICO_CLEAR: wcscpy (keyName, L"ICO_CLEAR"); break; 94 case VK_ICO_CLEAR: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"ICO_CLEAR"); break;
93 case VK_ATTN: wcscpy (keyName, L"Attn"); break; 95 case VK_ATTN: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"Attn"); break;
94 case VK_CRSEL: wcscpy (keyName, L"CrSel"); break; 96 case VK_CRSEL: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"CrSel"); break;
95 case VK_EXSEL: wcscpy (keyName, L"ExSel"); break; 97 case VK_EXSEL: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"ExSel"); break;
96 case VK_EREOF: wcscpy (keyName, L"Erase EOF"); break; 98 case VK_EREOF: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"Erase EOF"); break;
97 case VK_PA1: wcscpy (keyName, L"PA1"); break; 99 case VK_PA1: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"PA1"); break;
98 case VK_OEM_CLEAR: wcscpy (keyName, L"OEM Clear"); break; 100 case VK_OEM_CLEAR: StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, L"OEM Clear"); break;
99 101
100 case 0: 102 case 0:
101 case 1: 103 case 1:
@@ -107,12 +109,12 @@ BOOL GetKeyName (UINT vKey, wchar_t *keyName)
107 { 109 {
108 char key[16]; 110 char key[16];
109 wchar_t *desc; 111 wchar_t *desc;
110 sprintf (key, "VKEY_%02X", vKey); 112 StringCbPrintfA (key, sizeof(key),"VKEY_%02X", vKey);
111 desc = GetString (key); 113 desc = GetString (key);
112 if (desc == UnknownString) 114 if (desc == UnknownString)
113 result = FALSE; 115 result = FALSE;
114 else 116 else
115 wcsncpy (keyName, desc, MAX_KEY_COMB_NAME_LEN); 117 StringCbCopyW (keyName, MAX_KEY_COMB_NAME_LEN, desc);
116 } 118 }
117 } 119 }
118 } 120 }
@@ -226,36 +228,36 @@ static void DisplayHotkeyList (HWND hwndDlg)
226 SendMessageW (hList,LVM_INSERTITEMW,0,(LPARAM)&item); 228 SendMessageW (hList,LVM_INSERTITEMW,0,(LPARAM)&item);
227 229
228 item.iSubItem = 1; 230 item.iSubItem = 1;
229 wcscpy (Shortcut, L""); 231 Shortcut[0] = 0;
230 wcscpy (ShortcutMod, L""); 232 ShortcutMod[0] = 0;
231 233
232 if (GetKeyName (tmpHotkeys[i].vKeyCode, Shortcut)) 234 if (GetKeyName (tmpHotkeys[i].vKeyCode, Shortcut))
233 { 235 {
234 if (tmpHotkeys[i].vKeyModifiers & MOD_CONTROL) 236 if (tmpHotkeys[i].vKeyModifiers & MOD_CONTROL)
235 { 237 {
236 wcscat (ShortcutMod, GetString ("VK_CONTROL")); 238 StringCbCatW (ShortcutMod, sizeof(ShortcutMod),GetString ("VK_CONTROL"));
237 wcscat (ShortcutMod, L"+"); 239 StringCbCatW (ShortcutMod, sizeof(ShortcutMod),L"+");
238 } 240 }
239 241
240 if (tmpHotkeys[i].vKeyModifiers & MOD_SHIFT) 242 if (tmpHotkeys[i].vKeyModifiers & MOD_SHIFT)
241 { 243 {
242 wcscat (ShortcutMod, GetString ("VK_SHIFT")); 244 StringCbCatW (ShortcutMod, sizeof(ShortcutMod),GetString ("VK_SHIFT"));
243 wcscat (ShortcutMod, L"+"); 245 StringCbCatW (ShortcutMod, sizeof(ShortcutMod),L"+");
244 } 246 }
245 247
246 if (tmpHotkeys[i].vKeyModifiers & MOD_ALT) 248 if (tmpHotkeys[i].vKeyModifiers & MOD_ALT)
247 { 249 {
248 wcscat (ShortcutMod, GetString ("VK_ALT")); 250 StringCbCatW (ShortcutMod, sizeof(ShortcutMod),GetString ("VK_ALT"));
249 wcscat (ShortcutMod, L"+"); 251 StringCbCatW (ShortcutMod, sizeof(ShortcutMod),L"+");
250 } 252 }
251 253
252 if (tmpHotkeys[i].vKeyModifiers & MOD_WIN) 254 if (tmpHotkeys[i].vKeyModifiers & MOD_WIN)
253 { 255 {
254 wcscat (ShortcutMod, GetString ("VK_WIN")); 256 StringCbCatW (ShortcutMod, sizeof(ShortcutMod),GetString ("VK_WIN"));
255 wcscat (ShortcutMod, L"+"); 257 StringCbCatW (ShortcutMod, sizeof(ShortcutMod),L"+");
256 } 258 }
257 259
258 wsprintfW (ShortcutFinal, L"%s%s", ShortcutMod, Shortcut); 260 StringCbPrintfW (ShortcutFinal, sizeof(ShortcutFinal), L"%s%s", ShortcutMod, Shortcut);
259 item.pszText = ShortcutFinal; 261 item.pszText = ShortcutFinal;
260 } 262 }
261 else 263 else
diff --git a/src/Mount/Mount.c b/src/Mount/Mount.c
index 5f6e472e..c63d31eb 100644
--- a/src/Mount/Mount.c
+++ b/src/Mount/Mount.c
@@ -46,6 +46,8 @@
46#include "../Platform/Finally.h" 46#include "../Platform/Finally.h"
47#include "../Platform/ForEach.h" 47#include "../Platform/ForEach.h"
48 48
49#include <Strsafe.h>
50
49using namespace VeraCrypt; 51using namespace VeraCrypt;
50 52
51enum timer_ids 53enum timer_ids
@@ -534,7 +536,7 @@ void SaveSettings (HWND hwndDlg)
534 // Drive Letter 536 // Drive Letter
535 lLetter = GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST)); 537 lLetter = GetSelectedLong (GetDlgItem (hwndDlg, IDC_DRIVELIST));
536 if (LOWORD (lLetter) != 0xffff) 538 if (LOWORD (lLetter) != 0xffff)
537 sprintf (szTmp, "%c:", (char) HIWORD (lLetter)); 539 StringCbPrintfA (szTmp, sizeof(szTmp), "%c:", (char) HIWORD (lLetter));
538 ConfigWriteString ("LastSelectedDrive", szTmp); 540 ConfigWriteString ("LastSelectedDrive", szTmp);
539 541
540 ConfigWriteInt ("CloseSecurityTokenSessionsAfterMount", CloseSecurityTokenSessionsAfterMount); 542 ConfigWriteInt ("CloseSecurityTokenSessionsAfterMount", CloseSecurityTokenSessionsAfterMount);
@@ -721,19 +723,19 @@ static void PopulateSysEncContextMenu (HMENU popup, BOOL bToolsOnly)
721 AppendMenuW (popup, MF_STRING, IDM_PERMANENTLY_DECRYPT_SYS, GetString ("PERMANENTLY_DECRYPT")); 723 AppendMenuW (popup, MF_STRING, IDM_PERMANENTLY_DECRYPT_SYS, GetString ("PERMANENTLY_DECRYPT"));
722 724
723 AppendMenuW (popup, MF_STRING, IDM_ENCRYPT_SYSTEM_DEVICE, GetString ("ENCRYPT")); 725 AppendMenuW (popup, MF_STRING, IDM_ENCRYPT_SYSTEM_DEVICE, GetString ("ENCRYPT"));
724 AppendMenu (popup, MF_SEPARATOR, 0, NULL); 726 AppendMenu (popup, MF_SEPARATOR, 0, "");
725 } 727 }
726 } 728 }
727 729
728 AppendMenuW (popup, MF_STRING, IDM_CHANGE_SYS_PASSWORD, GetString ("IDM_CHANGE_SYS_PASSWORD")); 730 AppendMenuW (popup, MF_STRING, IDM_CHANGE_SYS_PASSWORD, GetString ("IDM_CHANGE_SYS_PASSWORD"));
729 AppendMenuW (popup, MF_STRING, IDM_CHANGE_SYS_HEADER_KEY_DERIV_ALGO, GetString ("IDM_CHANGE_SYS_HEADER_KEY_DERIV_ALGO")); 731 AppendMenuW (popup, MF_STRING, IDM_CHANGE_SYS_HEADER_KEY_DERIV_ALGO, GetString ("IDM_CHANGE_SYS_HEADER_KEY_DERIV_ALGO"));
730 732
731 AppendMenu (popup, MF_SEPARATOR, 0, NULL); 733 AppendMenu (popup, MF_SEPARATOR, 0, "");
732 AppendMenuW (popup, MF_STRING, IDM_SYS_ENC_SETTINGS, GetString ("IDM_SYS_ENC_SETTINGS")); 734 AppendMenuW (popup, MF_STRING, IDM_SYS_ENC_SETTINGS, GetString ("IDM_SYS_ENC_SETTINGS"));
733 735
734 if (!IsHiddenOSRunning()) 736 if (!IsHiddenOSRunning())
735 { 737 {
736 AppendMenu (popup, MF_SEPARATOR, 0, NULL); 738 AppendMenu (popup, MF_SEPARATOR, 0, "");
737 AppendMenuW (popup, MF_STRING, IDM_CREATE_RESCUE_DISK, GetString ("IDM_CREATE_RESCUE_DISK")); 739 AppendMenuW (popup, MF_STRING, IDM_CREATE_RESCUE_DISK, GetString ("IDM_CREATE_RESCUE_DISK"));
738 AppendMenuW (popup, MF_STRING, IDM_VERIFY_RESCUE_DISK, GetString ("IDM_VERIFY_RESCUE_DISK")); 740 AppendMenuW (popup, MF_STRING, IDM_VERIFY_RESCUE_DISK, GetString ("IDM_VERIFY_RESCUE_DISK"));
739 } 741 }
@@ -742,10 +744,10 @@ static void PopulateSysEncContextMenu (HMENU popup, BOOL bToolsOnly)
742 { 744 {
743 if (SysDriveOrPartitionFullyEncrypted (FALSE) && !IsHiddenOSRunning()) 745 if (SysDriveOrPartitionFullyEncrypted (FALSE) && !IsHiddenOSRunning())
744 { 746 {
745 AppendMenu (popup, MF_SEPARATOR, 0, NULL); 747 AppendMenu (popup, MF_SEPARATOR, 0, "");
746 AppendMenuW (popup, MF_STRING, IDM_PERMANENTLY_DECRYPT_SYS, GetString ("PERMANENTLY_DECRYPT")); 748 AppendMenuW (popup, MF_STRING, IDM_PERMANENTLY_DECRYPT_SYS, GetString ("PERMANENTLY_DECRYPT"));
747 } 749 }
748 AppendMenu (popup, MF_SEPARATOR, 0, NULL); 750 AppendMenu (popup, MF_SEPARATOR, 0, "");
749 AppendMenuW (popup, MF_STRING, IDM_VOLUME_PROPERTIES, GetString ("IDPM_PROPERTIES")); 751 AppendMenuW (popup, MF_STRING, IDM_VOLUME_PROPERTIES, GetString ("IDPM_PROPERTIES"));
750 } 752 }
751} 753}
@@ -764,7 +766,7 @@ BOOL CheckSysEncMountWithoutPBA (const char *devicePath, BOOL quiet)
764 if (strlen (devicePath) < 2) 766 if (strlen (devicePath) < 2)
765 { 767 {
766 GetWindowText (GetDlgItem (MainDlg, IDC_VOLUME), szDevicePath, sizeof (szDevicePath)); 768 GetWindowText (GetDlgItem (MainDlg, IDC_VOLUME), szDevicePath, sizeof (szDevicePath));
767 CreateFullVolumePath (szDiskFile, szDevicePath, &tmpbDevice); 769 CreateFullVolumePath (szDiskFile, sizeof(szDiskFile), szDevicePath, &tmpbDevice);
768 770
769 if (!tmpbDevice) 771 if (!tmpbDevice)
770 { 772 {
@@ -783,7 +785,7 @@ BOOL CheckSysEncMountWithoutPBA (const char *devicePath, BOOL quiet)
783 } 785 }
784 } 786 }
785 else 787 else
786 strncpy (szDevicePath, devicePath, sizeof (szDevicePath) - 1); 788 StringCbCopyA (szDevicePath, sizeof(szDevicePath), devicePath);
787 789
788 char *partionPortion = strrchr (szDevicePath, '\\'); 790 char *partionPortion = strrchr (szDevicePath, '\\');
789 791
@@ -815,7 +817,7 @@ BOOL CheckSysEncMountWithoutPBA (const char *devicePath, BOOL quiet)
815 return FALSE; 817 return FALSE;
816 } 818 }
817 819
818 _snprintf (parentDrivePath, 820 StringCbPrintfA (parentDrivePath,
819 sizeof (parentDrivePath), 821 sizeof (parentDrivePath),
820 "\\Device\\Harddisk%d\\Partition0", 822 "\\Device\\Harddisk%d\\Partition0",
821 driveNo); 823 driveNo);
@@ -872,7 +874,7 @@ BOOL TCBootLoaderOnInactiveSysEncDrive (void)
872 if (sscanf (szDevicePath, "\\Device\\Harddisk%d\\Partition", &driveNo) != 1) 874 if (sscanf (szDevicePath, "\\Device\\Harddisk%d\\Partition", &driveNo) != 1)
873 return FALSE; 875 return FALSE;
874 876
875 _snprintf (parentDrivePath, 877 StringCbPrintfA (parentDrivePath,
876 sizeof (parentDrivePath), 878 sizeof (parentDrivePath),
877 "\\Device\\Harddisk%d\\Partition0", 879 "\\Device\\Harddisk%d\\Partition0",
878 driveNo); 880 driveNo);
@@ -949,15 +951,16 @@ static void LaunchVolCreationWizard (HWND hwndDlg, const char *arg)
949 PROCESS_INFORMATION pi; 951 PROCESS_INFORMATION pi;
950 ZeroMemory (&si, sizeof (si)); 952 ZeroMemory (&si, sizeof (si));
951 953
952 strcpy (++tmp, "VeraCrypt Format.exe\""); 954 *tmp = 0;
955 StringCbCopyA (t, sizeof(t), "\\VeraCrypt Format.exe\"");
953 956
954 if (!FileExists(t)) 957 if (!FileExists(t))
955 Error ("VOL_CREATION_WIZARD_NOT_FOUND"); // Display a user-friendly error message and advise what to do 958 Error ("VOL_CREATION_WIZARD_NOT_FOUND"); // Display a user-friendly error message and advise what to do
956 959
957 if (strlen (arg) > 0) 960 if (strlen (arg) > 0)
958 { 961 {
959 strcat (t, " "); 962 StringCbCatA (t, sizeof(t), " ");
960 strcat (t, arg); 963 StringCbCatA (t, sizeof(t), arg);
961 } 964 }
962 965
963 if (!CreateProcess (NULL, (LPSTR) t, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi)) 966 if (!CreateProcess (NULL, (LPSTR) t, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi))
@@ -1068,7 +1071,8 @@ void LoadDriveLetters (HWND hTree, int drive)
1068 listItem.iItem = item++; 1071 listItem.iItem = item++;
1069 1072
1070 listItem.pszText = szTmp; 1073 listItem.pszText = szTmp;
1071 strcpy (szTmp, " "); 1074 szTmp[0] = ' ';
1075 szTmp[1] = 0;
1072 1076
1073 listItem.lParam = MAKELONG (TC_MLIST_ITEM_SYS_DRIVE, ENC_SYSDRIVE_PSEUDO_DRIVE_LETTER); 1077 listItem.lParam = MAKELONG (TC_MLIST_ITEM_SYS_DRIVE, ENC_SYSDRIVE_PSEUDO_DRIVE_LETTER);
1074 1078
@@ -1082,7 +1086,7 @@ void LoadDriveLetters (HWND hTree, int drive)
1082 // Fully encrypted 1086 // Fully encrypted
1083 if (SysDriveOrPartitionFullyEncrypted (TRUE)) 1087 if (SysDriveOrPartitionFullyEncrypted (TRUE))
1084 { 1088 {
1085 wcscpy (szTmpW, GetString ("SYSTEM_DRIVE")); 1089 StringCbCopyW (szTmpW, sizeof(szTmpW), GetString ("SYSTEM_DRIVE"));
1086 } 1090 }
1087 else 1091 else
1088 { 1092 {
@@ -1094,23 +1098,23 @@ void LoadDriveLetters (HWND hTree, int drive)
1094 1098
1095 if (BootEncStatus.SetupMode != SetupDecryption) 1099 if (BootEncStatus.SetupMode != SetupDecryption)
1096 { 1100 {
1097 _snwprintf (szTmpW, 1101 StringCbPrintfW (szTmpW,
1098 sizeof szTmpW/2, 1102 sizeof szTmpW,
1099 GetString ("SYSTEM_DRIVE_ENCRYPTING"), 1103 GetString ("SYSTEM_DRIVE_ENCRYPTING"),
1100 (double) GetSysEncDeviceEncryptedPartSize (TRUE) / (double) GetSysEncDeviceSize (TRUE) * 100.0); 1104 (double) GetSysEncDeviceEncryptedPartSize (TRUE) / (double) GetSysEncDeviceSize (TRUE) * 100.0);
1101 } 1105 }
1102 else 1106 else
1103 { 1107 {
1104 _snwprintf (szTmpW, 1108 StringCbPrintfW (szTmpW,
1105 sizeof szTmpW/2, 1109 sizeof szTmpW,
1106 GetString ("SYSTEM_DRIVE_DECRYPTING"), 1110 GetString ("SYSTEM_DRIVE_DECRYPTING"),
1107 100.0 - ((double) GetSysEncDeviceEncryptedPartSize (TRUE) / (double) GetSysEncDeviceSize (TRUE) * 100.0)); 1111 100.0 - ((double) GetSysEncDeviceEncryptedPartSize (TRUE) / (double) GetSysEncDeviceSize (TRUE) * 100.0));
1108 } 1112 }
1109 } 1113 }
1110 else 1114 else
1111 { 1115 {
1112 _snwprintf (szTmpW, 1116 StringCbPrintfW (szTmpW,
1113 sizeof szTmpW/2, 1117 sizeof szTmpW,
1114 GetString ("SYSTEM_DRIVE_PARTIALLY_ENCRYPTED"), 1118 GetString ("SYSTEM_DRIVE_PARTIALLY_ENCRYPTED"),
1115 (double) GetSysEncDeviceEncryptedPartSize (TRUE) / (double) GetSysEncDeviceSize (TRUE) * 100.0); 1119 (double) GetSysEncDeviceEncryptedPartSize (TRUE) / (double) GetSysEncDeviceSize (TRUE) * 100.0);
1116 } 1120 }
@@ -1118,7 +1122,7 @@ void LoadDriveLetters (HWND hTree, int drive)
1118 1122
1119 ListSubItemSetW (hTree, listItem.iItem, 1, szTmpW); 1123 ListSubItemSetW (hTree, listItem.iItem, 1, szTmpW);
1120 1124
1121 GetSizeString (GetSysEncDeviceSize(TRUE), szTmpW); 1125 GetSizeString (GetSysEncDeviceSize(TRUE), szTmpW, sizeof(szTmpW));
1122 ListSubItemSetW (hTree, listItem.iItem, 2, szTmpW); 1126 ListSubItemSetW (hTree, listItem.iItem, 2, szTmpW);
1123 1127
1124 EAGetName (szTmp, propSysEnc.ea); 1128 EAGetName (szTmp, propSysEnc.ea);
@@ -1182,7 +1186,7 @@ void LoadDriveLetters (HWND hTree, int drive)
1182 // Fully encrypted 1186 // Fully encrypted
1183 if (SysDriveOrPartitionFullyEncrypted (TRUE)) 1187 if (SysDriveOrPartitionFullyEncrypted (TRUE))
1184 { 1188 {
1185 wcscpy (szTmpW, GetString (IsHiddenOSRunning() ? "HIDDEN_SYSTEM_PARTITION" : "SYSTEM_PARTITION")); 1189 StringCbCopyW (szTmpW, sizeof(szTmpW), GetString (IsHiddenOSRunning() ? "HIDDEN_SYSTEM_PARTITION" : "SYSTEM_PARTITION"));
1186 } 1190 }
1187 else 1191 else
1188 { 1192 {
@@ -1194,23 +1198,23 @@ void LoadDriveLetters (HWND hTree, int drive)
1194 1198
1195 if (BootEncStatus.SetupMode != SetupDecryption) 1199 if (BootEncStatus.SetupMode != SetupDecryption)
1196 { 1200 {
1197 _snwprintf (szTmpW, 1201 StringCbPrintfW (szTmpW,
1198 sizeof szTmpW/2, 1202 sizeof szTmpW,
1199 GetString ("SYSTEM_PARTITION_ENCRYPTING"), 1203 GetString ("SYSTEM_PARTITION_ENCRYPTING"),
1200 (double) GetSysEncDeviceEncryptedPartSize (TRUE) / (double) GetSysEncDeviceSize (TRUE) * 100.0); 1204 (double) GetSysEncDeviceEncryptedPartSize (TRUE) / (double) GetSysEncDeviceSize (TRUE) * 100.0);
1201 } 1205 }
1202 else 1206 else
1203 { 1207 {
1204 _snwprintf (szTmpW, 1208 StringCbPrintfW (szTmpW,
1205 sizeof szTmpW/2, 1209 sizeof szTmpW,
1206 GetString ("SYSTEM_PARTITION_DECRYPTING"), 1210 GetString ("SYSTEM_PARTITION_DECRYPTING"),
1207 100.0 - ((double) GetSysEncDeviceEncryptedPartSize (TRUE) / (double) GetSysEncDeviceSize (TRUE) * 100.0)); 1211 100.0 - ((double) GetSysEncDeviceEncryptedPartSize (TRUE) / (double) GetSysEncDeviceSize (TRUE) * 100.0));
1208 } 1212 }
1209 } 1213 }
1210 else 1214 else
1211 { 1215 {
1212 _snwprintf (szTmpW, 1216 StringCbPrintfW (szTmpW,
1213 sizeof szTmpW/2, 1217 sizeof szTmpW,
1214 GetString ("SYSTEM_PARTITION_PARTIALLY_ENCRYPTED"), 1218 GetString ("SYSTEM_PARTITION_PARTIALLY_ENCRYPTED"),
1215 (double) GetSysEncDeviceEncryptedPartSize (TRUE) / (double) GetSysEncDeviceSize (TRUE) * 100.0); 1219 (double) GetSysEncDeviceEncryptedPartSize (TRUE) / (double) GetSysEncDeviceSize (TRUE) * 100.0);
1216 } 1220 }
@@ -1220,7 +1224,7 @@ void LoadDriveLetters (HWND hTree, int drive)
1220 } 1224 }
1221 else 1225 else
1222 { 1226 {
1223 ToSBCS (driver.wszVolume[i]); 1227 ToSBCS (driver.wszVolume[i], sizeof(driver.wszVolume[i]));
1224 char *path = (char *) driver.wszVolume[i]; 1228 char *path = (char *) driver.wszVolume[i];
1225 1229
1226 if (memcmp (path, "\\??\\", 4) == 0) 1230 if (memcmp (path, "\\??\\", 4) == 0)
@@ -1235,7 +1239,7 @@ void LoadDriveLetters (HWND hTree, int drive)
1235 ListSubItemSet (hTree, listItem.iItem, 1, (char *) FitPathInGfxWidth (hTree, hUserFont, ListView_GetColumnWidth (hTree, 1) - GetTextGfxWidth (hTree, L"___", hUserFont), path).c_str()); 1239 ListSubItemSet (hTree, listItem.iItem, 1, (char *) FitPathInGfxWidth (hTree, hUserFont, ListView_GetColumnWidth (hTree, 1) - GetTextGfxWidth (hTree, L"___", hUserFont), path).c_str());
1236 } 1240 }
1237 1241
1238 GetSizeString (bSysEncPartition ? GetSysEncDeviceSize(TRUE) : driver.diskLength[i], szTmpW); 1242 GetSizeString (bSysEncPartition ? GetSysEncDeviceSize(TRUE) : driver.diskLength[i], szTmpW, sizeof(szTmpW));
1239 ListSubItemSetW (hTree, listItem.iItem, 2, szTmpW); 1243 ListSubItemSetW (hTree, listItem.iItem, 2, szTmpW);
1240 1244
1241 EAGetName (szTmp, bSysEncPartition ? propSysEnc.ea : driver.ea[i]); 1245 EAGetName (szTmp, bSysEncPartition ? propSysEnc.ea : driver.ea[i]);
@@ -1276,7 +1280,7 @@ void LoadDriveLetters (HWND hTree, int drive)
1276 wchar_t szTmp[4096]; 1280 wchar_t szTmp[4096];
1277 1281
1278 VolumeNotificationsList.bHidVolDamagePrevReported[i] = TRUE; 1282 VolumeNotificationsList.bHidVolDamagePrevReported[i] = TRUE;
1279 swprintf (szTmp, GetString ("DAMAGE_TO_HIDDEN_VOLUME_PREVENTED"), i+'A'); 1283 StringCbPrintfW (szTmp, sizeof(szTmp), GetString ("DAMAGE_TO_HIDDEN_VOLUME_PREVENTED"), i+'A');
1280 SetForegroundWindow (GetParent(hTree)); 1284 SetForegroundWindow (GetParent(hTree));
1281 MessageBoxW (GetParent(hTree), szTmp, lpszTitle, MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST); 1285 MessageBoxW (GetParent(hTree), szTmp, lpszTitle, MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST);
1282 } 1286 }
@@ -1554,9 +1558,9 @@ BOOL CALLBACK PasswordChangeDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPAR
1554 bKeyboardLayoutChanged = TRUE; 1558 bKeyboardLayoutChanged = TRUE;
1555 1559
1556 wchar_t szTmp [4096]; 1560 wchar_t szTmp [4096];
1557 wcscpy (szTmp, GetString ("KEYB_LAYOUT_CHANGE_PREVENTED")); 1561 StringCbCopyW (szTmp, sizeof(szTmp), GetString ("KEYB_LAYOUT_CHANGE_PREVENTED"));
1558 wcscat (szTmp, L"\n\n"); 1562 StringCbCatW (szTmp, sizeof(szTmp), L"\n\n");
1559 wcscat (szTmp, GetString ("KEYB_LAYOUT_SYS_ENC_EXPLANATION")); 1563 StringCbCatW (szTmp, sizeof(szTmp), GetString ("KEYB_LAYOUT_SYS_ENC_EXPLANATION"));
1560 MessageBoxW (MainDlg, szTmp, lpszTitle, MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST); 1564 MessageBoxW (MainDlg, szTmp, lpszTitle, MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST);
1561 } 1565 }
1562 1566
@@ -1570,9 +1574,9 @@ BOOL CALLBACK PasswordChangeDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPAR
1570 bKeybLayoutAltKeyWarningShown = TRUE; 1574 bKeybLayoutAltKeyWarningShown = TRUE;
1571 1575
1572 wchar_t szTmp [4096]; 1576 wchar_t szTmp [4096];
1573 wcscpy (szTmp, GetString ("ALT_KEY_CHARS_NOT_FOR_SYS_ENCRYPTION")); 1577 StringCbCopyW (szTmp, sizeof(szTmp), GetString ("ALT_KEY_CHARS_NOT_FOR_SYS_ENCRYPTION"));
1574 wcscat (szTmp, L"\n\n"); 1578 StringCbCatW (szTmp, sizeof(szTmp), L"\n\n");
1575 wcscat (szTmp, GetString ("KEYB_LAYOUT_SYS_ENC_EXPLANATION")); 1579 StringCbCatW (szTmp, sizeof(szTmp), GetString ("KEYB_LAYOUT_SYS_ENC_EXPLANATION"));
1576 MessageBoxW (MainDlg, szTmp, lpszTitle, MB_ICONINFORMATION | MB_SETFOREGROUND | MB_TOPMOST); 1580 MessageBoxW (MainDlg, szTmp, lpszTitle, MB_ICONINFORMATION | MB_SETFOREGROUND | MB_TOPMOST);
1577 } 1581 }
1578 } 1582 }
@@ -1899,12 +1903,12 @@ BOOL CALLBACK PasswordDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
1899 wstring label = GetFavoriteVolumeLabel (PasswordDlgVolume); 1903 wstring label = GetFavoriteVolumeLabel (PasswordDlgVolume);
1900 if (!label.empty()) 1904 if (!label.empty())
1901 { 1905 {
1902 wsprintfW (s, GetString ("ENTER_PASSWORD_FOR_LABEL"), label.c_str()); 1906 StringCbPrintfW (s, sizeof(s), GetString ("ENTER_PASSWORD_FOR_LABEL"), label.c_str());
1903 } 1907 }
1904 else 1908 else
1905 { 1909 {
1906 wsprintfW (s, GetString ("ENTER_PASSWORD_FOR"), "___"); 1910 StringCbPrintfW (s, sizeof(s), GetString ("ENTER_PASSWORD_FOR"), "___");
1907 wsprintfW (s, GetString ("ENTER_PASSWORD_FOR"), FitPathInGfxWidth (hwndDlg, WindowTitleBarFont, rect.right - rect.left - GetTextGfxWidth (hwndDlg, s, WindowTitleBarFont), PasswordDlgVolume).c_str()); 1911 StringCbPrintfW (s, sizeof(s), GetString ("ENTER_PASSWORD_FOR"), FitPathInGfxWidth (hwndDlg, WindowTitleBarFont, rect.right - rect.left - GetTextGfxWidth (hwndDlg, s, WindowTitleBarFont), PasswordDlgVolume).c_str());
1908 } 1912 }
1909 1913
1910 SetWindowTextW (hwndDlg, s); 1914 SetWindowTextW (hwndDlg, s);
@@ -1957,7 +1961,7 @@ BOOL CALLBACK PasswordDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
1957 SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), tmp); 1961 SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), tmp);
1958 SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), ""); 1962 SetWindowText (GetDlgItem (hwndDlg, IDC_PASSWORD), "");
1959 1963
1960 sprintf (OrigKeyboardLayout, "%08X", (DWORD) GetKeyboardLayout (NULL) & 0xFFFF); 1964 StringCbPrintfA (OrigKeyboardLayout, sizeof(OrigKeyboardLayout),"%08X", (DWORD) GetKeyboardLayout (NULL) & 0xFFFF);
1961 1965
1962 DWORD keybLayout = (DWORD) LoadKeyboardLayout ("00000409", KLF_ACTIVATE); 1966 DWORD keybLayout = (DWORD) LoadKeyboardLayout ("00000409", KLF_ACTIVATE);
1963 1967
@@ -2015,9 +2019,9 @@ BOOL CALLBACK PasswordDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
2015 } 2019 }
2016 2020
2017 wchar_t szTmp [4096]; 2021 wchar_t szTmp [4096];
2018 wcscpy (szTmp, GetString ("KEYB_LAYOUT_CHANGE_PREVENTED")); 2022 StringCbCopyW (szTmp, sizeof(szTmp), GetString ("KEYB_LAYOUT_CHANGE_PREVENTED"));
2019 wcscat (szTmp, L"\n\n"); 2023 StringCbCatW (szTmp, sizeof(szTmp), L"\n\n");
2020 wcscat (szTmp, GetString ("KEYB_LAYOUT_SYS_ENC_EXPLANATION")); 2024 StringCbCatW (szTmp, sizeof(szTmp), GetString ("KEYB_LAYOUT_SYS_ENC_EXPLANATION"));
2021 MessageBoxW (MainDlg, szTmp, lpszTitle, MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST); 2025 MessageBoxW (MainDlg, szTmp, lpszTitle, MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST);
2022 } 2026 }
2023 } 2027 }
@@ -2152,9 +2156,12 @@ BOOL CALLBACK PasswordDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
2152 while (count-- > 0) 2156 while (count-- > 0)
2153 { 2157 {
2154 KeyFile *kf = (KeyFile *) malloc (sizeof (KeyFile)); 2158 KeyFile *kf = (KeyFile *) malloc (sizeof (KeyFile));
2155 DragQueryFile (hdrop, i++, kf->FileName, sizeof (kf->FileName)); 2159 if (kf)
2156 FirstKeyFile = KeyFileAdd (FirstKeyFile, kf); 2160 {
2157 KeyFilesEnable = TRUE; 2161 DragQueryFile (hdrop, i++, kf->FileName, sizeof (kf->FileName));
2162 FirstKeyFile = KeyFileAdd (FirstKeyFile, kf);
2163 KeyFilesEnable = TRUE;
2164 }
2158 } 2165 }
2159 2166
2160 SetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE, KeyFilesEnable); 2167 SetCheckBox (hwndDlg, IDC_KEYFILES_ENABLE, KeyFilesEnable);
@@ -2351,23 +2358,27 @@ BOOL CALLBACK PreferencesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM
2351 if (lw == IDC_MORE_SETTINGS) 2358 if (lw == IDC_MORE_SETTINGS)
2352 { 2359 {
2353 HMENU popup = CreatePopupMenu (); 2360 HMENU popup = CreatePopupMenu ();
2361 if (popup)
2362 {
2363 AppendMenuW (popup, MF_STRING, IDM_LANGUAGE, GetString ("IDM_LANGUAGE"));
2364 AppendMenuW (popup, MF_STRING, IDM_HOTKEY_SETTINGS, GetString ("IDM_HOTKEY_SETTINGS"));
2365 AppendMenuW (popup, MF_STRING, IDM_PERFORMANCE_SETTINGS, GetString ("IDM_PERFORMANCE_SETTINGS"));
2366 AppendMenuW (popup, MF_STRING, IDM_SYSENC_SETTINGS, GetString ("IDM_SYSENC_SETTINGS"));
2367 AppendMenuW (popup, MF_STRING, IDM_SYS_FAVORITES_SETTINGS, GetString ("IDM_SYS_FAVORITES_SETTINGS"));
2368 AppendMenuW (popup, MF_STRING, IDM_DEFAULT_KEYFILES, GetString ("IDM_DEFAULT_KEYFILES"));
2369 AppendMenuW (popup, MF_STRING, IDM_TOKEN_PREFERENCES, GetString ("IDM_TOKEN_PREFERENCES"));
2354 2370
2355 AppendMenuW (popup, MF_STRING, IDM_LANGUAGE, GetString ("IDM_LANGUAGE")); 2371 RECT rect;
2356 AppendMenuW (popup, MF_STRING, IDM_HOTKEY_SETTINGS, GetString ("IDM_HOTKEY_SETTINGS")); 2372 GetWindowRect (GetDlgItem (hwndDlg, IDC_MORE_SETTINGS), &rect);
2357 AppendMenuW (popup, MF_STRING, IDM_PERFORMANCE_SETTINGS, GetString ("IDM_PERFORMANCE_SETTINGS"));
2358 AppendMenuW (popup, MF_STRING, IDM_SYSENC_SETTINGS, GetString ("IDM_SYSENC_SETTINGS"));
2359 AppendMenuW (popup, MF_STRING, IDM_SYS_FAVORITES_SETTINGS, GetString ("IDM_SYS_FAVORITES_SETTINGS"));
2360 AppendMenuW (popup, MF_STRING, IDM_DEFAULT_KEYFILES, GetString ("IDM_DEFAULT_KEYFILES"));
2361 AppendMenuW (popup, MF_STRING, IDM_TOKEN_PREFERENCES, GetString ("IDM_TOKEN_PREFERENCES"));
2362
2363 RECT rect;
2364 GetWindowRect (GetDlgItem (hwndDlg, IDC_MORE_SETTINGS), &rect);
2365 2373
2366 int menuItem = TrackPopupMenu (popup, TPM_RETURNCMD | TPM_LEFTBUTTON, rect.left + 2, rect.top + 2, 0, hwndDlg, NULL); 2374 int menuItem = TrackPopupMenu (popup, TPM_RETURNCMD | TPM_LEFTBUTTON, rect.left + 2, rect.top + 2, 0, hwndDlg, NULL);
2367 DestroyMenu (popup); 2375 DestroyMenu (popup);
2368 2376
2369 SendMessage (MainDlg, WM_COMMAND, menuItem, NULL); 2377 SendMessage (MainDlg, WM_COMMAND, menuItem, NULL);
2370 return 1; 2378 return 1;
2379 }
2380 else
2381 return 0;
2371 } 2382 }
2372 2383
2373 if (HIWORD (wParam) == BN_CLICKED) 2384 if (HIWORD (wParam) == BN_CLICKED)
@@ -2739,7 +2750,7 @@ BOOL CALLBACK VolumePropertiesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
2739 2750
2740 // Size 2751 // Size
2741 ListItemAddW (list, i, GetString ("SIZE")); 2752 ListItemAddW (list, i, GetString ("SIZE"));
2742 swprintf (sw, L"%I64u %s", prop.diskLength, GetString ("BYTES")); 2753 StringCbPrintfW (sw, sizeof(sw), L"%I64u %s", prop.diskLength, GetString ("BYTES"));
2743 ListSubItemSetW (list, i++, 1, sw); 2754 ListSubItemSetW (list, i++, 1, sw);
2744 2755
2745 // Type 2756 // Type
@@ -2802,7 +2813,7 @@ BOOL CALLBACK VolumePropertiesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
2802 2813
2803 // Primary key 2814 // Primary key
2804 ListItemAddW (list, i, GetString ("KEY_SIZE")); 2815 ListItemAddW (list, i, GetString ("KEY_SIZE"));
2805 wsprintfW (sw, L"%d %s", size * 8, GetString ("BITS")); 2816 StringCbPrintfW (sw, sizeof(sw), L"%d %s", size * 8, GetString ("BITS"));
2806 ListSubItemSetW (list, i++, 1, sw); 2817 ListSubItemSetW (list, i++, 1, sw);
2807 2818
2808 if (strcmp (EAGetModeName (prop.ea, prop.mode, TRUE), "XTS") == 0) 2819 if (strcmp (EAGetModeName (prop.ea, prop.mode, TRUE), "XTS") == 0)
@@ -2817,7 +2828,7 @@ BOOL CALLBACK VolumePropertiesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
2817 // Tweak key (LRW) 2828 // Tweak key (LRW)
2818 2829
2819 ListItemAddW (list, i, GetString ("SECONDARY_KEY_SIZE_LRW")); 2830 ListItemAddW (list, i, GetString ("SECONDARY_KEY_SIZE_LRW"));
2820 swprintf (sw, L"%d %s", CipherGetBlockSize (EAGetFirstCipher(prop.ea))*8, GetString ("BITS")); 2831 StringCbPrintfW (sw, sizeof(sw), L"%d %s", CipherGetBlockSize (EAGetFirstCipher(prop.ea))*8, GetString ("BITS"));
2821 ListSubItemSetW (list, i++, 1, sw); 2832 ListSubItemSetW (list, i++, 1, sw);
2822 } 2833 }
2823 } 2834 }
@@ -2830,20 +2841,20 @@ BOOL CALLBACK VolumePropertiesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
2830 wchar_t tmpstr[64]; 2841 wchar_t tmpstr[64];
2831 int i = EAGetLastCipher(prop.ea); 2842 int i = EAGetLastCipher(prop.ea);
2832 2843
2833 swprintf (sw, L"%d", CipherGetBlockSize(i)*8); 2844 StringCbPrintfW (sw, sizeof(sw), L"%d", CipherGetBlockSize(i)*8);
2834 2845
2835 while (i = EAGetPreviousCipher(prop.ea, i)) 2846 while (i = EAGetPreviousCipher(prop.ea, i))
2836 { 2847 {
2837 swprintf (tmpstr, L"/%d", CipherGetBlockSize(i)*8); 2848 StringCbPrintfW (tmpstr, sizeof(tmpstr), L"/%d", CipherGetBlockSize(i)*8);
2838 wcscat (sw, tmpstr); 2849 StringCbCatW (sw, sizeof(sw), tmpstr);
2839 } 2850 }
2840 wcscat (sw, L" "); 2851 StringCbCatW (sw, sizeof(sw), L" ");
2841 } 2852 }
2842 else 2853 else
2843 { 2854 {
2844 swprintf (sw, L"%d ", CipherGetBlockSize (EAGetFirstCipher(prop.ea))*8); 2855 StringCbPrintfW (sw, sizeof(sw), L"%d ", CipherGetBlockSize (EAGetFirstCipher(prop.ea))*8);
2845 } 2856 }
2846 wcscat (sw, GetString ("BITS")); 2857 StringCbCatW (sw, sizeof(sw), GetString ("BITS"));
2847 ListSubItemSetW (list, i++, 1, sw); 2858 ListSubItemSetW (list, i++, 1, sw);
2848 2859
2849 // Mode 2860 // Mode
@@ -2906,7 +2917,7 @@ BOOL CALLBACK VolumePropertiesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
2906 { 2917 {
2907 // Volume format version 2918 // Volume format version
2908 ListItemAddW (list, i, GetString ("VOLUME_FORMAT_VERSION")); 2919 ListItemAddW (list, i, GetString ("VOLUME_FORMAT_VERSION"));
2909 sprintf (szTmp, "%d", prop.volFormatVersion); 2920 StringCbPrintfA (szTmp, sizeof(szTmp), "%d", prop.volFormatVersion);
2910 ListSubItemSet (list, i++, 1, szTmp); 2921 ListSubItemSet (list, i++, 1, szTmp);
2911 2922
2912 // Backup header 2923 // Backup header
@@ -2916,12 +2927,12 @@ BOOL CALLBACK VolumePropertiesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
2916 2927
2917 // Total data read 2928 // Total data read
2918 ListItemAddW (list, i, GetString ("TOTAL_DATA_READ")); 2929 ListItemAddW (list, i, GetString ("TOTAL_DATA_READ"));
2919 GetSizeString (prop.totalBytesRead, sw); 2930 GetSizeString (prop.totalBytesRead, sw, sizeof(sw));
2920 ListSubItemSetW (list, i++, 1, sw); 2931 ListSubItemSetW (list, i++, 1, sw);
2921 2932
2922 // Total data written 2933 // Total data written
2923 ListItemAddW (list, i, GetString ("TOTAL_DATA_WRITTEN")); 2934 ListItemAddW (list, i, GetString ("TOTAL_DATA_WRITTEN"));
2924 GetSizeString (prop.totalBytesWritten, sw); 2935 GetSizeString (prop.totalBytesWritten, sw, sizeof(sw));
2925 ListSubItemSetW (list, i++, 1, sw); 2936 ListSubItemSetW (list, i++, 1, sw);
2926 2937
2927 if (bSysEnc) 2938 if (bSysEnc)
@@ -2939,8 +2950,8 @@ BOOL CALLBACK VolumePropertiesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
2939 else 2950 else
2940 { 2951 {
2941 2952
2942 _snwprintf (sw, 2953 StringCbPrintfW (sw,
2943 sizeof sw/2, 2954 sizeof sw,
2944 GetString ("PROCESSED_PORTION_X_PERCENT"), 2955 GetString ("PROCESSED_PORTION_X_PERCENT"),
2945 (double) GetSysEncDeviceEncryptedPartSize (FALSE) / (double) GetSysEncDeviceSize (FALSE) * 100.0); 2956 (double) GetSysEncDeviceEncryptedPartSize (FALSE) / (double) GetSysEncDeviceSize (FALSE) * 100.0);
2946 2957
@@ -3078,6 +3089,7 @@ BOOL CALLBACK TravelerDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
3078 char sysDir[MAX_PATH]; 3089 char sysDir[MAX_PATH];
3079 char volName[MAX_PATH]; 3090 char volName[MAX_PATH];
3080 int drive; 3091 int drive;
3092 char* ptr;
3081 3093
3082 GetDlgItemText (hwndDlg, IDC_DIRECTORY, dstDir, sizeof dstDir); 3094 GetDlgItemText (hwndDlg, IDC_DIRECTORY, dstDir, sizeof dstDir);
3083 volName[0] = 0; 3095 volName[0] = 0;
@@ -3111,21 +3123,22 @@ BOOL CALLBACK TravelerDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
3111 if (volName[1] != 0) 3123 if (volName[1] != 0)
3112 { 3124 {
3113 volName[0] = '"'; 3125 volName[0] = '"';
3114 strcat (volName, "\""); 3126 StringCbCatA (volName, sizeof(volName), "\"");
3115 } 3127 }
3116 3128
3117 GetModuleFileName (NULL, appDir, sizeof (appDir)); 3129 GetModuleFileName (NULL, appDir, sizeof (appDir));
3118 strrchr (appDir, '\\')[0] = 0; 3130 if (ptr = strrchr (appDir, '\\'))
3131 ptr[0] = 0;
3119 3132
3120 WaitCursor (); 3133 WaitCursor ();
3121 GetSystemDirectory (sysDir, sizeof (sysDir)); 3134 GetSystemDirectory (sysDir, sizeof (sysDir));
3122 3135
3123 sprintf (dstPath, "%s\\VeraCrypt", dstDir); 3136 StringCbPrintfA (dstPath, sizeof(dstPath), "%s\\VeraCrypt", dstDir);
3124 CreateDirectory (dstPath, NULL); 3137 CreateDirectory (dstPath, NULL);
3125 3138
3126 // Main app 3139 // Main app
3127 sprintf (srcPath, "%s\\VeraCrypt.exe", appDir); 3140 StringCbPrintfA (srcPath, sizeof(srcPath), "%s\\VeraCrypt.exe", appDir);
3128 sprintf (dstPath, "%s\\VeraCrypt\\VeraCrypt.exe", dstDir); 3141 StringCbPrintfA (dstPath, sizeof(dstPath), "%s\\VeraCrypt\\VeraCrypt.exe", dstDir);
3129 if (!TCCopyFile (srcPath, dstPath)) 3142 if (!TCCopyFile (srcPath, dstPath))
3130 { 3143 {
3131 handleWin32Error (hwndDlg); 3144 handleWin32Error (hwndDlg);
@@ -3135,8 +3148,8 @@ BOOL CALLBACK TravelerDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
3135 // Wizard 3148 // Wizard
3136 if (copyWizard) 3149 if (copyWizard)
3137 { 3150 {
3138 sprintf (srcPath, "%s\\VeraCrypt Format.exe", appDir); 3151 StringCbPrintfA (srcPath, sizeof(srcPath), "%s\\VeraCrypt Format.exe", appDir);
3139 sprintf (dstPath, "%s\\VeraCrypt\\VeraCrypt Format.exe", dstDir); 3152 StringCbPrintfA (dstPath, sizeof(dstPath), "%s\\VeraCrypt\\VeraCrypt Format.exe", dstDir);
3140 if (!TCCopyFile (srcPath, dstPath)) 3153 if (!TCCopyFile (srcPath, dstPath))
3141 { 3154 {
3142 handleWin32Error (hwndDlg); 3155 handleWin32Error (hwndDlg);
@@ -3145,8 +3158,8 @@ BOOL CALLBACK TravelerDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
3145 } 3158 }
3146 3159
3147 // Driver 3160 // Driver
3148 sprintf (srcPath, "%s\\veracrypt.sys", appDir); 3161 StringCbPrintfA (srcPath, sizeof(srcPath), "%s\\veracrypt.sys", appDir);
3149 sprintf (dstPath, "%s\\VeraCrypt\\veracrypt.sys", dstDir); 3162 StringCbPrintfA (dstPath, sizeof(dstPath), "%s\\VeraCrypt\\veracrypt.sys", dstDir);
3150 if (!TCCopyFile (srcPath, dstPath)) 3163 if (!TCCopyFile (srcPath, dstPath))
3151 { 3164 {
3152 handleWin32Error (hwndDlg); 3165 handleWin32Error (hwndDlg);
@@ -3154,8 +3167,8 @@ BOOL CALLBACK TravelerDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
3154 } 3167 }
3155 3168
3156 // Driver x64 3169 // Driver x64
3157 sprintf (srcPath, "%s\\veracrypt-x64.sys", appDir); 3170 StringCbPrintfA (srcPath, sizeof(srcPath), "%s\\veracrypt-x64.sys", appDir);
3158 sprintf (dstPath, "%s\\VeraCrypt\\veracrypt-x64.sys", dstDir); 3171 StringCbPrintfA (dstPath, sizeof(dstPath), "%s\\VeraCrypt\\veracrypt-x64.sys", dstDir);
3159 if (!TCCopyFile (srcPath, dstPath)) 3172 if (!TCCopyFile (srcPath, dstPath))
3160 { 3173 {
3161 handleWin32Error (hwndDlg); 3174 handleWin32Error (hwndDlg);
@@ -3165,13 +3178,13 @@ BOOL CALLBACK TravelerDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
3165 if (GetPreferredLangId () && strcmp (GetPreferredLangId (), "en") != 0) 3178 if (GetPreferredLangId () && strcmp (GetPreferredLangId (), "en") != 0)
3166 { 3179 {
3167 // Language pack 3180 // Language pack
3168 sprintf (srcPath, "%s\\Language.%s.xml", appDir, GetPreferredLangId ()); 3181 StringCbPrintfA (srcPath, sizeof(srcPath), "%s\\Language.%s.xml", appDir, GetPreferredLangId ());
3169 sprintf (dstPath, "%s\\VeraCrypt\\Language.%s.xml", dstDir, GetPreferredLangId ()); 3182 StringCbPrintfA (dstPath, sizeof(dstPath), "%s\\VeraCrypt\\Language.%s.xml", dstDir, GetPreferredLangId ());
3170 TCCopyFile (srcPath, dstPath); 3183 TCCopyFile (srcPath, dstPath);
3171 } 3184 }
3172 3185
3173 // AutoRun 3186 // AutoRun
3174 sprintf (dstPath, "%s\\autorun.inf", dstDir); 3187 StringCbPrintfA (dstPath, sizeof(dstPath), "%s\\autorun.inf", dstDir);
3175 DeleteFile (dstPath); 3188 DeleteFile (dstPath);
3176 if (bAutoRun) 3189 if (bAutoRun)
3177 { 3190 {
@@ -3187,7 +3200,7 @@ BOOL CALLBACK TravelerDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa
3187 goto stop; 3200 goto stop;
3188 } 3201 }
3189 3202
3190 sprintf (autoMount, "VeraCrypt\\VeraCrypt.exe /q background%s%s%s%s /m rm /v %s", 3203 StringCbPrintfA (autoMount, sizeof(autoMount), "VeraCrypt\\VeraCrypt.exe /q background%s%s%s%s /m rm /v %s",
3191 drive > 0 ? driveLetter : "", 3204 drive > 0 ? driveLetter : "",
3192 bExplore ? " /e" : "", 3205 bExplore ? " /e" : "",
3193 bCacheInDriver ? " /c y" : "", 3206 bCacheInDriver ? " /c y" : "",
@@ -3452,7 +3465,7 @@ static BOOL Mount (HWND hwndDlg, int nDosDriveNo, char *szFileName)
3452 } 3465 }
3453 else if (!Silent) 3466 else if (!Silent)
3454 { 3467 {
3455 strcpy (PasswordDlgVolume, szFileName); 3468 StringCbCopyA (PasswordDlgVolume, sizeof(PasswordDlgVolume), szFileName);
3456 3469
3457 if (!AskVolumePassword (hwndDlg, &VolumePassword, NULL, TRUE)) 3470 if (!AskVolumePassword (hwndDlg, &VolumePassword, NULL, TRUE))
3458 goto ret; 3471 goto ret;
@@ -3615,7 +3628,7 @@ retry:
3615 wchar_t msg[4096]; 3628 wchar_t msg[4096];
3616 3629
3617 VolumeNotificationsList.bHidVolDamagePrevReported [unmount.nDosDriveNo] = TRUE; 3630 VolumeNotificationsList.bHidVolDamagePrevReported [unmount.nDosDriveNo] = TRUE;
3618 swprintf (msg, GetString ("DAMAGE_TO_HIDDEN_VOLUME_PREVENTED"), unmount.nDosDriveNo + 'A'); 3631 StringCbPrintfW (msg, sizeof(msg), GetString ("DAMAGE_TO_HIDDEN_VOLUME_PREVENTED"), unmount.nDosDriveNo + 'A');
3619 SetForegroundWindow (hwndDlg); 3632 SetForegroundWindow (hwndDlg);
3620 MessageBoxW (hwndDlg, msg, lpszTitle, MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST); 3633 MessageBoxW (hwndDlg, msg, lpszTitle, MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST);
3621 3634
@@ -3836,9 +3849,9 @@ static BOOL MountAllDevices (HWND hwndDlg, BOOL bPasswordPrompt)
3836 { 3849 {
3837 WCHAR szTmp[4096]; 3850 WCHAR szTmp[4096];
3838 3851
3839 swprintf (szTmp, GetString (KeyFilesEnable || FirstCmdKeyFile ? "PASSWORD_OR_KEYFILE_WRONG_AUTOMOUNT" : "PASSWORD_WRONG_AUTOMOUNT")); 3852 StringCbPrintfW (szTmp, sizeof(szTmp), GetString (KeyFilesEnable || FirstCmdKeyFile ? "PASSWORD_OR_KEYFILE_WRONG_AUTOMOUNT" : "PASSWORD_WRONG_AUTOMOUNT"));
3840 if (CheckCapsLock (hwndDlg, TRUE)) 3853 if (CheckCapsLock (hwndDlg, TRUE))
3841 wcscat (szTmp, GetString ("PASSWORD_WRONG_CAPSLOCK_ON")); 3854 StringCbCatW (szTmp, sizeof(szTmp), GetString ("PASSWORD_WRONG_CAPSLOCK_ON"));
3842 3855
3843 MessageBoxW (hwndDlg, szTmp, lpszTitle, MB_ICONWARNING); 3856 MessageBoxW (hwndDlg, szTmp, lpszTitle, MB_ICONWARNING);
3844 } 3857 }
@@ -3986,7 +3999,7 @@ static void ChangeSysEncPassword (HWND hwndDlg, BOOL bOnlyChangeKDF)
3986 3999
3987 if (CreateSysEncMutex ()) // If no instance of the wizard is currently taking care of system encryption 4000 if (CreateSysEncMutex ()) // If no instance of the wizard is currently taking care of system encryption
3988 { 4001 {
3989 sprintf (OrigKeyboardLayout, "%08X", (DWORD) GetKeyboardLayout (NULL) & 0xFFFF); 4002 StringCbPrintfA (OrigKeyboardLayout, sizeof(OrigKeyboardLayout), "%08X", (DWORD) GetKeyboardLayout (NULL) & 0xFFFF);
3990 4003
3991 bSysEncPwdChangeDlgMode = TRUE; 4004 bSysEncPwdChangeDlgMode = TRUE;
3992 4005
@@ -4251,7 +4264,7 @@ void CreateRescueDisk (void)
4251 WaitCursor(); 4264 WaitCursor();
4252 BootEncObj->CreateRescueIsoImage (false, szRescueDiskISO); 4265 BootEncObj->CreateRescueIsoImage (false, szRescueDiskISO);
4253 4266
4254 _snwprintf (szTmp, sizeof szTmp / 2, 4267 StringCbPrintfW (szTmp, sizeof szTmp,
4255 GetString (IsWindowsIsoBurnerAvailable() ? "RESCUE_DISK_NON_WIZARD_CREATION_WIN_ISOBURN" : "RESCUE_DISK_NON_WIZARD_CREATION_BURN"), 4268 GetString (IsWindowsIsoBurnerAvailable() ? "RESCUE_DISK_NON_WIZARD_CREATION_WIN_ISOBURN" : "RESCUE_DISK_NON_WIZARD_CREATION_BURN"),
4256 szRescueDiskISO); 4269 szRescueDiskISO);
4257 4270
@@ -4785,7 +4798,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
4785 { 4798 {
4786 VolumePassword.Length = 0; 4799 VolumePassword.Length = 0;
4787 4800
4788 strcpy (PasswordDlgVolume, szFileName); 4801 StringCbCopyA (PasswordDlgVolume, sizeof(PasswordDlgVolume),szFileName);
4789 if (!AskVolumePassword (hwndDlg, &VolumePassword, NULL, TRUE)) 4802 if (!AskVolumePassword (hwndDlg, &VolumePassword, NULL, TRUE))
4790 break; 4803 break;
4791 4804
@@ -5323,7 +5336,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
5323 if (MainWindowHidden) 5336 if (MainWindowHidden)
5324 { 5337 {
5325 AppendMenuW (popup, MF_STRING, IDM_SHOW_HIDE, GetString ("SHOW_TC")); 5338 AppendMenuW (popup, MF_STRING, IDM_SHOW_HIDE, GetString ("SHOW_TC"));
5326 AppendMenu (popup, MF_SEPARATOR, 0, NULL); 5339 AppendMenu (popup, MF_SEPARATOR, 0, "");
5327 } 5340 }
5328 else if (bEnableBkgTask 5341 else if (bEnableBkgTask
5329 && (!(LastKnownMountList.ulMountedDrives == 0 5342 && (!(LastKnownMountList.ulMountedDrives == 0
@@ -5332,12 +5345,12 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
5332 && GetDriverRefCount () < 2))) 5345 && GetDriverRefCount () < 2)))
5333 { 5346 {
5334 AppendMenuW (popup, MF_STRING, IDM_SHOW_HIDE, GetString ("HIDE_TC")); 5347 AppendMenuW (popup, MF_STRING, IDM_SHOW_HIDE, GetString ("HIDE_TC"));
5335 AppendMenu (popup, MF_SEPARATOR, 0, NULL); 5348 AppendMenu (popup, MF_SEPARATOR, 0, "");
5336 } 5349 }
5337 AppendMenuW (popup, MF_STRING, IDM_MOUNTALL, GetString ("IDC_MOUNTALL")); 5350 AppendMenuW (popup, MF_STRING, IDM_MOUNTALL, GetString ("IDC_MOUNTALL"));
5338 AppendMenuW (popup, MF_STRING, IDM_MOUNT_FAVORITE_VOLUMES, GetString ("IDM_MOUNT_FAVORITE_VOLUMES")); 5351 AppendMenuW (popup, MF_STRING, IDM_MOUNT_FAVORITE_VOLUMES, GetString ("IDM_MOUNT_FAVORITE_VOLUMES"));
5339 AppendMenuW (popup, MF_STRING, IDM_UNMOUNTALL, GetString ("IDC_UNMOUNTALL")); 5352 AppendMenuW (popup, MF_STRING, IDM_UNMOUNTALL, GetString ("IDC_UNMOUNTALL"));
5340 AppendMenu (popup, MF_SEPARATOR, 0, NULL); 5353 AppendMenu (popup, MF_SEPARATOR, 0, "");
5341 5354
5342 for (n = 0; n < 2; n++) 5355 for (n = 0; n < 2; n++)
5343 { 5356 {
@@ -5352,7 +5365,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
5352 5365
5353 wstring label = GetFavoriteVolumeLabel (WideToSingleString (vol)); 5366 wstring label = GetFavoriteVolumeLabel (WideToSingleString (vol));
5354 5367
5355 wsprintfW (s, L"%s %c: (%s)", 5368 StringCbPrintfW (s, sizeof(s), L"%s %c: (%s)",
5356 GetString (n==0 ? "OPEN" : "DISMOUNT"), 5369 GetString (n==0 ? "OPEN" : "DISMOUNT"),
5357 i + L'A', 5370 i + L'A',
5358 label.empty() ? vol : label.c_str()); 5371 label.empty() ? vol : label.c_str());
@@ -5360,14 +5373,14 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
5360 } 5373 }
5361 } 5374 }
5362 if (LastKnownMountList.ulMountedDrives != 0) 5375 if (LastKnownMountList.ulMountedDrives != 0)
5363 AppendMenu (popup, MF_SEPARATOR, 0, NULL); 5376 AppendMenu (popup, MF_SEPARATOR, 0, "");
5364 } 5377 }
5365 5378
5366 AppendMenuW (popup, MF_STRING, IDM_HELP, GetString ("MENU_HELP")); 5379 AppendMenuW (popup, MF_STRING, IDM_HELP, GetString ("MENU_HELP"));
5367 AppendMenuW (popup, MF_STRING, IDM_HOMEPAGE_SYSTRAY, GetString ("HOMEPAGE")); 5380 AppendMenuW (popup, MF_STRING, IDM_HOMEPAGE_SYSTRAY, GetString ("HOMEPAGE"));
5368 AppendMenuW (popup, MF_STRING, IDM_PREFERENCES, GetString ("IDM_PREFERENCES")); 5381 AppendMenuW (popup, MF_STRING, IDM_PREFERENCES, GetString ("IDM_PREFERENCES"));
5369 AppendMenuW (popup, MF_STRING, IDM_ABOUT, GetString ("IDM_ABOUT")); 5382 AppendMenuW (popup, MF_STRING, IDM_ABOUT, GetString ("IDM_ABOUT"));
5370 AppendMenu (popup, MF_SEPARATOR, 0, NULL); 5383 AppendMenu (popup, MF_SEPARATOR, 0, "");
5371 AppendMenuW (popup, MF_STRING, IDCANCEL, GetString ("EXIT")); 5384 AppendMenuW (popup, MF_STRING, IDCANCEL, GetString ("EXIT"));
5372 5385
5373 GetCursorPos (&pos); 5386 GetCursorPos (&pos);
@@ -5393,7 +5406,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
5393 if (Dismount (hwndDlg, sel - TRAYICON_MENU_DRIVE_OFFSET - 26)) 5406 if (Dismount (hwndDlg, sel - TRAYICON_MENU_DRIVE_OFFSET - 26))
5394 { 5407 {
5395 wchar_t txt [2048]; 5408 wchar_t txt [2048];
5396 wsprintfW (txt, GetString ("VOLUME_MOUNTED_AS_DRIVE_LETTER_X_DISMOUNTED"), sel - TRAYICON_MENU_DRIVE_OFFSET - 26 + L'A'); 5409 StringCbPrintfW (txt, sizeof(txt), GetString ("VOLUME_MOUNTED_AS_DRIVE_LETTER_X_DISMOUNTED"), sel - TRAYICON_MENU_DRIVE_OFFSET - 26 + L'A');
5397 5410
5398 InfoBalloonDirect (GetString ("SUCCESSFULLY_DISMOUNTED"), txt); 5411 InfoBalloonDirect (GetString ("SUCCESSFULLY_DISMOUNTED"), txt);
5399 } 5412 }
@@ -5499,7 +5512,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
5499 if (wcsstr (vol, L"\\??\\") == vol) 5512 if (wcsstr (vol, L"\\??\\") == vol)
5500 vol += 4; 5513 vol += 4;
5501 5514
5502 _snprintf (volp, sizeof(volp), "%ls", vol); 5515 StringCbPrintfA (volp, sizeof(volp), "%ls", vol);
5503 5516
5504 if (IsVolumeDeviceHosted (volp)) 5517 if (IsVolumeDeviceHosted (volp))
5505 { 5518 {
@@ -5603,7 +5616,7 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
5603 // No mounted volume at this drive letter 5616 // No mounted volume at this drive letter
5604 5617
5605 AppendMenuW (popup, MF_STRING, IDM_MOUNT_VOLUME, GetString ("IDM_MOUNT_VOLUME")); 5618 AppendMenuW (popup, MF_STRING, IDM_MOUNT_VOLUME, GetString ("IDM_MOUNT_VOLUME"));
5606 AppendMenu (popup, MF_SEPARATOR, 0, NULL); 5619 AppendMenu (popup, MF_SEPARATOR, 0, "");
5607 AppendMenuW (popup, MF_STRING, IDPM_SELECT_FILE_AND_MOUNT, GetString ("SELECT_FILE_AND_MOUNT")); 5620 AppendMenuW (popup, MF_STRING, IDPM_SELECT_FILE_AND_MOUNT, GetString ("SELECT_FILE_AND_MOUNT"));
5608 AppendMenuW (popup, MF_STRING, IDPM_SELECT_DEVICE_AND_MOUNT, GetString ("SELECT_DEVICE_AND_MOUNT")); 5621 AppendMenuW (popup, MF_STRING, IDPM_SELECT_DEVICE_AND_MOUNT, GetString ("SELECT_DEVICE_AND_MOUNT"));
5609 break; 5622 break;
@@ -5614,13 +5627,13 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
5614 5627
5615 AppendMenuW (popup, MF_STRING, IDM_UNMOUNT_VOLUME, GetString ("DISMOUNT")); 5628 AppendMenuW (popup, MF_STRING, IDM_UNMOUNT_VOLUME, GetString ("DISMOUNT"));
5616 AppendMenuW (popup, MF_STRING, IDPM_OPEN_VOLUME, GetString ("OPEN")); 5629 AppendMenuW (popup, MF_STRING, IDPM_OPEN_VOLUME, GetString ("OPEN"));
5617 AppendMenu (popup, MF_SEPARATOR, 0, NULL); 5630 AppendMenu (popup, MF_SEPARATOR, 0, "");
5618 AppendMenuW (popup, MF_STRING, IDPM_CHECK_FILESYS, GetString ("IDPM_CHECK_FILESYS")); 5631 AppendMenuW (popup, MF_STRING, IDPM_CHECK_FILESYS, GetString ("IDPM_CHECK_FILESYS"));
5619 AppendMenuW (popup, MF_STRING, IDPM_REPAIR_FILESYS, GetString ("IDPM_REPAIR_FILESYS")); 5632 AppendMenuW (popup, MF_STRING, IDPM_REPAIR_FILESYS, GetString ("IDPM_REPAIR_FILESYS"));
5620 AppendMenu (popup, MF_SEPARATOR, 0, NULL); 5633 AppendMenu (popup, MF_SEPARATOR, 0, "");
5621 AppendMenuW (popup, MF_STRING, IDPM_ADD_TO_FAVORITES, GetString ("IDPM_ADD_TO_FAVORITES")); 5634 AppendMenuW (popup, MF_STRING, IDPM_ADD_TO_FAVORITES, GetString ("IDPM_ADD_TO_FAVORITES"));
5622 AppendMenuW (popup, MF_STRING, IDPM_ADD_TO_SYSTEM_FAVORITES, GetString ("IDPM_ADD_TO_SYSTEM_FAVORITES")); 5635 AppendMenuW (popup, MF_STRING, IDPM_ADD_TO_SYSTEM_FAVORITES, GetString ("IDPM_ADD_TO_SYSTEM_FAVORITES"));
5623 AppendMenu (popup, MF_SEPARATOR, 0, NULL); 5636 AppendMenu (popup, MF_SEPARATOR, 0, "");
5624 AppendMenuW (popup, MF_STRING, IDM_VOLUME_PROPERTIES, GetString ("IDPM_PROPERTIES")); 5637 AppendMenuW (popup, MF_STRING, IDM_VOLUME_PROPERTIES, GetString ("IDPM_PROPERTIES"));
5625 break; 5638 break;
5626 5639
@@ -5867,10 +5880,10 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
5867 { 5880 {
5868 AppendMenuW (popup, MF_STRING, IDM_CHANGE_PASSWORD, GetString ("IDM_CHANGE_PASSWORD")); 5881 AppendMenuW (popup, MF_STRING, IDM_CHANGE_PASSWORD, GetString ("IDM_CHANGE_PASSWORD"));
5869 AppendMenuW (popup, MF_STRING, IDM_CHANGE_HEADER_KEY_DERIV_ALGO, GetString ("IDM_CHANGE_HEADER_KEY_DERIV_ALGO")); 5882 AppendMenuW (popup, MF_STRING, IDM_CHANGE_HEADER_KEY_DERIV_ALGO, GetString ("IDM_CHANGE_HEADER_KEY_DERIV_ALGO"));
5870 AppendMenu (popup, MF_SEPARATOR, 0, NULL); 5883 AppendMenu (popup, MF_SEPARATOR, 0, "");
5871 AppendMenuW (popup, MF_STRING, IDM_ADD_REMOVE_VOL_KEYFILES, GetString ("IDM_ADD_REMOVE_VOL_KEYFILES")); 5884 AppendMenuW (popup, MF_STRING, IDM_ADD_REMOVE_VOL_KEYFILES, GetString ("IDM_ADD_REMOVE_VOL_KEYFILES"));
5872 AppendMenuW (popup, MF_STRING, IDM_REMOVE_ALL_KEYFILES_FROM_VOL, GetString ("IDM_REMOVE_ALL_KEYFILES_FROM_VOL")); 5885 AppendMenuW (popup, MF_STRING, IDM_REMOVE_ALL_KEYFILES_FROM_VOL, GetString ("IDM_REMOVE_ALL_KEYFILES_FROM_VOL"));
5873 AppendMenu (popup, MF_SEPARATOR, 0, NULL); 5886 AppendMenu (popup, MF_SEPARATOR, 0, "");
5874 AppendMenuW (popup, MF_STRING, IDM_BACKUP_VOL_HEADER, GetString ("IDM_BACKUP_VOL_HEADER")); 5887 AppendMenuW (popup, MF_STRING, IDM_BACKUP_VOL_HEADER, GetString ("IDM_BACKUP_VOL_HEADER"));
5875 AppendMenuW (popup, MF_STRING, IDM_RESTORE_VOL_HEADER, GetString ("IDM_RESTORE_VOL_HEADER")); 5888 AppendMenuW (popup, MF_STRING, IDM_RESTORE_VOL_HEADER, GetString ("IDM_RESTORE_VOL_HEADER"));
5876 } 5889 }
@@ -6250,9 +6263,9 @@ BOOL CALLBACK MainDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPa
6250 // volPathHigher will contain the volume path selected in the main drive list 6263 // volPathHigher will contain the volume path selected in the main drive list
6251 wstring volPathHigher (prop.wszVolume); 6264 wstring volPathHigher (prop.wszVolume);
6252 6265
6253 ToSBCS (prop.wszVolume); 6266 ToSBCS (prop.wszVolume, sizeof(prop.wszVolume));
6254 strcpy ((char *) volPathLowerW, volPathLower); 6267 StringCbCopyA ((char *) volPathLowerW, sizeof(volPathLowerW), volPathLower);
6255 ToUNICODE ((char *) volPathLowerW); 6268 ToUNICODE ((char *) volPathLowerW, sizeof(volPathLowerW));
6256 6269
6257 if (strcmp (((memcmp ((char *) prop.wszVolume, "\\??\\", 4) == 0) ? (char *) prop.wszVolume + 4 : (char *) prop.wszVolume), volPathLower) != 0) 6270 if (strcmp (((memcmp ((char *) prop.wszVolume, "\\??\\", 4) == 0) ? (char *) prop.wszVolume + 4 : (char *) prop.wszVolume), volPathLower) != 0)
6258 { 6271 {
@@ -6700,8 +6713,11 @@ void ExtractCommandLine (HWND hwndDlg, char *lpszCommandLine)
6700 KeyFile *kf; 6713 KeyFile *kf;
6701 RelativePath2Absolute (tmpPath); 6714 RelativePath2Absolute (tmpPath);
6702 kf = (KeyFile *) malloc (sizeof (KeyFile)); 6715 kf = (KeyFile *) malloc (sizeof (KeyFile));
6703 strncpy (kf->FileName, tmpPath, sizeof (kf->FileName) - 1); 6716 if (kf)
6704 FirstCmdKeyFile = KeyFileAdd (FirstCmdKeyFile, kf); 6717 {
6718 StringCbCopyA (kf->FileName, sizeof(kf->FileName), tmpPath);
6719 FirstCmdKeyFile = KeyFileAdd (FirstCmdKeyFile, kf);
6720 }
6705 } 6721 }
6706 break; 6722 break;
6707 6723
@@ -7025,7 +7041,7 @@ BOOL TaskBarIconAdd (HWND hwnd)
7025 | LR_SHARED 7041 | LR_SHARED
7026 | (nCurrentOS != WIN_2000 ? LR_DEFAULTCOLOR : LR_VGACOLOR)); // Windows 2000 cannot display more than 16 fixed colors in notification tray 7042 | (nCurrentOS != WIN_2000 ? LR_DEFAULTCOLOR : LR_VGACOLOR)); // Windows 2000 cannot display more than 16 fixed colors in notification tray
7027 7043
7028 wcscpy (tnid.szTip, L"VeraCrypt"); 7044 StringCbCopyW (tnid.szTip, sizeof(tnid.szTip), L"VeraCrypt");
7029 7045
7030 return Shell_NotifyIconW (NIM_ADD, &tnid); 7046 return Shell_NotifyIconW (NIM_ADD, &tnid);
7031} 7047}
@@ -7450,7 +7466,7 @@ void ChangeMainWindowVisibility ()
7450} 7466}
7451 7467
7452 7468
7453int BackupVolumeHeader (HWND hwndDlg, BOOL bRequireConfirmation, char *lpszVolume) 7469int BackupVolumeHeader (HWND hwndDlg, BOOL bRequireConfirmation, const char *lpszVolume)
7454{ 7470{
7455 int nStatus = ERR_OS_ERROR; 7471 int nStatus = ERR_OS_ERROR;
7456 wchar_t szTmp[4096]; 7472 wchar_t szTmp[4096];
@@ -7461,6 +7477,13 @@ int BackupVolumeHeader (HWND hwndDlg, BOOL bRequireConfirmation, char *lpszVolum
7461 byte temporaryKey[MASTER_KEYDATA_SIZE]; 7477 byte temporaryKey[MASTER_KEYDATA_SIZE];
7462 byte originalK2[MASTER_KEYDATA_SIZE]; 7478 byte originalK2[MASTER_KEYDATA_SIZE];
7463 7479
7480 if (!lpszVolume)
7481 {
7482 nStatus = ERR_OUTOFMEMORY;
7483 handleError (hwndDlg, nStatus);
7484 return nStatus;
7485 }
7486
7464 volume.VolumeIsOpen = FALSE; 7487 volume.VolumeIsOpen = FALSE;
7465 hiddenVolume.VolumeIsOpen = FALSE; 7488 hiddenVolume.VolumeIsOpen = FALSE;
7466 7489
@@ -7560,7 +7583,7 @@ noHidden:
7560 goto error; 7583 goto error;
7561 } 7584 }
7562 7585
7563 swprintf (szTmp, GetString ("CONFIRM_VOL_HEADER_BAK"), lpszVolume); 7586 StringCbPrintfW (szTmp, sizeof(szTmp), GetString ("CONFIRM_VOL_HEADER_BAK"), lpszVolume);
7564 7587
7565 if (bRequireConfirmation 7588 if (bRequireConfirmation
7566 && (MessageBoxW (hwndDlg, szTmp, lpszTitle, YES_NO|MB_ICONQUESTION|MB_DEFBUTTON1) == IDNO)) 7589 && (MessageBoxW (hwndDlg, szTmp, lpszTitle, YES_NO|MB_ICONQUESTION|MB_DEFBUTTON1) == IDNO))
@@ -7672,7 +7695,7 @@ error:
7672} 7695}
7673 7696
7674 7697
7675int RestoreVolumeHeader (HWND hwndDlg, char *lpszVolume) 7698int RestoreVolumeHeader (HWND hwndDlg, const char *lpszVolume)
7676{ 7699{
7677 int nDosLinkCreated = -1, nStatus = ERR_OS_ERROR; 7700 int nDosLinkCreated = -1, nStatus = ERR_OS_ERROR;
7678 char szDiskFile[TC_MAX_PATH], szCFDevice[TC_MAX_PATH]; 7701 char szDiskFile[TC_MAX_PATH], szCFDevice[TC_MAX_PATH];
@@ -7691,6 +7714,13 @@ int RestoreVolumeHeader (HWND hwndDlg, char *lpszVolume)
7691 LARGE_INTEGER headerOffset; 7714 LARGE_INTEGER headerOffset;
7692 CRYPTO_INFO *restoredCryptoInfo = NULL; 7715 CRYPTO_INFO *restoredCryptoInfo = NULL;
7693 7716
7717 if (!lpszVolume)
7718 {
7719 nStatus = ERR_OUTOFMEMORY;
7720 handleError (hwndDlg, nStatus);
7721 return nStatus;
7722 }
7723
7694 switch (IsSystemDevicePath (lpszVolume, hwndDlg, TRUE)) 7724 switch (IsSystemDevicePath (lpszVolume, hwndDlg, TRUE))
7695 { 7725 {
7696 case 1: 7726 case 1:
@@ -7750,7 +7780,7 @@ int RestoreVolumeHeader (HWND hwndDlg, char *lpszVolume)
7750 // Open the volume using backup header 7780 // Open the volume using backup header
7751 while (TRUE) 7781 while (TRUE)
7752 { 7782 {
7753 strncpy (PasswordDlgVolume, lpszVolume, sizeof (PasswordDlgVolume) - 1); 7783 StringCbCopyA (PasswordDlgVolume, sizeof(PasswordDlgVolume), lpszVolume);
7754 if (!AskVolumePassword (hwndDlg, &VolumePassword, NULL, FALSE)) 7784 if (!AskVolumePassword (hwndDlg, &VolumePassword, NULL, FALSE))
7755 { 7785 {
7756 nStatus = ERR_SUCCESS; 7786 nStatus = ERR_SUCCESS;
@@ -7806,7 +7836,7 @@ int RestoreVolumeHeader (HWND hwndDlg, char *lpszVolume)
7806 { 7836 {
7807 // Restore header from an external backup 7837 // Restore header from an external backup
7808 7838
7809 swprintf (szTmp, GetString ("CONFIRM_VOL_HEADER_RESTORE"), lpszVolume); 7839 StringCbPrintfW (szTmp, sizeof(szTmp), GetString ("CONFIRM_VOL_HEADER_RESTORE"), lpszVolume);
7810 7840
7811 if (MessageBoxW (hwndDlg, szTmp, lpszTitle, YES_NO|MB_ICONWARNING|MB_DEFBUTTON2) == IDNO) 7841 if (MessageBoxW (hwndDlg, szTmp, lpszTitle, YES_NO|MB_ICONWARNING|MB_DEFBUTTON2) == IDNO)
7812 { 7842 {
@@ -7837,13 +7867,13 @@ int RestoreVolumeHeader (HWND hwndDlg, char *lpszVolume)
7837 goto error; 7867 goto error;
7838 } 7868 }
7839 7869
7840 CreateFullVolumePath (szDiskFile, lpszVolume, &bDevice); 7870 CreateFullVolumePath (szDiskFile, sizeof(szDiskFile), lpszVolume, &bDevice);
7841 7871
7842 if (bDevice == FALSE) 7872 if (bDevice == FALSE)
7843 strcpy (szCFDevice, szDiskFile); 7873 StringCbCopyA (szCFDevice, sizeof(szCFDevice), szDiskFile);
7844 else 7874 else
7845 { 7875 {
7846 nDosLinkCreated = FakeDosNameForDevice (szDiskFile, szDosDevice, szCFDevice, FALSE); 7876 nDosLinkCreated = FakeDosNameForDevice (szDiskFile, szDosDevice, sizeof(szDosDevice),szCFDevice, sizeof(szCFDevice),FALSE);
7847 if (nDosLinkCreated != 0) 7877 if (nDosLinkCreated != 0)
7848 goto error; 7878 goto error;
7849 } 7879 }
@@ -8302,12 +8332,12 @@ static BOOL CALLBACK SecurityTokenPreferencesDlgProc (HWND hwndDlg, UINT msg, WP
8302 else 8332 else
8303 { 8333 {
8304 char prevSecurityTokenLibraryPath[MAX_PATH]; 8334 char prevSecurityTokenLibraryPath[MAX_PATH];
8305 strcpy (prevSecurityTokenLibraryPath, SecurityTokenLibraryPath); 8335 StringCbCopyA (prevSecurityTokenLibraryPath, sizeof(prevSecurityTokenLibraryPath), SecurityTokenLibraryPath);
8306 strcpy (SecurityTokenLibraryPath, securityTokenLibraryPath); 8336 StringCbCopyA (SecurityTokenLibraryPath, sizeof(SecurityTokenLibraryPath), securityTokenLibraryPath);
8307 8337
8308 if (!InitSecurityTokenLibrary()) 8338 if (!InitSecurityTokenLibrary())
8309 { 8339 {
8310 strcpy (SecurityTokenLibraryPath, prevSecurityTokenLibraryPath); 8340 StringCbCopyA (SecurityTokenLibraryPath, sizeof(SecurityTokenLibraryPath), prevSecurityTokenLibraryPath);
8311 return 1; 8341 return 1;
8312 } 8342 }
8313 } 8343 }
@@ -8393,7 +8423,7 @@ static BOOL CALLBACK SecurityTokenPreferencesDlgProc (HWND hwndDlg, UINT msg, WP
8393 8423
8394 Info ("SELECT_PKCS11_MODULE_HELP"); 8424 Info ("SELECT_PKCS11_MODULE_HELP");
8395 8425
8396 wsprintfW (browseFilter, L"%ls (*.dll)%c*.dll%c%c", GetString ("DLL_FILES"), 0, 0, 0); 8426 StringCbPrintfW (browseFilter, sizeof(browseFilter), L"%ls (*.dll)%c*.dll%c%c", GetString ("DLL_FILES"), 0, 0, 0);
8397 GetSystemDirectory (systemDir, sizeof (systemDir)); 8427 GetSystemDirectory (systemDir, sizeof (systemDir));
8398 8428
8399 if (BrowseFilesInDir (hwndDlg, "SELECT_PKCS11_MODULE", systemDir, securityTokenLibraryPath, TRUE, FALSE, browseFilter)) 8429 if (BrowseFilesInDir (hwndDlg, "SELECT_PKCS11_MODULE", systemDir, securityTokenLibraryPath, TRUE, FALSE, browseFilter))
diff --git a/src/Mount/Mount.h b/src/Mount/Mount.h
index 140b3e99..7509542c 100644
--- a/src/Mount/Mount.h
+++ b/src/Mount/Mount.h
@@ -94,8 +94,8 @@ BOOL WholeSysDriveEncryption (BOOL bSilent);
94BOOL CheckSysEncMountWithoutPBA (const char *devicePath, BOOL quiet); 94BOOL CheckSysEncMountWithoutPBA (const char *devicePath, BOOL quiet);
95BOOL TCBootLoaderOnInactiveSysEncDrive (void); 95BOOL TCBootLoaderOnInactiveSysEncDrive (void);
96void CreateRescueDisk (void); 96void CreateRescueDisk (void);
97int BackupVolumeHeader (HWND hwndDlg, BOOL bRequireConfirmation, char *lpszVolume); 97int BackupVolumeHeader (HWND hwndDlg, BOOL bRequireConfirmation, const char *lpszVolume);
98int RestoreVolumeHeader (HWND hwndDlg, char *lpszVolume); 98int RestoreVolumeHeader (HWND hwndDlg, const char *lpszVolume);
99void SecurityTokenPreferencesDialog (HWND hwndDlg); 99void SecurityTokenPreferencesDialog (HWND hwndDlg);
100static BOOL CALLBACK PerformanceSettingsDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); 100static BOOL CALLBACK PerformanceSettingsDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
101static BOOL CALLBACK BootLoaderPreferencesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); 101static BOOL CALLBACK BootLoaderPreferencesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);