VeraCrypt
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2014-07-14 17:34:26 +0200
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2014-11-08 23:21:24 +0100
commitc01f392a7ba1d5cdd4aa182eeb273cf41717d94f (patch)
tree1ece0f48b75d5a6b3c6a61a687898153874e41f4
parentbbc738c490bcd691151c28f971e0e153777fb255 (diff)
downloadVeraCrypt-c01f392a7ba1d5cdd4aa182eeb273cf41717d94f.tar.gz
VeraCrypt-c01f392a7ba1d5cdd4aa182eeb273cf41717d94f.zip
Static Code Analysis : Use Safe String function in Dlgcode.c. Add byte size parameter in various functions to help implement secure handling of strings.
-rw-r--r--src/Common/Dlgcode.c590
-rw-r--r--src/Common/Dlgcode.h24
2 files changed, 340 insertions, 274 deletions
diff --git a/src/Common/Dlgcode.c b/src/Common/Dlgcode.c
index de400e7a..071ed8e2 100644
--- a/src/Common/Dlgcode.c
+++ b/src/Common/Dlgcode.c
@@ -61,6 +61,8 @@
61#include "Setup/Setup.h" 61#include "Setup/Setup.h"
62#endif 62#endif
63 63
64#include <strsafe.h>
65
64using namespace VeraCrypt; 66using namespace VeraCrypt;
65 67
66LONG DriverVersion; 68LONG DriverVersion;
@@ -320,14 +322,19 @@ void LowerCaseCopy (char *lpszDest, const char *lpszSource)
320 322
321} 323}
322 324
323void UpperCaseCopy (char *lpszDest, const char *lpszSource) 325void UpperCaseCopy (char *lpszDest, size_t cbDest, const char *lpszSource)
324{ 326{
325 int i = strlen (lpszSource); 327 if (lpszDest && cbDest)
326
327 lpszDest[i] = 0;
328 while (--i >= 0)
329 { 328 {
330 lpszDest[i] = (char) toupper (lpszSource[i]); 329 int i = strlen (lpszSource);
330 if (i >= (int) cbDest)
331 i = cbDest - 1;
332
333 lpszDest[i] = 0;
334 while (--i >= 0)
335 {
336 lpszDest[i] = (char) toupper (lpszSource[i]);
337 }
331 } 338 }
332} 339}
333 340
@@ -351,9 +358,9 @@ BOOL IsVolumeDeviceHosted (const char *lpszDiskFile)
351} 358}
352 359
353 360
354void CreateFullVolumePath (char *lpszDiskFile, const char *lpszFileName, BOOL * bDevice) 361void CreateFullVolumePath (char *lpszDiskFile, size_t cbDiskFile, const char *lpszFileName, BOOL * bDevice)
355{ 362{
356 UpperCaseCopy (lpszDiskFile, lpszFileName); 363 UpperCaseCopy (lpszDiskFile, cbDiskFile, lpszFileName);
357 364
358 *bDevice = FALSE; 365 *bDevice = FALSE;
359 366
@@ -362,7 +369,7 @@ void CreateFullVolumePath (char *lpszDiskFile, const char *lpszFileName, BOOL *
362 *bDevice = TRUE; 369 *bDevice = TRUE;
363 } 370 }
364 371
365 strcpy (lpszDiskFile, lpszFileName); 372 StringCbCopyA (lpszDiskFile, cbDiskFile, lpszFileName);
366 373
367#if _DEBUG 374#if _DEBUG
368 OutputDebugString ("CreateFullVolumePath: "); 375 OutputDebugString ("CreateFullVolumePath: ");
@@ -372,10 +379,10 @@ void CreateFullVolumePath (char *lpszDiskFile, const char *lpszFileName, BOOL *
372 379
373} 380}
374 381
375int FakeDosNameForDevice (const char *lpszDiskFile, char *lpszDosDevice, char *lpszCFDevice, BOOL bNameOnly) 382int FakeDosNameForDevice (const char *lpszDiskFile , char *lpszDosDevice , size_t cbDosDevice, char *lpszCFDevice , size_t cbCFDevice, BOOL bNameOnly)
376{ 383{
377 BOOL bDosLinkCreated = TRUE; 384 BOOL bDosLinkCreated = TRUE;
378 sprintf (lpszDosDevice, "veracrypt%lu", GetCurrentProcessId ()); 385 StringCbPrintfA (lpszDosDevice, cbDosDevice,"veracrypt%lu", GetCurrentProcessId ());
379 386
380 if (bNameOnly == FALSE) 387 if (bNameOnly == FALSE)
381 bDosLinkCreated = DefineDosDevice (DDD_RAW_TARGET_PATH, lpszDosDevice, lpszDiskFile); 388 bDosLinkCreated = DefineDosDevice (DDD_RAW_TARGET_PATH, lpszDosDevice, lpszDiskFile);
@@ -383,7 +390,7 @@ int FakeDosNameForDevice (const char *lpszDiskFile, char *lpszDosDevice, char *l
383 if (bDosLinkCreated == FALSE) 390 if (bDosLinkCreated == FALSE)
384 return ERR_OS_ERROR; 391 return ERR_OS_ERROR;
385 else 392 else
386 sprintf (lpszCFDevice, "\\\\.\\%s", lpszDosDevice); 393 StringCbPrintfA (lpszCFDevice, cbCFDevice,"\\\\.\\%s", lpszDosDevice);
387 394
388 return 0; 395 return 0;
389} 396}
@@ -809,8 +816,11 @@ BOOL CALLBACK AuxiliaryDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP
809 { 816 {
810 HDC hDC = GetDC (hwndDlg); 817 HDC hDC = GetDC (hwndDlg);
811 818
812 ScreenDPI = GetDeviceCaps (hDC, LOGPIXELSY); 819 if (hDC)
813 ReleaseDC (hwndDlg, hDC); 820 {
821 ScreenDPI = GetDeviceCaps (hDC, LOGPIXELSY);
822 ReleaseDC (hwndDlg, hDC);
823 }
814 824
815 DPIScaleFactorX = 1; 825 DPIScaleFactorX = 1;
816 DPIScaleFactorY = 1; 826 DPIScaleFactorY = 1;
@@ -890,9 +900,9 @@ BOOL CALLBACK AboutDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam
890 900
891 // Version 901 // Version
892 SendMessage (GetDlgItem (hwndDlg, IDT_ABOUT_VERSION), WM_SETFONT, (WPARAM) hUserBoldFont, 0); 902 SendMessage (GetDlgItem (hwndDlg, IDT_ABOUT_VERSION), WM_SETFONT, (WPARAM) hUserBoldFont, 0);
893 sprintf (szTmp, "VeraCrypt %s", VERSION_STRING); 903 StringCbPrintfA (szTmp, sizeof(szTmp), "VeraCrypt %s", VERSION_STRING);
894#if (defined(_DEBUG) || defined(DEBUG)) 904#if (defined(_DEBUG) || defined(DEBUG))
895 strcat (szTmp, " (debug)"); 905 StringCbCatA (szTmp, sizeof(szTmp), " (debug)");
896#endif 906#endif
897 SetDlgItemText (hwndDlg, IDT_ABOUT_VERSION, szTmp); 907 SetDlgItemText (hwndDlg, IDT_ABOUT_VERSION, szTmp);
898 SetDlgItemText (hwndDlg, IDT_ABOUT_RELEASE, TC_STR_RELEASED_BY); 908 SetDlgItemText (hwndDlg, IDT_ABOUT_RELEASE, TC_STR_RELEASED_BY);
@@ -1050,23 +1060,26 @@ void LeftPadString (char *szTmp, int len, int targetLen, char filler)
1050 ToSBCS: converts a unicode string to Single Byte Character String (SBCS). 1060 ToSBCS: converts a unicode string to Single Byte Character String (SBCS).
1051 ***************************************************************************/ 1061 ***************************************************************************/
1052 1062
1053void ToSBCS (LPWSTR lpszText) 1063void ToSBCS (LPWSTR lpszText, size_t cbSize)
1054{ 1064{
1055 int j = wcslen (lpszText); 1065 if (lpszText)
1056 if (j == 0)
1057 {
1058 strcpy ((char *) lpszText, "");
1059 return;
1060 }
1061 else
1062 { 1066 {
1063 char *lpszNewText = (char *) err_malloc (j + 1); 1067 int j = wcslen (lpszText);
1064 j = WideCharToMultiByte (CP_ACP, 0L, lpszText, -1, lpszNewText, j + 1, NULL, NULL); 1068 if (j == 0)
1065 if (j > 0) 1069 {
1066 strcpy ((char *) lpszText, lpszNewText); 1070 *((char *) lpszText) = 0;
1071 return;
1072 }
1067 else 1073 else
1068 strcpy ((char *) lpszText, ""); 1074 {
1069 free (lpszNewText); 1075 char *lpszNewText = (char *) err_malloc (j + 1);
1076 j = WideCharToMultiByte (CP_ACP, 0L, lpszText, -1, lpszNewText, j + 1, NULL, NULL);
1077 if (j > 0)
1078 StringCbCopyA ((char *) lpszText, cbSize, lpszNewText);
1079 else
1080 *((char *) lpszText) = 0;
1081 free (lpszNewText);
1082 }
1070 } 1083 }
1071} 1084}
1072 1085
@@ -1074,12 +1087,12 @@ void ToSBCS (LPWSTR lpszText)
1074 ToUNICODE: converts a SBCS string to a UNICODE string. 1087 ToUNICODE: converts a SBCS string to a UNICODE string.
1075 ***************************************************************************/ 1088 ***************************************************************************/
1076 1089
1077void ToUNICODE (char *lpszText) 1090void ToUNICODE (char *lpszText, size_t cbSize)
1078{ 1091{
1079 int j = strlen (lpszText); 1092 int j = (int) strlen (lpszText);
1080 if (j == 0) 1093 if (j == 0)
1081 { 1094 {
1082 wcscpy ((LPWSTR) lpszText, (LPWSTR) WIDE ("")); 1095 StringCbCopyW ((LPWSTR) lpszText, cbSize, (LPWSTR) WIDE (""));
1083 return; 1096 return;
1084 } 1097 }
1085 else 1098 else
@@ -1087,9 +1100,9 @@ void ToUNICODE (char *lpszText)
1087 LPWSTR lpszNewText = (LPWSTR) err_malloc ((j + 1) * 2); 1100 LPWSTR lpszNewText = (LPWSTR) err_malloc ((j + 1) * 2);
1088 j = MultiByteToWideChar (CP_ACP, 0L, lpszText, -1, lpszNewText, j + 1); 1101 j = MultiByteToWideChar (CP_ACP, 0L, lpszText, -1, lpszNewText, j + 1);
1089 if (j > 0) 1102 if (j > 0)
1090 wcscpy ((LPWSTR) lpszText, lpszNewText); 1103 StringCbCopyW ((LPWSTR) lpszText, cbSize, lpszNewText);
1091 else 1104 else
1092 wcscpy ((LPWSTR) lpszText, (LPWSTR) WIDE ("")); 1105 StringCbCopyW ((LPWSTR) lpszText, cbSize, (LPWSTR) WIDE (""));
1093 free (lpszNewText); 1106 free (lpszNewText);
1094 } 1107 }
1095} 1108}
@@ -1123,13 +1136,13 @@ void InitDialog (HWND hwndDlg)
1123 1136
1124 if (font && wcscmp (font->FaceName, L"default") != 0) 1137 if (font && wcscmp (font->FaceName, L"default") != 0)
1125 { 1138 {
1126 wcsncpy ((WCHAR *)metric.lfMessageFont.lfFaceName, font->FaceName, sizeof (metric.lfMessageFont.lfFaceName)/2); 1139 StringCbCopyW ((WCHAR *)metric.lfMessageFont.lfFaceName, sizeof (metric.lfMessageFont.lfFaceName), font->FaceName);
1127 } 1140 }
1128 else if (IsOSAtLeast (WIN_VISTA)) 1141 else if (IsOSAtLeast (WIN_VISTA))
1129 { 1142 {
1130 // Vista's new default font (size and spacing) breaks compatibility with Windows 2k/XP applications. 1143 // Vista's new default font (size and spacing) breaks compatibility with Windows 2k/XP applications.
1131 // Force use of Tahoma (as Microsoft does in many dialogs) until a native Vista look is implemented. 1144 // Force use of Tahoma (as Microsoft does in many dialogs) until a native Vista look is implemented.
1132 wcsncpy ((WCHAR *)metric.lfMessageFont.lfFaceName, L"Tahoma", sizeof (metric.lfMessageFont.lfFaceName)/2); 1145 StringCbCopyW ((WCHAR *)metric.lfMessageFont.lfFaceName, sizeof (metric.lfMessageFont.lfFaceName), L"Tahoma");
1133 } 1146 }
1134 1147
1135 hUserFont = CreateFontIndirectW (&metric.lfMessageFont); 1148 hUserFont = CreateFontIndirectW (&metric.lfMessageFont);
@@ -1160,7 +1173,7 @@ void InitDialog (HWND hwndDlg)
1160 lf.lfClipPrecision = CLIP_DEFAULT_PRECIS; 1173 lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
1161 lf.lfQuality = PROOF_QUALITY; 1174 lf.lfQuality = PROOF_QUALITY;
1162 lf.lfPitchAndFamily = FF_DONTCARE; 1175 lf.lfPitchAndFamily = FF_DONTCARE;
1163 wcscpy (lf.lfFaceName, L"Courier New"); 1176 StringCbCopyW (lf.lfFaceName, sizeof(lf.lfFaceName), L"Courier New");
1164 hFixedDigitFont = CreateFontIndirectW (&lf); 1177 hFixedDigitFont = CreateFontIndirectW (&lf);
1165 if (hFixedDigitFont == NULL) 1178 if (hFixedDigitFont == NULL)
1166 { 1179 {
@@ -1174,7 +1187,7 @@ void InitDialog (HWND hwndDlg)
1174 nHeight = CompensateDPIFont (!font ? -13 : -font->Size); 1187 nHeight = CompensateDPIFont (!font ? -13 : -font->Size);
1175 lf.lfHeight = nHeight; 1188 lf.lfHeight = nHeight;
1176 lf.lfWeight = FW_BLACK; 1189 lf.lfWeight = FW_BLACK;
1177 wcsncpy (lf.lfFaceName, !font ? L"Arial" : font->FaceName, sizeof (lf.lfFaceName)/2); 1190 StringCbCopyW (lf.lfFaceName, sizeof(lf.lfFaceName), !font ? L"Arial" : font->FaceName);
1178 hBoldFont = CreateFontIndirectW (&lf); 1191 hBoldFont = CreateFontIndirectW (&lf);
1179 if (hBoldFont == NULL) 1192 if (hBoldFont == NULL)
1180 { 1193 {
@@ -1188,7 +1201,7 @@ void InitDialog (HWND hwndDlg)
1188 nHeight = CompensateDPIFont (!font ? -21 : -font->Size); 1201 nHeight = CompensateDPIFont (!font ? -21 : -font->Size);
1189 lf.lfHeight = nHeight; 1202 lf.lfHeight = nHeight;
1190 lf.lfWeight = FW_REGULAR; 1203 lf.lfWeight = FW_REGULAR;
1191 wcsncpy (lf.lfFaceName, !font ? L"Times New Roman" : font->FaceName, sizeof (lf.lfFaceName)/2); 1204 StringCbCopyW (lf.lfFaceName, sizeof(lf.lfFaceName),!font ? L"Times New Roman" : font->FaceName);
1192 hTitleFont = CreateFontIndirectW (&lf); 1205 hTitleFont = CreateFontIndirectW (&lf);
1193 if (hTitleFont == NULL) 1206 if (hTitleFont == NULL)
1194 { 1207 {
@@ -1213,7 +1226,7 @@ void InitDialog (HWND hwndDlg)
1213 lf.lfClipPrecision = CLIP_DEFAULT_PRECIS; 1226 lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
1214 lf.lfQuality = PROOF_QUALITY; 1227 lf.lfQuality = PROOF_QUALITY;
1215 lf.lfPitchAndFamily = FF_DONTCARE; 1228 lf.lfPitchAndFamily = FF_DONTCARE;
1216 wcsncpy (lf.lfFaceName, !font ? L"Lucida Console" : font->FaceName, sizeof (lf.lfFaceName)/2); 1229 StringCbCopyW (lf.lfFaceName, sizeof(lf.lfFaceName),!font ? L"Lucida Console" : font->FaceName);
1217 hFixedFont = CreateFontIndirectW (&lf); 1230 hFixedFont = CreateFontIndirectW (&lf);
1218 if (hFixedFont == NULL) 1231 if (hFixedFont == NULL)
1219 { 1232 {
@@ -1224,7 +1237,7 @@ void InitDialog (HWND hwndDlg)
1224 if (!aboutMenuAppended) 1237 if (!aboutMenuAppended)
1225 { 1238 {
1226 hMenu = GetSystemMenu (hwndDlg, FALSE); 1239 hMenu = GetSystemMenu (hwndDlg, FALSE);
1227 AppendMenu (hMenu, MF_SEPARATOR, 0, NULL); 1240 AppendMenu (hMenu, MF_SEPARATOR, 0, "");
1228 AppendMenuW (hMenu, MF_ENABLED | MF_STRING, IDC_ABOUT, GetString ("ABOUTBOX")); 1241 AppendMenuW (hMenu, MF_ENABLED | MF_STRING, IDC_ABOUT, GetString ("ABOUTBOX"));
1229 1242
1230 aboutMenuAppended = TRUE; 1243 aboutMenuAppended = TRUE;
@@ -1280,10 +1293,12 @@ HBITMAP RenderBitmap (char *resource, HWND hwndDest, int x, int y, int nWidth, i
1280 LRESULT lResult = 0; 1293 LRESULT lResult = 0;
1281 1294
1282 HDC hdcSrc = CreateMemBitmap (hInst, hwndDest, resource); 1295 HDC hdcSrc = CreateMemBitmap (hInst, hwndDest, resource);
1296 if (!hdcSrc)
1297 return NULL;
1283 1298
1284 HGDIOBJ picture = GetCurrentObject (hdcSrc, OBJ_BITMAP); 1299 HGDIOBJ picture = GetCurrentObject (hdcSrc, OBJ_BITMAP);
1285 1300
1286 HBITMAP hbmpRescaled; 1301 HBITMAP hbmpRescaled = NULL;
1287 BITMAP bitmap; 1302 BITMAP bitmap;
1288 1303
1289 HDC hdcRescaled; 1304 HDC hdcRescaled;
@@ -1320,46 +1335,51 @@ HBITMAP RenderBitmap (char *resource, HWND hwndDest, int x, int y, int nWidth, i
1320 1335
1321 GetObject (picture, sizeof (BITMAP), &bitmap); 1336 GetObject (picture, sizeof (BITMAP), &bitmap);
1322 1337
1323 hdcRescaled = CreateCompatibleDC (hdcSrc); 1338 hdcRescaled = CreateCompatibleDC (hdcSrc);
1324
1325 hbmpRescaled = CreateCompatibleBitmap (hdcSrc, nWidth, nHeight);
1326
1327 SelectObject (hdcRescaled, hbmpRescaled);
1328 1339
1329 /* Anti-aliasing mode (HALFTONE is the only anti-aliasing algorithm natively supported by Windows 2000. 1340 if (hdcRescaled)
1330 TODO: GDI+ offers higher quality -- InterpolationModeHighQualityBicubic) */ 1341 {
1331 SetStretchBltMode (hdcRescaled, HALFTONE); 1342 hbmpRescaled = CreateCompatibleBitmap (hdcSrc, nWidth, nHeight);
1332 1343
1333 StretchBlt (hdcRescaled, 1344 SelectObject (hdcRescaled, hbmpRescaled);
1334 0,
1335 0,
1336 nWidth,
1337 nHeight,
1338 hdcSrc,
1339 0,
1340 0,
1341 bitmap.bmWidth,
1342 bitmap.bmHeight,
1343 SRCCOPY);
1344 1345
1345 DeleteDC (hdcSrc); 1346 /* Anti-aliasing mode (HALFTONE is the only anti-aliasing algorithm natively supported by Windows 2000.
1347 TODO: GDI+ offers higher quality -- InterpolationModeHighQualityBicubic) */
1348 SetStretchBltMode (hdcRescaled, HALFTONE);
1346 1349
1347 if (bDirectRender) 1350 StretchBlt (hdcRescaled,
1348 { 1351 0,
1349 HDC hdcDest = GetDC (hwndDest); 1352 0,
1353 nWidth,
1354 nHeight,
1355 hdcSrc,
1356 0,
1357 0,
1358 bitmap.bmWidth,
1359 bitmap.bmHeight,
1360 SRCCOPY);
1350 1361
1351 BitBlt (hdcDest, x, y, nWidth, nHeight, hdcRescaled, 0, 0, SRCCOPY); 1362 DeleteDC (hdcSrc);
1352 ReleaseDC (hwndDest, hdcDest);
1353 }
1354 else
1355 {
1356 lResult = SendMessage (hwndDest, (UINT) STM_SETIMAGE, (WPARAM) IMAGE_BITMAP, (LPARAM) (HANDLE) hbmpRescaled);
1357 }
1358 1363
1359 if ((HGDIOBJ) lResult != NULL && (HGDIOBJ) lResult != (HGDIOBJ) hbmpRescaled) 1364 if (bDirectRender)
1360 DeleteObject ((HGDIOBJ) lResult); 1365 {
1366 HDC hdcDest = GetDC (hwndDest);
1367 if (hdcDest)
1368 {
1369 BitBlt (hdcDest, x, y, nWidth, nHeight, hdcRescaled, 0, 0, SRCCOPY);
1370 ReleaseDC (hwndDest, hdcDest);
1371 }
1372 }
1373 else
1374 {
1375 lResult = SendMessage (hwndDest, (UINT) STM_SETIMAGE, (WPARAM) IMAGE_BITMAP, (LPARAM) (HANDLE) hbmpRescaled);
1376 }
1377
1378 if ((HGDIOBJ) lResult != NULL && (HGDIOBJ) lResult != (HGDIOBJ) hbmpRescaled)
1379 DeleteObject ((HGDIOBJ) lResult);
1361 1380
1362 DeleteDC (hdcRescaled); 1381 DeleteDC (hdcRescaled);
1382 }
1363 1383
1364 return hbmpRescaled; 1384 return hbmpRescaled;
1365} 1385}
@@ -2339,8 +2359,8 @@ void InitApp (HINSTANCE hInstance, char *lpszCommandLine)
2339 2359
2340 GetModuleFileName (NULL, modPath, sizeof (modPath)); 2360 GetModuleFileName (NULL, modPath, sizeof (modPath));
2341 2361
2342 strcpy (newCmdLine, "/q UAC "); 2362 StringCbCopyA (newCmdLine, sizeof(newCmdLine), "/q UAC ");
2343 strcat_s (newCmdLine, sizeof (newCmdLine), lpszCommandLine); 2363 StringCbCatA (newCmdLine, sizeof (newCmdLine), lpszCommandLine);
2344 2364
2345 if ((int)ShellExecute (hWnd, "runas", modPath, newCmdLine, NULL, SW_SHOWNORMAL) <= 32) 2365 if ((int)ShellExecute (hWnd, "runas", modPath, newCmdLine, NULL, SW_SHOWNORMAL) <= 32)
2346 exit (1); 2366 exit (1);
@@ -2444,9 +2464,9 @@ void InitApp (HINSTANCE hInstance, char *lpszCommandLine)
2444 } 2464 }
2445 2465
2446 if (GetSystemDirectory(dllPath, MAX_PATH)) 2466 if (GetSystemDirectory(dllPath, MAX_PATH))
2447 strcat(dllPath, "\\Riched20.dll"); 2467 StringCbCatA(dllPath, sizeof(dllPath), "\\Riched20.dll");
2448 else 2468 else
2449 strcpy(dllPath, "c:\\Windows\\System32\\Riched20.dll"); 2469 StringCbCopyA(dllPath, sizeof(dllPath), "c:\\Windows\\System32\\Riched20.dll");
2450 // Required for RichEdit text fields to work 2470 // Required for RichEdit text fields to work
2451 if (LoadLibrary(dllPath) == NULL) 2471 if (LoadLibrary(dllPath) == NULL)
2452 { 2472 {
@@ -2480,16 +2500,19 @@ void InitHelpFileName (void)
2480 { 2500 {
2481 char szTemp[TC_MAX_PATH]; 2501 char szTemp[TC_MAX_PATH];
2482 2502
2503 ++lpszTmp;
2504 *lpszTmp = 0; // add null terminating character to prepare for append operations
2505
2483 // Primary file name 2506 // Primary file name
2484 if (strcmp (GetPreferredLangId(), "en") == 0 2507 if (strcmp (GetPreferredLangId(), "en") == 0
2485 || GetPreferredLangId() == NULL) 2508 || GetPreferredLangId() == NULL)
2486 { 2509 {
2487 strcpy (++lpszTmp, "VeraCrypt User Guide.pdf"); 2510 StringCbCatA (szHelpFile, sizeof(szHelpFile), "VeraCrypt User Guide.pdf");
2488 } 2511 }
2489 else 2512 else
2490 { 2513 {
2491 sprintf (szTemp, "VeraCrypt User Guide.%s.pdf", GetPreferredLangId()); 2514 StringCbPrintfA (szTemp, sizeof(szTemp), "VeraCrypt User Guide.%s.pdf", GetPreferredLangId());
2492 strcpy (++lpszTmp, szTemp); 2515 StringCbCatA (szHelpFile, sizeof(szHelpFile), szTemp);
2493 } 2516 }
2494 2517
2495 // Secondary file name (used when localized documentation is not found). 2518 // Secondary file name (used when localized documentation is not found).
@@ -2497,7 +2520,9 @@ void InitHelpFileName (void)
2497 lpszTmp = strrchr (szHelpFile2, '\\'); 2520 lpszTmp = strrchr (szHelpFile2, '\\');
2498 if (lpszTmp) 2521 if (lpszTmp)
2499 { 2522 {
2500 strcpy (++lpszTmp, "VeraCrypt User Guide.pdf"); 2523 ++lpszTmp;
2524 *lpszTmp = 0;
2525 StringCbCopyA (szHelpFile2, sizeof(szHelpFile2), "VeraCrypt User Guide.pdf");
2501 } 2526 }
2502 } 2527 }
2503} 2528}
@@ -2507,8 +2532,8 @@ BOOL OpenDevice (const char *lpszPath, OPEN_TEST_STRUCT *driver, BOOL detectFile
2507 DWORD dwResult; 2532 DWORD dwResult;
2508 BOOL bResult; 2533 BOOL bResult;
2509 2534
2510 strcpy ((char *) &driver->wszFileName[0], lpszPath); 2535 StringCbCopyA ((char *) &driver->wszFileName[0], sizeof(driver->wszFileName), lpszPath);
2511 ToUNICODE ((char *) &driver->wszFileName[0]); 2536 ToUNICODE ((char *) &driver->wszFileName[0], sizeof(driver->wszFileName));
2512 2537
2513 driver->bDetectTCBootLoader = FALSE; 2538 driver->bDetectTCBootLoader = FALSE;
2514 driver->DetectFilesystem = detectFilesystem; 2539 driver->DetectFilesystem = detectFilesystem;
@@ -2627,7 +2652,7 @@ Return codes:
26273 - it is the extra boot partition path 26523 - it is the extra boot partition path
26280 - it's not the system partition/drive path 26530 - it's not the system partition/drive path
2629-1 - the result can't be determined, isn't reliable, or there was an error. */ 2654-1 - the result can't be determined, isn't reliable, or there was an error. */
2630int IsSystemDevicePath (char *path, HWND hwndDlg, BOOL bReliableRequired) 2655int IsSystemDevicePath (const char *path, HWND hwndDlg, BOOL bReliableRequired)
2631{ 2656{
2632 if (!bCachedSysDevicePathsValid 2657 if (!bCachedSysDevicePathsValid
2633 && bReliableRequired) 2658 && bReliableRequired)
@@ -2639,6 +2664,9 @@ int IsSystemDevicePath (char *path, HWND hwndDlg, BOOL bReliableRequired)
2639 if (strlen (SysPartitionDevicePath) <= 1 || strlen (SysDriveDevicePath) <= 1) 2664 if (strlen (SysPartitionDevicePath) <= 1 || strlen (SysDriveDevicePath) <= 1)
2640 return -1; 2665 return -1;
2641 2666
2667 if (!path)
2668 return -1;
2669
2642 if (strncmp (path, SysPartitionDevicePath, max (strlen(path), strlen(SysPartitionDevicePath))) == 0) 2670 if (strncmp (path, SysPartitionDevicePath, max (strlen(path), strlen(SysPartitionDevicePath))) == 0)
2643 return 1; 2671 return 1;
2644 else if (strncmp (path, SysDriveDevicePath, max (strlen(path), strlen(SysDriveDevicePath))) == 0) 2672 else if (strncmp (path, SysDriveDevicePath, max (strlen(path), strlen(SysDriveDevicePath))) == 0)
@@ -2959,12 +2987,12 @@ BOOL CALLBACK RawDevicesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l
2959 { 2987 {
2960 wchar_t s[1024]; 2988 wchar_t s[1024];
2961 if (device.Removable) 2989 if (device.Removable)
2962 wsprintfW (s, L"%s %d", GetString ("REMOVABLE_DISK"), device.SystemNumber); 2990 StringCbPrintfW (s, sizeof(s), L"%s %d", GetString ("REMOVABLE_DISK"), device.SystemNumber);
2963 else 2991 else
2964 wsprintfW (s, L"%s %d", GetString ("HARDDISK"), device.SystemNumber); 2992 StringCbPrintfW (s, sizeof(s), L"%s %d", GetString ("HARDDISK"), device.SystemNumber);
2965 2993
2966 if (!device.Partitions.empty()) 2994 if (!device.Partitions.empty())
2967 wcscat (s, L":"); 2995 StringCbCatW (s, sizeof(s), L":");
2968 2996
2969 ListItemAddW (hList, item.iItem, s); 2997 ListItemAddW (hList, item.iItem, s);
2970 } 2998 }
@@ -2980,7 +3008,7 @@ BOOL CALLBACK RawDevicesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l
2980 if (device.Size != 0) 3008 if (device.Size != 0)
2981 { 3009 {
2982 wchar_t size[100] = { 0 }; 3010 wchar_t size[100] = { 0 };
2983 GetSizeString (device.Size, size); 3011 GetSizeString (device.Size, size, sizeof(size));
2984 ListSubItemSetW (hList, item.iItem, 2, size); 3012 ListSubItemSetW (hList, item.iItem, 2, size);
2985 } 3013 }
2986 3014
@@ -3258,11 +3286,13 @@ static int DriverLoad ()
3258 tmp = strrchr (driverPath, '\\'); 3286 tmp = strrchr (driverPath, '\\');
3259 if (!tmp) 3287 if (!tmp)
3260 { 3288 {
3261 strcpy (driverPath, "."); 3289 driverPath[0] = '.';
3262 tmp = driverPath + 1; 3290 driverPath[1] = 0;
3263 } 3291 }
3292 else
3293 *tmp = 0;
3264 3294
3265 strcpy (tmp, !Is64BitOs () ? "\\veracrypt.sys" : "\\veracrypt-x64.sys"); 3295 StringCbCatA (driverPath, sizeof(driverPath), !Is64BitOs () ? "\\veracrypt.sys" : "\\veracrypt-x64.sys");
3266 3296
3267 file = FindFirstFile (driverPath, &find); 3297 file = FindFirstFile (driverPath, &find);
3268 3298
@@ -3590,7 +3620,7 @@ BOOL BrowseFilesInDir (HWND hwndDlg, char *stringId, char *initialDir, char *lps
3590 ofn.lStructSize = sizeof (ofn); 3620 ofn.lStructSize = sizeof (ofn);
3591 ofn.hwndOwner = hwndDlg; 3621 ofn.hwndOwner = hwndDlg;
3592 3622
3593 wsprintfW (filter, L"%ls (*.*)%c*.*%c%ls (*.hc)%c*.hc%c%c", 3623 StringCbPrintfW (filter, sizeof(filter), L"%ls (*.*)%c*.*%c%ls (*.hc)%c*.hc%c%c",
3594 GetString ("ALL_FILES"), 0, 0, GetString ("TC_VOLUMES"), 0, 0, 0); 3624 GetString ("ALL_FILES"), 0, 0, GetString ("TC_VOLUMES"), 0, 0, 0);
3595 ofn.lpstrFilter = browseFilter ? browseFilter : filter; 3625 ofn.lpstrFilter = browseFilter ? browseFilter : filter;
3596 ofn.nFilterIndex = 1; 3626 ofn.nFilterIndex = 1;
@@ -3641,7 +3671,7 @@ ret:
3641static char SelectMultipleFilesPath[131072]; 3671static char SelectMultipleFilesPath[131072];
3642static int SelectMultipleFilesOffset; 3672static int SelectMultipleFilesOffset;
3643 3673
3644BOOL SelectMultipleFiles (HWND hwndDlg, char *stringId, char *lpszFileName, BOOL keepHistory) 3674BOOL SelectMultipleFiles (HWND hwndDlg, const char *stringId, char *lpszFileName, size_t cbFileName,BOOL keepHistory)
3645{ 3675{
3646 OPENFILENAMEW ofn; 3676 OPENFILENAMEW ofn;
3647 wchar_t file[0xffff * 2] = { 0 }; // The size must not exceed 0xffff*2 due to a bug in Windows 2000 and XP SP1 3677 wchar_t file[0xffff * 2] = { 0 }; // The size must not exceed 0xffff*2 due to a bug in Windows 2000 and XP SP1
@@ -3655,7 +3685,7 @@ BOOL SelectMultipleFiles (HWND hwndDlg, char *stringId, char *lpszFileName, BOOL
3655 *lpszFileName = 0; 3685 *lpszFileName = 0;
3656 ofn.lStructSize = sizeof (ofn); 3686 ofn.lStructSize = sizeof (ofn);
3657 ofn.hwndOwner = hwndDlg; 3687 ofn.hwndOwner = hwndDlg;
3658 wsprintfW (filter, L"%ls (*.*)%c*.*%c%ls (*.hc)%c*.hc%c%c", 3688 StringCbPrintfW (filter, sizeof(filter), L"%ls (*.*)%c*.*%c%ls (*.hc)%c*.hc%c%c",
3659 GetString ("ALL_FILES"), 0, 0, GetString ("TC_VOLUMES"), 0, 0, 0); 3689 GetString ("ALL_FILES"), 0, 0, GetString ("TC_VOLUMES"), 0, 0, 0);
3660 ofn.lpstrFilter = filter; 3690 ofn.lpstrFilter = filter;
3661 ofn.nFilterIndex = 1; 3691 ofn.nFilterIndex = 1;
@@ -3698,7 +3728,7 @@ BOOL SelectMultipleFiles (HWND hwndDlg, char *stringId, char *lpszFileName, BOOL
3698 } 3728 }
3699 3729
3700 SelectMultipleFilesOffset = ofn.nFileOffset; 3730 SelectMultipleFilesOffset = ofn.nFileOffset;
3701 SelectMultipleFilesNext (lpszFileName); 3731 SelectMultipleFilesNext (lpszFileName, cbFileName);
3702 } 3732 }
3703 3733
3704 if (!keepHistory) 3734 if (!keepHistory)
@@ -3715,18 +3745,18 @@ ret:
3715} 3745}
3716 3746
3717 3747
3718BOOL SelectMultipleFilesNext (char *lpszFileName) 3748BOOL SelectMultipleFilesNext (char *lpszFileName, size_t cbFileName)
3719{ 3749{
3720 if (SelectMultipleFilesOffset == 0) 3750 if (SelectMultipleFilesOffset == 0)
3721 return FALSE; 3751 return FALSE;
3722 3752
3723 strncpy (lpszFileName, SelectMultipleFilesPath, TC_MAX_PATH); 3753 StringCbCopyA (lpszFileName, cbFileName,SelectMultipleFilesPath);
3724 lpszFileName[TC_MAX_PATH - 1] = 0; 3754 lpszFileName[TC_MAX_PATH - 1] = 0;
3725 3755
3726 if (lpszFileName[strlen (lpszFileName) - 1] != '\\') 3756 if (lpszFileName[strlen (lpszFileName) - 1] != '\\')
3727 strcat (lpszFileName, "\\"); 3757 StringCbCatA (lpszFileName, cbFileName,"\\");
3728 3758
3729 strcat (lpszFileName, SelectMultipleFilesPath + SelectMultipleFilesOffset); 3759 StringCbCatA (lpszFileName, cbFileName,SelectMultipleFilesPath + SelectMultipleFilesOffset);
3730 3760
3731 SelectMultipleFilesOffset += strlen (SelectMultipleFilesPath + SelectMultipleFilesOffset) + 1; 3761 SelectMultipleFilesOffset += strlen (SelectMultipleFilesPath + SelectMultipleFilesOffset) + 1;
3732 if (SelectMultipleFilesPath[SelectMultipleFilesOffset] == 0) 3762 if (SelectMultipleFilesPath[SelectMultipleFilesOffset] == 0)
@@ -3810,19 +3840,19 @@ std::wstring GetWrongPasswordErrorMessage (HWND hwndDlg)
3810{ 3840{
3811 WCHAR szTmp[8192]; 3841 WCHAR szTmp[8192];
3812 3842
3813 swprintf (szTmp, GetString (KeyFilesEnable ? "PASSWORD_OR_KEYFILE_WRONG" : "PASSWORD_WRONG")); 3843 StringCbPrintfW (szTmp, sizeof(szTmp), GetString (KeyFilesEnable ? "PASSWORD_OR_KEYFILE_WRONG" : "PASSWORD_WRONG"));
3814 if (CheckCapsLock (hwndDlg, TRUE)) 3844 if (CheckCapsLock (hwndDlg, TRUE))
3815 wcscat (szTmp, GetString ("PASSWORD_WRONG_CAPSLOCK_ON")); 3845 StringCbCatW (szTmp, sizeof(szTmp), GetString ("PASSWORD_WRONG_CAPSLOCK_ON"));
3816 3846
3817#ifdef TCMOUNT 3847#ifdef TCMOUNT
3818 if (TCBootLoaderOnInactiveSysEncDrive ()) 3848 if (TCBootLoaderOnInactiveSysEncDrive ())
3819 { 3849 {
3820 swprintf (szTmp, GetString (KeyFilesEnable ? "PASSWORD_OR_KEYFILE_OR_MODE_WRONG" : "PASSWORD_OR_MODE_WRONG")); 3850 StringCbPrintfW (szTmp, sizeof(szTmp), GetString (KeyFilesEnable ? "PASSWORD_OR_KEYFILE_OR_MODE_WRONG" : "PASSWORD_OR_MODE_WRONG"));
3821 3851
3822 if (CheckCapsLock (hwndDlg, TRUE)) 3852 if (CheckCapsLock (hwndDlg, TRUE))
3823 wcscat (szTmp, GetString ("PASSWORD_WRONG_CAPSLOCK_ON")); 3853 StringCbCatW (szTmp, sizeof(szTmp), GetString ("PASSWORD_WRONG_CAPSLOCK_ON"));
3824 3854
3825 wcscat (szTmp, GetString ("SYSENC_MOUNT_WITHOUT_PBA_NOTE")); 3855 StringCbCatW (szTmp, sizeof(szTmp), GetString ("SYSENC_MOUNT_WITHOUT_PBA_NOTE"));
3826 } 3856 }
3827#endif 3857#endif
3828 3858
@@ -3940,7 +3970,7 @@ void handleError (HWND hwndDlg, int code)
3940 break; 3970 break;
3941 3971
3942 default: 3972 default:
3943 wsprintfW (szTmp, GetString ("ERR_UNKNOWN"), code); 3973 StringCbPrintfW (szTmp, sizeof(szTmp), GetString ("ERR_UNKNOWN"), code);
3944 MessageBoxW (hwndDlg, szTmp, lpszTitle, ICON_HAND); 3974 MessageBoxW (hwndDlg, szTmp, lpszTitle, ICON_HAND);
3945 } 3975 }
3946} 3976}
@@ -3951,7 +3981,7 @@ BOOL CheckFileStreamWriteErrors (FILE *file, const char *fileName)
3951 if (ferror (file)) 3981 if (ferror (file))
3952 { 3982 {
3953 wchar_t s[TC_MAX_PATH]; 3983 wchar_t s[TC_MAX_PATH];
3954 swprintf_s (s, ARRAYSIZE (s), GetString ("CANNOT_WRITE_FILE_X"), fileName); 3984 StringCbPrintfW (s, sizeof (s), GetString ("CANNOT_WRITE_FILE_X"), fileName);
3955 ErrorDirect (s); 3985 ErrorDirect (s);
3956 3986
3957 return FALSE; 3987 return FALSE;
@@ -4008,7 +4038,7 @@ void OpenVolumeExplorerWindow (int driveNo)
4008 char dosName[5]; 4038 char dosName[5];
4009 SHFILEINFO fInfo; 4039 SHFILEINFO fInfo;
4010 4040
4011 sprintf (dosName, "%c:\\", (char) driveNo + 'A'); 4041 StringCbPrintfA (dosName, sizeof(dosName), "%c:\\", (char) driveNo + 'A');
4012 4042
4013 // Force explorer to discover the drive 4043 // Force explorer to discover the drive
4014 SHGetFileInfo (dosName, 0, &fInfo, sizeof (fInfo), 0); 4044 SHGetFileInfo (dosName, 0, &fInfo, sizeof (fInfo), 0);
@@ -4039,7 +4069,7 @@ static BOOL CALLBACK CloseVolumeExplorerWindowsEnum (HWND hwnd, LPARAM driveNo)
4039 char driveStr[10]; 4069 char driveStr[10];
4040 char s[MAX_PATH]; 4070 char s[MAX_PATH];
4041 4071
4042 sprintf (driveStr, "%c:\\", driveNo + 'A'); 4072 StringCbPrintfA (driveStr, sizeof(driveStr), "%c:\\", driveNo + 'A');
4043 4073
4044 GetClassName (hwnd, s, sizeof s); 4074 GetClassName (hwnd, s, sizeof s);
4045 if (strcmp (s, "CabinetWClass") == 0) 4075 if (strcmp (s, "CabinetWClass") == 0)
@@ -4073,7 +4103,7 @@ BOOL CloseVolumeExplorerWindows (HWND hwnd, int driveNo)
4073string GetUserFriendlyVersionString (int version) 4103string GetUserFriendlyVersionString (int version)
4074{ 4104{
4075 char szTmp [64]; 4105 char szTmp [64];
4076 sprintf (szTmp, "%x", version); 4106 StringCbPrintfA (szTmp, sizeof(szTmp), "%x", version);
4077 4107
4078 string versionString (szTmp); 4108 string versionString (szTmp);
4079 4109
@@ -4085,7 +4115,7 @@ string GetUserFriendlyVersionString (int version)
4085 return (versionString); 4115 return (versionString);
4086} 4116}
4087 4117
4088void GetSizeString (unsigned __int64 size, wchar_t *str) 4118void GetSizeString (unsigned __int64 size, wchar_t *str, size_t cbStr)
4089{ 4119{
4090 static wchar_t *b, *kb, *mb, *gb, *tb, *pb; 4120 static wchar_t *b, *kb, *mb, *gb, *tb, *pb;
4091 static int serNo; 4121 static int serNo;
@@ -4102,29 +4132,29 @@ void GetSizeString (unsigned __int64 size, wchar_t *str)
4102 } 4132 }
4103 4133
4104 if (size > 1024I64*1024*1024*1024*1024*99) 4134 if (size > 1024I64*1024*1024*1024*1024*99)
4105 swprintf (str, L"%I64d %s", size/1024/1024/1024/1024/1024, pb); 4135 StringCbPrintfW (str, cbStr, L"%I64d %s", size/1024/1024/1024/1024/1024, pb);
4106 else if (size > 1024I64*1024*1024*1024*1024) 4136 else if (size > 1024I64*1024*1024*1024*1024)
4107 swprintf (str, L"%.1f %s",(double)(size/1024.0/1024/1024/1024/1024), pb); 4137 StringCbPrintfW (str, cbStr, L"%.1f %s",(double)(size/1024.0/1024/1024/1024/1024), pb);
4108 else if (size > 1024I64*1024*1024*1024*99) 4138 else if (size > 1024I64*1024*1024*1024*99)
4109 swprintf (str, L"%I64d %s",size/1024/1024/1024/1024, tb); 4139 StringCbPrintfW (str, cbStr, L"%I64d %s",size/1024/1024/1024/1024, tb);
4110 else if (size > 1024I64*1024*1024*1024) 4140 else if (size > 1024I64*1024*1024*1024)
4111 swprintf (str, L"%.1f %s",(double)(size/1024.0/1024/1024/1024), tb); 4141 StringCbPrintfW (str, cbStr, L"%.1f %s",(double)(size/1024.0/1024/1024/1024), tb);
4112 else if (size > 1024I64*1024*1024*99) 4142 else if (size > 1024I64*1024*1024*99)
4113 swprintf (str, L"%I64d %s",size/1024/1024/1024, gb); 4143 StringCbPrintfW (str, cbStr, L"%I64d %s",size/1024/1024/1024, gb);
4114 else if (size > 1024I64*1024*1024) 4144 else if (size > 1024I64*1024*1024)
4115 swprintf (str, L"%.1f %s",(double)(size/1024.0/1024/1024), gb); 4145 StringCbPrintfW (str, cbStr, L"%.1f %s",(double)(size/1024.0/1024/1024), gb);
4116 else if (size > 1024I64*1024*99) 4146 else if (size > 1024I64*1024*99)
4117 swprintf (str, L"%I64d %s", size/1024/1024, mb); 4147 StringCbPrintfW (str, cbStr, L"%I64d %s", size/1024/1024, mb);
4118 else if (size > 1024I64*1024) 4148 else if (size > 1024I64*1024)
4119 swprintf (str, L"%.1f %s",(double)(size/1024.0/1024), mb); 4149 StringCbPrintfW (str, cbStr, L"%.1f %s",(double)(size/1024.0/1024), mb);
4120 else if (size >= 1024I64) 4150 else if (size >= 1024I64)
4121 swprintf (str, L"%I64d %s", size/1024, kb); 4151 StringCbPrintfW (str, cbStr, L"%I64d %s", size/1024, kb);
4122 else 4152 else
4123 swprintf (str, L"%I64d %s", size, b); 4153 StringCbPrintfW (str, cbStr, L"%I64d %s", size, b);
4124} 4154}
4125 4155
4126#ifndef SETUP 4156#ifndef SETUP
4127void GetSpeedString (unsigned __int64 speed, wchar_t *str) 4157void GetSpeedString (unsigned __int64 speed, wchar_t *str, size_t cbStr)
4128{ 4158{
4129 static wchar_t *b, *kb, *mb, *gb, *tb, *pb; 4159 static wchar_t *b, *kb, *mb, *gb, *tb, *pb;
4130 static int serNo; 4160 static int serNo;
@@ -4141,25 +4171,25 @@ void GetSpeedString (unsigned __int64 speed, wchar_t *str)
4141 } 4171 }
4142 4172
4143 if (speed > 1024I64*1024*1024*1024*1024*99) 4173 if (speed > 1024I64*1024*1024*1024*1024*99)
4144 swprintf (str, L"%I64d %s", speed/1024/1024/1024/1024/1024, pb); 4174 StringCbPrintfW (str, cbStr, L"%I64d %s", speed/1024/1024/1024/1024/1024, pb);
4145 else if (speed > 1024I64*1024*1024*1024*1024) 4175 else if (speed > 1024I64*1024*1024*1024*1024)
4146 swprintf (str, L"%.1f %s",(double)(speed/1024.0/1024/1024/1024/1024), pb); 4176 StringCbPrintfW (str, cbStr, L"%.1f %s",(double)(speed/1024.0/1024/1024/1024/1024), pb);
4147 else if (speed > 1024I64*1024*1024*1024*99) 4177 else if (speed > 1024I64*1024*1024*1024*99)
4148 swprintf (str, L"%I64d %s",speed/1024/1024/1024/1024, tb); 4178 StringCbPrintfW (str, cbStr, L"%I64d %s",speed/1024/1024/1024/1024, tb);
4149 else if (speed > 1024I64*1024*1024*1024) 4179 else if (speed > 1024I64*1024*1024*1024)
4150 swprintf (str, L"%.1f %s",(double)(speed/1024.0/1024/1024/1024), tb); 4180 StringCbPrintfW (str, cbStr, L"%.1f %s",(double)(speed/1024.0/1024/1024/1024), tb);
4151 else if (speed > 1024I64*1024*1024*99) 4181 else if (speed > 1024I64*1024*1024*99)
4152 swprintf (str, L"%I64d %s",speed/1024/1024/1024, gb); 4182 StringCbPrintfW (str, cbStr, L"%I64d %s",speed/1024/1024/1024, gb);
4153 else if (speed > 1024I64*1024*1024) 4183 else if (speed > 1024I64*1024*1024)
4154 swprintf (str, L"%.1f %s",(double)(speed/1024.0/1024/1024), gb); 4184 StringCbPrintfW (str, cbStr, L"%.1f %s",(double)(speed/1024.0/1024/1024), gb);
4155 else if (speed > 1024I64*1024*99) 4185 else if (speed > 1024I64*1024*99)
4156 swprintf (str, L"%I64d %s", speed/1024/1024, mb); 4186 StringCbPrintfW (str, cbStr, L"%I64d %s", speed/1024/1024, mb);
4157 else if (speed > 1024I64*1024) 4187 else if (speed > 1024I64*1024)
4158 swprintf (str, L"%.1f %s",(double)(speed/1024.0/1024), mb); 4188 StringCbPrintfW (str, cbStr, L"%.1f %s",(double)(speed/1024.0/1024), mb);
4159 else if (speed > 1024I64) 4189 else if (speed > 1024I64)
4160 swprintf (str, L"%I64d %s", speed/1024, kb); 4190 StringCbPrintfW (str, cbStr, L"%I64d %s", speed/1024, kb);
4161 else 4191 else
4162 swprintf (str, L"%I64d %s", speed, b); 4192 StringCbPrintfW (str, cbStr, L"%I64d %s", speed, b);
4163} 4193}
4164 4194
4165static void DisplayBenchmarkResults (HWND hwndDlg) 4195static void DisplayBenchmarkResults (HWND hwndDlg)
@@ -4230,7 +4260,7 @@ static void DisplayBenchmarkResults (HWND hwndDlg)
4230#if PKCS5_BENCHMARKS 4260#if PKCS5_BENCHMARKS
4231 wcscpy (item1, L"-"); 4261 wcscpy (item1, L"-");
4232#else 4262#else
4233 GetSpeedString ((unsigned __int64) (benchmarkLastBufferSize / ((float) benchmarkTable[i].encSpeed / benchmarkPerformanceFrequency.QuadPart)), item1); 4263 GetSpeedString ((unsigned __int64) (benchmarkLastBufferSize / ((float) benchmarkTable[i].encSpeed / benchmarkPerformanceFrequency.QuadPart)), item1, sizeof(item1));
4234#endif 4264#endif
4235 LvItem.iSubItem = 1; 4265 LvItem.iSubItem = 1;
4236 LvItem.pszText = item1; 4266 LvItem.pszText = item1;
@@ -4240,7 +4270,7 @@ static void DisplayBenchmarkResults (HWND hwndDlg)
4240#if PKCS5_BENCHMARKS 4270#if PKCS5_BENCHMARKS
4241 wcscpy (item1, L"-"); 4271 wcscpy (item1, L"-");
4242#else 4272#else
4243 GetSpeedString ((unsigned __int64) (benchmarkLastBufferSize / ((float) benchmarkTable[i].decSpeed / benchmarkPerformanceFrequency.QuadPart)), item1); 4273 GetSpeedString ((unsigned __int64) (benchmarkLastBufferSize / ((float) benchmarkTable[i].decSpeed / benchmarkPerformanceFrequency.QuadPart)), item1, sizeof(item1));
4244#endif 4274#endif
4245 LvItem.iSubItem = 2; 4275 LvItem.iSubItem = 2;
4246 LvItem.pszText = item1; 4276 LvItem.pszText = item1;
@@ -4250,7 +4280,7 @@ static void DisplayBenchmarkResults (HWND hwndDlg)
4250#if PKCS5_BENCHMARKS 4280#if PKCS5_BENCHMARKS
4251 swprintf (item1, L"%d t", benchmarkTable[i].encSpeed); 4281 swprintf (item1, L"%d t", benchmarkTable[i].encSpeed);
4252#else 4282#else
4253 GetSpeedString (benchmarkTable[i].meanBytesPerSec, item1); 4283 GetSpeedString (benchmarkTable[i].meanBytesPerSec, item1, sizeof(item1));
4254#endif 4284#endif
4255 LvItem.iSubItem = 3; 4285 LvItem.iSubItem = 3;
4256 LvItem.pszText = item1; 4286 LvItem.pszText = item1;
@@ -4367,7 +4397,7 @@ static BOOL PerformBenchmark(HWND hwndDlg)
4367 benchmarkTable[benchmarkTotalItems].decSpeed = benchmarkTable[benchmarkTotalItems].encSpeed; 4397 benchmarkTable[benchmarkTotalItems].decSpeed = benchmarkTable[benchmarkTotalItems].encSpeed;
4368 benchmarkTable[benchmarkTotalItems].id = hid; 4398 benchmarkTable[benchmarkTotalItems].id = hid;
4369 benchmarkTable[benchmarkTotalItems].meanBytesPerSec = ((unsigned __int64) (benchmarkBufferSize / ((float) benchmarkTable[benchmarkTotalItems].encSpeed / benchmarkPerformanceFrequency.QuadPart)) + (unsigned __int64) (benchmarkBufferSize / ((float) benchmarkTable[benchmarkTotalItems].decSpeed / benchmarkPerformanceFrequency.QuadPart))) / 2; 4399 benchmarkTable[benchmarkTotalItems].meanBytesPerSec = ((unsigned __int64) (benchmarkBufferSize / ((float) benchmarkTable[benchmarkTotalItems].encSpeed / benchmarkPerformanceFrequency.QuadPart)) + (unsigned __int64) (benchmarkBufferSize / ((float) benchmarkTable[benchmarkTotalItems].decSpeed / benchmarkPerformanceFrequency.QuadPart))) / 2;
4370 sprintf (benchmarkTable[benchmarkTotalItems].name, "%s", HashGetName(hid)); 4400 StringCbPrintfA (benchmarkTable[benchmarkTotalItems].name, sizeof(benchmarkTable[benchmarkTotalItems].name),"%s", HashGetName(hid));
4371 4401
4372 benchmarkTotalItems++; 4402 benchmarkTotalItems++;
4373 } 4403 }
@@ -4421,7 +4451,7 @@ static BOOL PerformBenchmark(HWND hwndDlg)
4421 4451
4422 benchmarkTable[benchmarkTotalItems].encSpeed = performanceCountEnd.QuadPart - performanceCountStart.QuadPart; 4452 benchmarkTable[benchmarkTotalItems].encSpeed = performanceCountEnd.QuadPart - performanceCountStart.QuadPart;
4423 benchmarkTable[benchmarkTotalItems].id = thid; 4453 benchmarkTable[benchmarkTotalItems].id = thid;
4424 sprintf (benchmarkTable[benchmarkTotalItems].name, "%s", get_pkcs5_prf_name (thid)); 4454 StringCbPrintfA (benchmarkTable[benchmarkTotalItems].name, sizeof(benchmarkTable[benchmarkTable[benchmarkTotalItems].name),"%s", get_pkcs5_prf_name (thid));
4425 4455
4426 benchmarkTotalItems++; 4456 benchmarkTotalItems++;
4427 } 4457 }
@@ -4569,43 +4599,43 @@ BOOL CALLBACK BenchmarkDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP
4569 4599
4570 SendMessage (hCboxBufferSize, CB_RESETCONTENT, 0, 0); 4600 SendMessage (hCboxBufferSize, CB_RESETCONTENT, 0, 0);
4571 4601
4572 swprintf (s, L"100 %s", GetString ("KB")); 4602 StringCbPrintfW (s, sizeof(s), L"100 %s", GetString ("KB"));
4573 nIndex = SendMessageW (hCboxBufferSize, CB_ADDSTRING, 0, (LPARAM) s); 4603 nIndex = SendMessageW (hCboxBufferSize, CB_ADDSTRING, 0, (LPARAM) s);
4574 SendMessage (hCboxBufferSize, CB_SETITEMDATA, nIndex, (LPARAM) 100 * BYTES_PER_KB); 4604 SendMessage (hCboxBufferSize, CB_SETITEMDATA, nIndex, (LPARAM) 100 * BYTES_PER_KB);
4575 4605
4576 swprintf (s, L"500 %s", GetString ("KB")); 4606 StringCbPrintfW (s, sizeof(s), L"500 %s", GetString ("KB"));
4577 nIndex = SendMessageW (hCboxBufferSize, CB_ADDSTRING, 0, (LPARAM) s); 4607 nIndex = SendMessageW (hCboxBufferSize, CB_ADDSTRING, 0, (LPARAM) s);
4578 SendMessage (hCboxBufferSize, CB_SETITEMDATA, nIndex, (LPARAM) 500 * BYTES_PER_KB); 4608 SendMessage (hCboxBufferSize, CB_SETITEMDATA, nIndex, (LPARAM) 500 * BYTES_PER_KB);
4579 4609
4580 swprintf (s, L"1 %s", GetString ("MB")); 4610 StringCbPrintfW (s, sizeof(s), L"1 %s", GetString ("MB"));
4581 nIndex = SendMessageW (hCboxBufferSize, CB_ADDSTRING, 0, (LPARAM) s); 4611 nIndex = SendMessageW (hCboxBufferSize, CB_ADDSTRING, 0, (LPARAM) s);
4582 SendMessage (hCboxBufferSize, CB_SETITEMDATA, nIndex, (LPARAM) 1 * BYTES_PER_MB); 4612 SendMessage (hCboxBufferSize, CB_SETITEMDATA, nIndex, (LPARAM) 1 * BYTES_PER_MB);
4583 4613
4584 swprintf (s, L"5 %s", GetString ("MB")); 4614 StringCbPrintfW (s, sizeof(s), L"5 %s", GetString ("MB"));
4585 nIndex = SendMessageW (hCboxBufferSize, CB_ADDSTRING, 0, (LPARAM) s); 4615 nIndex = SendMessageW (hCboxBufferSize, CB_ADDSTRING, 0, (LPARAM) s);
4586 SendMessage (hCboxBufferSize, CB_SETITEMDATA, nIndex, (LPARAM) 5 * BYTES_PER_MB); 4616 SendMessage (hCboxBufferSize, CB_SETITEMDATA, nIndex, (LPARAM) 5 * BYTES_PER_MB);
4587 4617
4588 swprintf (s, L"10 %s", GetString ("MB")); 4618 StringCbPrintfW (s, sizeof(s), L"10 %s", GetString ("MB"));
4589 nIndex = SendMessageW (hCboxBufferSize, CB_ADDSTRING, 0, (LPARAM) s); 4619 nIndex = SendMessageW (hCboxBufferSize, CB_ADDSTRING, 0, (LPARAM) s);
4590 SendMessage (hCboxBufferSize, CB_SETITEMDATA, nIndex, (LPARAM) 10 * BYTES_PER_MB); 4620 SendMessage (hCboxBufferSize, CB_SETITEMDATA, nIndex, (LPARAM) 10 * BYTES_PER_MB);
4591 4621
4592 swprintf (s, L"50 %s", GetString ("MB")); 4622 StringCbPrintfW (s, sizeof(s), L"50 %s", GetString ("MB"));
4593 nIndex = SendMessageW (hCboxBufferSize, CB_ADDSTRING, 0, (LPARAM) s); 4623 nIndex = SendMessageW (hCboxBufferSize, CB_ADDSTRING, 0, (LPARAM) s);
4594 SendMessage (hCboxBufferSize, CB_SETITEMDATA, nIndex, (LPARAM) 50 * BYTES_PER_MB); 4624 SendMessage (hCboxBufferSize, CB_SETITEMDATA, nIndex, (LPARAM) 50 * BYTES_PER_MB);
4595 4625
4596 swprintf (s, L"100 %s", GetString ("MB")); 4626 StringCbPrintfW (s, sizeof(s), L"100 %s", GetString ("MB"));
4597 nIndex = SendMessageW (hCboxBufferSize, CB_ADDSTRING, 0, (LPARAM) s); 4627 nIndex = SendMessageW (hCboxBufferSize, CB_ADDSTRING, 0, (LPARAM) s);
4598 SendMessage (hCboxBufferSize, CB_SETITEMDATA, nIndex, (LPARAM) 100 * BYTES_PER_MB); 4628 SendMessage (hCboxBufferSize, CB_SETITEMDATA, nIndex, (LPARAM) 100 * BYTES_PER_MB);
4599 4629
4600 swprintf (s, L"200 %s", GetString ("MB")); 4630 StringCbPrintfW (s, sizeof(s), L"200 %s", GetString ("MB"));
4601 nIndex = SendMessageW (hCboxBufferSize, CB_ADDSTRING, 0, (LPARAM) s); 4631 nIndex = SendMessageW (hCboxBufferSize, CB_ADDSTRING, 0, (LPARAM) s);
4602 SendMessage (hCboxBufferSize, CB_SETITEMDATA, nIndex, (LPARAM) 200 * BYTES_PER_MB); 4632 SendMessage (hCboxBufferSize, CB_SETITEMDATA, nIndex, (LPARAM) 200 * BYTES_PER_MB);
4603 4633
4604 swprintf (s, L"500 %s", GetString ("MB")); 4634 StringCbPrintfW (s, sizeof(s), L"500 %s", GetString ("MB"));
4605 nIndex = SendMessageW (hCboxBufferSize, CB_ADDSTRING, 0, (LPARAM) s); 4635 nIndex = SendMessageW (hCboxBufferSize, CB_ADDSTRING, 0, (LPARAM) s);
4606 SendMessage (hCboxBufferSize, CB_SETITEMDATA, nIndex, (LPARAM) 500 * BYTES_PER_MB); 4636 SendMessage (hCboxBufferSize, CB_SETITEMDATA, nIndex, (LPARAM) 500 * BYTES_PER_MB);
4607 4637
4608 swprintf (s, L"1 %s", GetString ("GB")); 4638 StringCbPrintfW (s, sizeof(s), L"1 %s", GetString ("GB"));
4609 nIndex = SendMessageW (hCboxBufferSize, CB_ADDSTRING, 0, (LPARAM) s); 4639 nIndex = SendMessageW (hCboxBufferSize, CB_ADDSTRING, 0, (LPARAM) s);
4610 SendMessage (hCboxBufferSize, CB_SETITEMDATA, nIndex, (LPARAM) 1 * BYTES_PER_GB); 4640 SendMessage (hCboxBufferSize, CB_SETITEMDATA, nIndex, (LPARAM) 1 * BYTES_PER_GB);
4611 4641
@@ -4631,15 +4661,15 @@ BOOL CALLBACK BenchmarkDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP
4631 wchar_t nbrThreadsStr [300]; 4661 wchar_t nbrThreadsStr [300];
4632 if (sysInfo.dwNumberOfProcessors < 2) 4662 if (sysInfo.dwNumberOfProcessors < 2)
4633 { 4663 {
4634 wcscpy (nbrThreadsStr, GetString ("NOT_APPLICABLE_OR_NOT_AVAILABLE")); 4664 StringCbCopyW (nbrThreadsStr, sizeof(nbrThreadsStr), GetString ("NOT_APPLICABLE_OR_NOT_AVAILABLE"));
4635 } 4665 }
4636 else if (nbrThreads < 2) 4666 else if (nbrThreads < 2)
4637 { 4667 {
4638 wcscpy (nbrThreadsStr, GetString ("UISTR_DISABLED")); 4668 StringCbCopyW (nbrThreadsStr, sizeof(nbrThreadsStr), GetString ("UISTR_DISABLED"));
4639 } 4669 }
4640 else 4670 else
4641 { 4671 {
4642 wsprintfW (nbrThreadsStr, GetString ("NUMBER_OF_THREADS"), nbrThreads); 4672 StringCbPrintfW (nbrThreadsStr, sizeof(nbrThreadsStr), GetString ("NUMBER_OF_THREADS"), nbrThreads);
4643 } 4673 }
4644 4674
4645 SetDlgItemTextW (hwndDlg, IDC_PARALLELIZATION, (wstring (L" ") + nbrThreadsStr).c_str()); 4675 SetDlgItemTextW (hwndDlg, IDC_PARALLELIZATION, (wstring (L" ") + nbrThreadsStr).c_str());
@@ -4772,10 +4802,10 @@ static BOOL CALLBACK RandomPoolEnrichementDlgProc (HWND hwndDlg, UINT msg, WPARA
4772 { 4802 {
4773 tmpByte = randPool[row * RANDPOOL_DISPLAY_COLUMNS + col]; 4803 tmpByte = randPool[row * RANDPOOL_DISPLAY_COLUMNS + col];
4774 4804
4775 sprintf (tmp, bRandPoolDispAscii ? ((tmpByte >= 32 && tmpByte < 255 && tmpByte != '&') ? " %c " : " . ") : "%02X ", tmpByte); 4805 StringCbPrintfA (tmp, sizeof(tmp), bRandPoolDispAscii ? ((tmpByte >= 32 && tmpByte < 255 && tmpByte != '&') ? " %c " : " . ") : "%02X ", tmpByte);
4776 strcat (outputDispBuffer, tmp); 4806 StringCbCatA (outputDispBuffer, sizeof(outputDispBuffer), tmp);
4777 } 4807 }
4778 strcat (outputDispBuffer, "\n"); 4808 StringCbCatA (outputDispBuffer, sizeof(outputDispBuffer), "\n");
4779 } 4809 }
4780 SetWindowText (GetDlgItem (hwndDlg, IDC_POOL_CONTENTS), outputDispBuffer); 4810 SetWindowText (GetDlgItem (hwndDlg, IDC_POOL_CONTENTS), outputDispBuffer);
4781 4811
@@ -4926,10 +4956,10 @@ BOOL CALLBACK KeyfileGeneratorDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LP
4926 { 4956 {
4927 tmpByte = randPool[row * RANDPOOL_DISPLAY_COLUMNS + col]; 4957 tmpByte = randPool[row * RANDPOOL_DISPLAY_COLUMNS + col];
4928 4958
4929 sprintf (tmp, bRandPoolDispAscii ? ((tmpByte >= 32 && tmpByte < 255 && tmpByte != '&') ? " %c " : " . ") : "%02X ", tmpByte); 4959 StringCbPrintfA (tmp, sizeof(tmp), bRandPoolDispAscii ? ((tmpByte >= 32 && tmpByte < 255 && tmpByte != '&') ? " %c " : " . ") : "%02X ", tmpByte);
4930 strcat (outputDispBuffer, tmp); 4960 StringCbCatA (outputDispBuffer, sizeof(outputDispBuffer), tmp);
4931 } 4961 }
4932 strcat (outputDispBuffer, "\n"); 4962 StringCbCatA (outputDispBuffer, sizeof(outputDispBuffer), "\n");
4933 } 4963 }
4934 SetWindowText (GetDlgItem (hwndDlg, IDC_POOL_CONTENTS), outputDispBuffer); 4964 SetWindowText (GetDlgItem (hwndDlg, IDC_POOL_CONTENTS), outputDispBuffer);
4935 4965
@@ -5370,8 +5400,8 @@ CipherTestDialogProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
5370 for (n = 0; n < pt; n ++) 5400 for (n = 0; n < pt; n ++)
5371 { 5401 {
5372 char szTmp2[3]; 5402 char szTmp2[3];
5373 sprintf(szTmp2, "%02x", (int)((unsigned char)tmp[n])); 5403 StringCbPrintfA(szTmp2, sizeof(szTmp2), "%02x", (int)((unsigned char)tmp[n]));
5374 strcat(szTmp, szTmp2); 5404 StringCbCatA(szTmp, sizeof(szTmp), szTmp2);
5375 } 5405 }
5376 5406
5377 if (bEncrypt) 5407 if (bEncrypt)
@@ -5424,7 +5454,7 @@ ResetCipherTest(HWND hwndDlg, int idTestCipher)
5424 { 5454 {
5425 char tmpStr [16]; 5455 char tmpStr [16];
5426 5456
5427 sprintf (tmpStr, "%d", ndx); 5457 StringCbPrintfA (tmpStr, sizeof(tmpStr), "%d", ndx);
5428 5458
5429 ndx = SendMessage (GetDlgItem(hwndDlg, IDC_TEST_BLOCK_NUMBER), CB_ADDSTRING, 0,(LPARAM) tmpStr); 5459 ndx = SendMessage (GetDlgItem(hwndDlg, IDC_TEST_BLOCK_NUMBER), CB_ADDSTRING, 0,(LPARAM) tmpStr);
5430 SendMessage(GetDlgItem(hwndDlg, IDC_TEST_BLOCK_NUMBER), CB_SETITEMDATA, ndx,(LPARAM) ndx); 5460 SendMessage(GetDlgItem(hwndDlg, IDC_TEST_BLOCK_NUMBER), CB_SETITEMDATA, ndx,(LPARAM) ndx);
@@ -5871,7 +5901,7 @@ int DriverUnmountVolume (HWND hwndDlg, int nDosDriveNo, BOOL forced)
5871 wchar_t msg[4096]; 5901 wchar_t msg[4096];
5872 5902
5873 VolumeNotificationsList.bHidVolDamagePrevReported [nDosDriveNo] = TRUE; 5903 VolumeNotificationsList.bHidVolDamagePrevReported [nDosDriveNo] = TRUE;
5874 swprintf (msg, GetString ("DAMAGE_TO_HIDDEN_VOLUME_PREVENTED"), nDosDriveNo + 'A'); 5904 StringCbPrintfW (msg, sizeof(msg), GetString ("DAMAGE_TO_HIDDEN_VOLUME_PREVENTED"), nDosDriveNo + 'A');
5875 SetForegroundWindow (hwndDlg); 5905 SetForegroundWindow (hwndDlg);
5876 MessageBoxW (hwndDlg, msg, lpszTitle, MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST); 5906 MessageBoxW (hwndDlg, msg, lpszTitle, MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST);
5877 } 5907 }
@@ -5914,7 +5944,7 @@ void BroadcastDeviceChange (WPARAM message, int nDosDriveNo, DWORD driveMap)
5914 if (nCurrentOS == WIN_2000 && RemoteSession) 5944 if (nCurrentOS == WIN_2000 && RemoteSession)
5915 { 5945 {
5916 char target[32]; 5946 char target[32];
5917 wsprintf (target, "%ls%c", TC_MOUNT_PREFIX, i + 'A'); 5947 StringCbPrintfA (target, sizeof(target), "%ls%c", TC_MOUNT_PREFIX, i + 'A');
5918 root[2] = 0; 5948 root[2] = 0;
5919 5949
5920 if (message == DBT_DEVICEARRIVAL) 5950 if (message == DBT_DEVICEARRIVAL)
@@ -6055,7 +6085,7 @@ retry:
6055 strcpy_s (volumePath, TC_MAX_PATH, resolvedPath.c_str()); 6085 strcpy_s (volumePath, TC_MAX_PATH, resolvedPath.c_str());
6056 } 6086 }
6057 6087
6058 CreateFullVolumePath ((char *) mount.wszVolume, volumePath, &bDevice); 6088 CreateFullVolumePath ((char *) mount.wszVolume, sizeof(mount.wszVolume), volumePath, &bDevice);
6059 6089
6060 if (!bDevice) 6090 if (!bDevice)
6061 { 6091 {
@@ -6077,7 +6107,7 @@ retry:
6077 } 6107 }
6078 } 6108 }
6079 6109
6080 ToUNICODE ((char *) mount.wszVolume); 6110 ToUNICODE ((char *) mount.wszVolume, sizeof(mount.wszVolume));
6081 6111
6082 if (mountOptions->PartitionInInactiveSysEncScope) 6112 if (mountOptions->PartitionInInactiveSysEncScope)
6083 { 6113 {
@@ -6168,7 +6198,7 @@ retry:
6168 memset (&openTestStruct, 0, sizeof (openTestStruct)); 6198 memset (&openTestStruct, 0, sizeof (openTestStruct));
6169 6199
6170 openTestStruct.bDetectTCBootLoader = TRUE; 6200 openTestStruct.bDetectTCBootLoader = TRUE;
6171 _snwprintf ((wchar_t *) openTestStruct.wszFileName, array_capacity (openTestStruct.wszFileName), L"\\Device\\Harddisk%d\\Partition0", driveNo); 6201 StringCchPrintfW ((wchar_t *) openTestStruct.wszFileName, array_capacity (openTestStruct.wszFileName), L"\\Device\\Harddisk%d\\Partition0", driveNo);
6172 6202
6173 DWORD dwResult; 6203 DWORD dwResult;
6174 if (DeviceIoControl (hDriver, TC_IOCTL_OPEN_TEST, &openTestStruct, sizeof (OPEN_TEST_STRUCT), &openTestStruct, sizeof (OPEN_TEST_STRUCT), &dwResult, NULL) && openTestStruct.TCBootLoaderDetected) 6204 if (DeviceIoControl (hDriver, TC_IOCTL_OPEN_TEST, &openTestStruct, sizeof (OPEN_TEST_STRUCT), &openTestStruct, sizeof (OPEN_TEST_STRUCT), &dwResult, NULL) && openTestStruct.TCBootLoaderDetected)
@@ -6205,7 +6235,7 @@ retry:
6205 { 6235 {
6206 wchar_t msg[1024]; 6236 wchar_t msg[1024];
6207 wchar_t mountPoint[] = { L'A' + (wchar_t) driveNo, L':', 0 }; 6237 wchar_t mountPoint[] = { L'A' + (wchar_t) driveNo, L':', 0 };
6208 wsprintfW (msg, GetString ("MOUNTED_VOLUME_DIRTY"), mountPoint); 6238 StringCbPrintfW (msg, sizeof(msg), GetString ("MOUNTED_VOLUME_DIRTY"), mountPoint);
6209 6239
6210 if (AskWarnYesNoStringTopmost (msg) == IDYES) 6240 if (AskWarnYesNoStringTopmost (msg) == IDYES)
6211 CheckFilesystem (driveNo, TRUE); 6241 CheckFilesystem (driveNo, TRUE);
@@ -6219,7 +6249,7 @@ retry:
6219 { 6249 {
6220 wchar_t msg[1024]; 6250 wchar_t msg[1024];
6221 wchar_t mountPoint[] = { L'A' + (wchar_t) driveNo, L':', 0 }; 6251 wchar_t mountPoint[] = { L'A' + (wchar_t) driveNo, L':', 0 };
6222 wsprintfW (msg, GetString ("MOUNTED_CONTAINER_FORCED_READ_ONLY"), mountPoint); 6252 StringCbPrintfW (msg, sizeof(msg), GetString ("MOUNTED_CONTAINER_FORCED_READ_ONLY"), mountPoint);
6223 6253
6224 WarningDirect (msg); 6254 WarningDirect (msg);
6225 } 6255 }
@@ -6230,7 +6260,7 @@ retry:
6230 { 6260 {
6231 wchar_t msg[1024]; 6261 wchar_t msg[1024];
6232 wchar_t mountPoint[] = { L'A' + (wchar_t) driveNo, L':', 0 }; 6262 wchar_t mountPoint[] = { L'A' + (wchar_t) driveNo, L':', 0 };
6233 wsprintfW (msg, GetString ("MOUNTED_DEVICE_FORCED_READ_ONLY"), mountPoint); 6263 StringCbPrintfW (msg, sizeof(msg), GetString ("MOUNTED_DEVICE_FORCED_READ_ONLY"), mountPoint);
6234 6264
6235 WarningDirect (msg); 6265 WarningDirect (msg);
6236 } 6266 }
@@ -6241,7 +6271,7 @@ retry:
6241 { 6271 {
6242 wchar_t msg[1024]; 6272 wchar_t msg[1024];
6243 wchar_t mountPoint[] = { L'A' + (wchar_t) driveNo, L':', 0 }; 6273 wchar_t mountPoint[] = { L'A' + (wchar_t) driveNo, L':', 0 };
6244 wsprintfW (msg, GetString ("MOUNTED_DEVICE_FORCED_READ_ONLY_WRITE_PROTECTION"), mountPoint); 6274 StringCbPrintfW (msg, sizeof(msg), GetString ("MOUNTED_DEVICE_FORCED_READ_ONLY_WRITE_PROTECTION"), mountPoint);
6245 6275
6246 WarningDirect (msg); 6276 WarningDirect (msg);
6247 6277
@@ -6329,16 +6359,16 @@ BOOL IsMountedVolume (const char *volname)
6329 int i; 6359 int i;
6330 char volume[TC_MAX_PATH*2+16]; 6360 char volume[TC_MAX_PATH*2+16];
6331 6361
6332 strcpy (volume, volname); 6362 StringCbCopyA (volume, sizeof(volume), volname);
6333 6363
6334 if (strstr (volname, "\\Device\\") != volname) 6364 if (strstr (volname, "\\Device\\") != volname)
6335 sprintf(volume, "\\??\\%s", volname); 6365 StringCbPrintfA(volume, sizeof(volume), "\\??\\%s", volname);
6336 6366
6337 string resolvedPath = VolumeGuidPathToDevicePath (volname); 6367 string resolvedPath = VolumeGuidPathToDevicePath (volname);
6338 if (!resolvedPath.empty()) 6368 if (!resolvedPath.empty())
6339 strcpy_s (volume, sizeof (volume), resolvedPath.c_str()); 6369 StringCbCopyA (volume, sizeof (volume), resolvedPath.c_str());
6340 6370
6341 ToUNICODE (volume); 6371 ToUNICODE (volume, sizeof(volume));
6342 6372
6343 memset (&mlist, 0, sizeof (mlist)); 6373 memset (&mlist, 0, sizeof (mlist));
6344 DeviceIoControl (hDriver, TC_IOCTL_GET_MOUNTED_VOLUMES, &mlist, 6374 DeviceIoControl (hDriver, TC_IOCTL_GET_MOUNTED_VOLUMES, &mlist,
@@ -6363,16 +6393,16 @@ int GetMountedVolumeDriveNo (char *volname)
6363 if (volname == NULL) 6393 if (volname == NULL)
6364 return -1; 6394 return -1;
6365 6395
6366 strcpy (volume, volname); 6396 StringCbCopyA (volume, sizeof(volume), volname);
6367 6397
6368 if (strstr (volname, "\\Device\\") != volname) 6398 if (strstr (volname, "\\Device\\") != volname)
6369 sprintf(volume, "\\??\\%s", volname); 6399 StringCbPrintfA (volume, sizeof(volume), "\\??\\%s", volname);
6370 6400
6371 string resolvedPath = VolumeGuidPathToDevicePath (volname); 6401 string resolvedPath = VolumeGuidPathToDevicePath (volname);
6372 if (!resolvedPath.empty()) 6402 if (!resolvedPath.empty())
6373 strcpy_s (volume, sizeof (volume), resolvedPath.c_str()); 6403 StringCbCopyA (volume, sizeof (volume), resolvedPath.c_str());
6374 6404
6375 ToUNICODE (volume); 6405 ToUNICODE (volume, sizeof(volume));
6376 6406
6377 memset (&mlist, 0, sizeof (mlist)); 6407 memset (&mlist, 0, sizeof (mlist));
6378 DeviceIoControl (hDriver, TC_IOCTL_GET_MOUNTED_VOLUMES, &mlist, 6408 DeviceIoControl (hDriver, TC_IOCTL_GET_MOUNTED_VOLUMES, &mlist,
@@ -6439,20 +6469,20 @@ BOOL IsUacSupported ()
6439} 6469}
6440 6470
6441 6471
6442BOOL ResolveSymbolicLink (const wchar_t *symLinkName, PWSTR targetName) 6472BOOL ResolveSymbolicLink (const wchar_t *symLinkName, PWSTR targetName, size_t cbTargetName)
6443{ 6473{
6444 BOOL bResult; 6474 BOOL bResult;
6445 DWORD dwResult; 6475 DWORD dwResult;
6446 RESOLVE_SYMLINK_STRUCT resolve; 6476 RESOLVE_SYMLINK_STRUCT resolve;
6447 6477
6448 memset (&resolve, 0, sizeof(resolve)); 6478 memset (&resolve, 0, sizeof(resolve));
6449 wcscpy ((PWSTR) &resolve.symLinkName, symLinkName); 6479 StringCbCopyW (resolve.symLinkName, sizeof(resolve.symLinkName), symLinkName);
6450 6480
6451 bResult = DeviceIoControl (hDriver, TC_IOCTL_GET_RESOLVED_SYMLINK, &resolve, 6481 bResult = DeviceIoControl (hDriver, TC_IOCTL_GET_RESOLVED_SYMLINK, &resolve,
6452 sizeof (resolve), &resolve, sizeof (resolve), &dwResult, 6482 sizeof (resolve), &resolve, sizeof (resolve), &dwResult,
6453 NULL); 6483 NULL);
6454 6484
6455 wcscpy (targetName, (PWSTR) &resolve.targetName); 6485 StringCbCopyW (targetName, cbTargetName, resolve.targetName);
6456 6486
6457 return bResult; 6487 return bResult;
6458} 6488}
@@ -6465,7 +6495,7 @@ BOOL GetPartitionInfo (const char *deviceName, PPARTITION_INFORMATION rpartInfo)
6465 DISK_PARTITION_INFO_STRUCT dpi; 6495 DISK_PARTITION_INFO_STRUCT dpi;
6466 6496
6467 memset (&dpi, 0, sizeof(dpi)); 6497 memset (&dpi, 0, sizeof(dpi));
6468 wsprintfW ((PWSTR) &dpi.deviceName, L"%hs", deviceName); 6498 StringCbPrintfW ((PWSTR) &dpi.deviceName, sizeof(dpi.deviceName), L"%hs", deviceName);
6469 6499
6470 bResult = DeviceIoControl (hDriver, TC_IOCTL_GET_DRIVE_PARTITION_INFO, &dpi, 6500 bResult = DeviceIoControl (hDriver, TC_IOCTL_GET_DRIVE_PARTITION_INFO, &dpi,
6471 sizeof (dpi), &dpi, sizeof (dpi), &dwResult, NULL); 6501 sizeof (dpi), &dpi, sizeof (dpi), &dwResult, NULL);
@@ -6480,7 +6510,7 @@ BOOL GetDeviceInfo (const char *deviceName, DISK_PARTITION_INFO_STRUCT *info)
6480 DWORD dwResult; 6510 DWORD dwResult;
6481 6511
6482 memset (info, 0, sizeof(*info)); 6512 memset (info, 0, sizeof(*info));
6483 wsprintfW ((PWSTR) &info->deviceName, L"%hs", deviceName); 6513 StringCbPrintfW ((PWSTR) &info->deviceName, sizeof(info->deviceName), L"%hs", deviceName);
6484 6514
6485 return DeviceIoControl (hDriver, TC_IOCTL_GET_DRIVE_PARTITION_INFO, info, sizeof (*info), info, sizeof (*info), &dwResult, NULL); 6515 return DeviceIoControl (hDriver, TC_IOCTL_GET_DRIVE_PARTITION_INFO, info, sizeof (*info), info, sizeof (*info), &dwResult, NULL);
6486} 6516}
@@ -6493,7 +6523,7 @@ BOOL GetDriveGeometry (const char *deviceName, PDISK_GEOMETRY diskGeometry)
6493 DISK_GEOMETRY_STRUCT dg; 6523 DISK_GEOMETRY_STRUCT dg;
6494 6524
6495 memset (&dg, 0, sizeof(dg)); 6525 memset (&dg, 0, sizeof(dg));
6496 wsprintfW ((PWSTR) &dg.deviceName, L"%hs", deviceName); 6526 StringCbPrintfW ((PWSTR) &dg.deviceName, sizeof(dg.deviceName), L"%hs", deviceName);
6497 6527
6498 bResult = DeviceIoControl (hDriver, TC_IOCTL_GET_DRIVE_GEOMETRY, &dg, 6528 bResult = DeviceIoControl (hDriver, TC_IOCTL_GET_DRIVE_GEOMETRY, &dg,
6499 sizeof (dg), &dg, sizeof (dg), &dwResult, NULL); 6529 sizeof (dg), &dg, sizeof (dg), &dwResult, NULL);
@@ -6511,17 +6541,17 @@ int GetDiskDeviceDriveLetter (PWSTR deviceName)
6511 WCHAR target[MAX_PATH]; 6541 WCHAR target[MAX_PATH];
6512 WCHAR device[MAX_PATH]; 6542 WCHAR device[MAX_PATH];
6513 6543
6514 if (!ResolveSymbolicLink (deviceName, device)) 6544 if (!ResolveSymbolicLink (deviceName, device, sizeof(device)))
6515 wcscpy (device, deviceName); 6545 StringCchCopyW (device, MAX_PATH, deviceName);
6516 6546
6517 for (i = 0; i < 26; i++) 6547 for (i = 0; i < 26; i++)
6518 { 6548 {
6519 WCHAR drive[] = { (WCHAR) i + 'A', ':', 0 }; 6549 WCHAR drive[] = { (WCHAR) i + 'A', ':', 0 };
6520 6550
6521 wcscpy (link, L"\\DosDevices\\"); 6551 StringCchCopyW (link, MAX_PATH, L"\\DosDevices\\");
6522 wcscat (link, drive); 6552 StringCchCatW (link, MAX_PATH, drive);
6523 6553
6524 ResolveSymbolicLink (link, target); 6554 ResolveSymbolicLink (link, target, sizeof(target));
6525 6555
6526 if (wcscmp (device, target) == 0) 6556 if (wcscmp (device, target) == 0)
6527 return i; 6557 return i;
@@ -6566,8 +6596,8 @@ __int64 GetStatsFreeSpaceOnPartition (const char *devicePath, float *percentFree
6566 ULARGE_INTEGER totalNumberOfBytes; 6596 ULARGE_INTEGER totalNumberOfBytes;
6567 ULARGE_INTEGER totalNumberOfFreeBytes; 6597 ULARGE_INTEGER totalNumberOfFreeBytes;
6568 6598
6569 strcpy ((char *) devPath, devicePath); 6599 StringCbCopyA ((char *) devPath, sizeof(devPath), devicePath);
6570 ToUNICODE ((char *) devPath); 6600 ToUNICODE ((char *) devPath, sizeof(devPath));
6571 6601
6572 driveLetterNo = GetDiskDeviceDriveLetter (devPath); 6602 driveLetterNo = GetDiskDeviceDriveLetter (devPath);
6573 szRootPath[0] = (char) driveLetterNo + 'A'; 6603 szRootPath[0] = (char) driveLetterNo + 'A';
@@ -6633,8 +6663,8 @@ HANDLE DismountDrive (char *devName, char *devicePath)
6633 int driveLetterNo = -1; 6663 int driveLetterNo = -1;
6634 WCHAR devPath [MAX_PATH]; 6664 WCHAR devPath [MAX_PATH];
6635 6665
6636 strcpy ((char *) devPath, devicePath); 6666 StringCbCopyA ((char *) devPath, sizeof(devPath), devicePath);
6637 ToUNICODE ((char *) devPath); 6667 ToUNICODE ((char *) devPath, sizeof(devPath));
6638 driveLetterNo = GetDiskDeviceDriveLetter (devPath); 6668 driveLetterNo = GetDiskDeviceDriveLetter (devPath);
6639 6669
6640 6670
@@ -6702,16 +6732,16 @@ int64 FindString (const char *buf, const char *str, int64 bufLen, size_t strLen,
6702// Returns TRUE if the file or directory exists (both may be enclosed in quotation marks). 6732// Returns TRUE if the file or directory exists (both may be enclosed in quotation marks).
6703BOOL FileExists (const char *filePathPtr) 6733BOOL FileExists (const char *filePathPtr)
6704{ 6734{
6705 char filePath [TC_MAX_PATH]; 6735 char filePath [TC_MAX_PATH * 2 + 1];
6706 6736
6707 // Strip quotation marks (if any) 6737 // Strip quotation marks (if any)
6708 if (filePathPtr [0] == '"') 6738 if (filePathPtr [0] == '"')
6709 { 6739 {
6710 strcpy (filePath, filePathPtr + 1); 6740 StringCbCopyA (filePath, sizeof(filePath), filePathPtr + 1);
6711 } 6741 }
6712 else 6742 else
6713 { 6743 {
6714 strcpy (filePath, filePathPtr); 6744 StringCbCopyA (filePath, sizeof(filePath), filePathPtr);
6715 } 6745 }
6716 6746
6717 // Strip quotation marks (if any) 6747 // Strip quotation marks (if any)
@@ -6928,21 +6958,21 @@ BOOL PrintHardCopyTextUTF16 (wchar_t *text, char *title, int textByteLen)
6928 char path [MAX_PATH * 2] = { 0 }; 6958 char path [MAX_PATH * 2] = { 0 };
6929 char filename [MAX_PATH + 1] = { 0 }; 6959 char filename [MAX_PATH + 1] = { 0 };
6930 6960
6931 strcpy (filename, title); 6961 StringCbCopyA (filename, sizeof(filename), title);
6932 //strcat (filename, ".txt"); 6962 //strcat (filename, ".txt");
6933 6963
6934 GetTempPath (sizeof (path), path); 6964 GetTempPath (sizeof (path), path);
6935 6965
6936 if (!FileExists (path)) 6966 if (!FileExists (path))
6937 { 6967 {
6938 strcpy (path, GetConfigPath (filename)); 6968 StringCbCopyA (path, sizeof(path), GetConfigPath (filename));
6939 6969
6940 if (strlen(path) < 2) 6970 if (strlen(path) < 2)
6941 return FALSE; 6971 return FALSE;
6942 } 6972 }
6943 else 6973 else
6944 { 6974 {
6945 strcat (path, filename); 6975 StringCbCatA (path, sizeof(path), filename);
6946 } 6976 }
6947 6977
6948 // Write the Unicode signature 6978 // Write the Unicode signature
@@ -6959,18 +6989,18 @@ BOOL PrintHardCopyTextUTF16 (wchar_t *text, char *title, int textByteLen)
6959 return FALSE; 6989 return FALSE;
6960 } 6990 }
6961 6991
6962 strcat (cl, path); 6992 StringCbCatA (cl, sizeof(cl), path);
6963 strcat (cl, "\""); 6993 StringCbCatA (cl, sizeof(cl), "\"");
6964 6994
6965 // Get the absolute path for notepad 6995 // Get the absolute path for notepad
6966 if (GetWindowsDirectory(filename, MAX_PATH)) 6996 if (GetWindowsDirectory(filename, MAX_PATH))
6967 { 6997 {
6968 if (filename[strlen (filename) - 1] != '\\') 6998 if (filename[strlen (filename) - 1] != '\\')
6969 strcat (filename, "\\"); 6999 StringCbCatA (filename, sizeof(filename), "\\");
6970 strcat(filename, PRINT_TOOL); 7000 StringCbCatA(filename, sizeof(filename), PRINT_TOOL);
6971 } 7001 }
6972 else 7002 else
6973 strcpy(filename, "C:\\Windows\\" PRINT_TOOL); 7003 StringCbCopyA(filename, sizeof(filename), "C:\\Windows\\" PRINT_TOOL);
6974 7004
6975 WaitCursor (); 7005 WaitCursor ();
6976 ShellExecute (NULL, "open", PRINT_TOOL, cl, NULL, SW_HIDE); 7006 ShellExecute (NULL, "open", PRINT_TOOL, cl, NULL, SW_HIDE);
@@ -7020,8 +7050,8 @@ BOOL IsNonInstallMode ()
7020 // We can't use GetConfigPath() here because it would call us back (indirect recursion) 7050 // We can't use GetConfigPath() here because it would call us back (indirect recursion)
7021 if (SUCCEEDED(SHGetFolderPath (NULL, CSIDL_APPDATA, NULL, 0, path))) 7051 if (SUCCEEDED(SHGetFolderPath (NULL, CSIDL_APPDATA, NULL, 0, path)))
7022 { 7052 {
7023 strcat (path, "\\VeraCrypt\\"); 7053 StringCbCatA (path, MAX_PATH * 2, "\\VeraCrypt\\");
7024 strcat (path, TC_APPD_FILENAME_SYSTEM_ENCRYPTION); 7054 StringCbCatA (path, MAX_PATH * 2, TC_APPD_FILENAME_SYSTEM_ENCRYPTION);
7025 7055
7026 if (FileExists (path)) 7056 if (FileExists (path))
7027 { 7057 {
@@ -7088,7 +7118,7 @@ void ManageStartupSeq (void)
7088 { 7118 {
7089 char regk [64]; 7119 char regk [64];
7090 7120
7091 GetStartupRegKeyName (regk); 7121 GetStartupRegKeyName (regk, sizeof(regk));
7092 7122
7093 if (bStartOnLogon || bMountDevicesOnLogon || bMountFavoritesOnLogon) 7123 if (bStartOnLogon || bMountDevicesOnLogon || bMountFavoritesOnLogon)
7094 { 7124 {
@@ -7101,13 +7131,16 @@ void ManageStartupSeq (void)
7101 char *tmp = NULL; 7131 char *tmp = NULL;
7102 7132
7103 if (tmp = strrchr (exe, '\\')) 7133 if (tmp = strrchr (exe, '\\'))
7104 strcpy (++tmp, "VeraCrypt.exe"); 7134 {
7135 *tmp = 0;
7136 StringCbCatA (exe, MAX_PATH * 2, "\\VeraCrypt.exe");
7137 }
7105 } 7138 }
7106#endif 7139#endif
7107 strcat (exe, "\" /q preferences /a logon"); 7140 StringCbCatA (exe, MAX_PATH * 2, "\" /q preferences /a logon");
7108 7141
7109 if (bMountDevicesOnLogon) strcat (exe, " /a devices"); 7142 if (bMountDevicesOnLogon) StringCbCatA (exe, MAX_PATH * 2, " /a devices");
7110 if (bMountFavoritesOnLogon) strcat (exe, " /a favorites"); 7143 if (bMountFavoritesOnLogon) StringCbCatA (exe, MAX_PATH * 2, " /a favorites");
7111 7144
7112 WriteRegistryString (regk, "VeraCrypt", exe); 7145 WriteRegistryString (regk, "VeraCrypt", exe);
7113 } 7146 }
@@ -7117,34 +7150,42 @@ void ManageStartupSeq (void)
7117} 7150}
7118 7151
7119 7152
7120// Adds or removes the TrueCrypt Volume Creation Wizard to/from the system startup sequence 7153// Adds or removes the VeraCrypt Volume Creation Wizard to/from the system startup sequence
7121void ManageStartupSeqWiz (BOOL bRemove, const char *arg) 7154void ManageStartupSeqWiz (BOOL bRemove, const char *arg)
7122{ 7155{
7123 char regk [64]; 7156 char regk [64];
7124 7157
7125 GetStartupRegKeyName (regk); 7158 GetStartupRegKeyName (regk, sizeof(regk));
7126 7159
7127 if (!bRemove) 7160 if (!bRemove)
7128 { 7161 {
7129 char exe[MAX_PATH * 2] = { '"' }; 7162 size_t exeSize = (MAX_PATH * 2) + 3 + 20 + strlen (arg); // enough room for all concatenation operations
7130 GetModuleFileName (NULL, exe + 1, sizeof (exe) - 1); 7163 char* exe = (char*) calloc(1, exeSize);
7164 exe[0] = '"';
7165 GetModuleFileName (NULL, exe + 1, (DWORD) (exeSize - 1));
7131 7166
7132#ifndef VOLFORMAT 7167#ifndef VOLFORMAT
7133 { 7168 {
7134 char *tmp = NULL; 7169 char *tmp = NULL;
7135 7170
7136 if (tmp = strrchr (exe, '\\')) 7171 if (tmp = strrchr (exe, '\\'))
7137 strcpy (++tmp, "VeraCrypt Format.exe"); 7172 {
7173 *tmp = 0;
7174
7175 StringCbCatA (exe, exeSize, "\\VeraCrypt Format.exe");
7176 }
7138 } 7177 }
7139#endif 7178#endif
7140 7179
7141 if (strlen (arg) > 0) 7180 if (strlen (arg) > 0)
7142 { 7181 {
7143 strcat (exe, "\" "); 7182 StringCbCatA (exe, exeSize, "\" ");
7144 strcat (exe, arg); 7183 StringCbCatA (exe, exeSize, arg);
7145 } 7184 }
7146 7185
7147 WriteRegistryString (regk, "VeraCrypt Format", exe); 7186 WriteRegistryString (regk, "VeraCrypt Format", exe);
7187
7188 free(exe);
7148 } 7189 }
7149 else 7190 else
7150 DeleteRegistryValue (regk, "VeraCrypt Format"); 7191 DeleteRegistryValue (regk, "VeraCrypt Format");
@@ -7165,12 +7206,12 @@ void CleanLastVisitedMRU (void)
7165 GetModuleFileNameW (NULL, exeFilename, sizeof (exeFilename) / sizeof(exeFilename[0])); 7206 GetModuleFileNameW (NULL, exeFilename, sizeof (exeFilename) / sizeof(exeFilename[0]));
7166 strToMatch = wcsrchr (exeFilename, '\\') + 1; 7207 strToMatch = wcsrchr (exeFilename, '\\') + 1;
7167 7208
7168 sprintf (regPath, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ComDlg32\\LastVisited%sMRU", IsOSAtLeast (WIN_VISTA) ? "Pidl" : ""); 7209 StringCbPrintfA (regPath, sizeof(regPath), "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ComDlg32\\LastVisited%sMRU", IsOSAtLeast (WIN_VISTA) ? "Pidl" : "");
7169 7210
7170 for (id = (IsOSAtLeast (WIN_VISTA) ? 0 : 'a'); id <= (IsOSAtLeast (WIN_VISTA) ? 1000 : 'z'); id++) 7211 for (id = (IsOSAtLeast (WIN_VISTA) ? 0 : 'a'); id <= (IsOSAtLeast (WIN_VISTA) ? 1000 : 'z'); id++)
7171 { 7212 {
7172 *strTmp = 0; 7213 *strTmp = 0;
7173 sprintf (key, (IsOSAtLeast (WIN_VISTA) ? "%d" : "%c"), id); 7214 StringCbPrintfA (key, sizeof(key), (IsOSAtLeast (WIN_VISTA) ? "%d" : "%c"), id);
7174 7215
7175 if ((len = ReadRegistryBytes (regPath, key, (char *) strTmp, sizeof (strTmp))) > 0) 7216 if ((len = ReadRegistryBytes (regPath, key, (char *) strTmp, sizeof (strTmp))) > 0)
7176 { 7217 {
@@ -7513,7 +7554,9 @@ __int64 GetFileSize64 (const char *path)
7513char *GetModPath (char *path, int maxSize) 7554char *GetModPath (char *path, int maxSize)
7514{ 7555{
7515 GetModuleFileName (NULL, path, maxSize); 7556 GetModuleFileName (NULL, path, maxSize);
7516 strrchr (path, '\\')[1] = 0; 7557 char* ptr = strrchr (path, '\\');
7558 if (ptr)
7559 ptr[1] = 0;
7517 return path; 7560 return path;
7518} 7561}
7519 7562
@@ -7525,16 +7568,16 @@ char *GetConfigPath (char *fileName)
7525 if (IsNonInstallMode ()) 7568 if (IsNonInstallMode ())
7526 { 7569 {
7527 GetModPath (path, sizeof (path)); 7570 GetModPath (path, sizeof (path));
7528 strcat (path, fileName); 7571 StringCbCatA (path, (MAX_PATH * 2), fileName);
7529 7572
7530 return path; 7573 return path;
7531 } 7574 }
7532 7575
7533 if (SUCCEEDED(SHGetFolderPath (NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, path))) 7576 if (SUCCEEDED(SHGetFolderPath (NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, path)))
7534 { 7577 {
7535 strcat (path, "\\VeraCrypt\\"); 7578 StringCbCatA (path, (MAX_PATH * 2), "\\VeraCrypt\\");
7536 CreateDirectory (path, NULL); 7579 CreateDirectory (path, NULL);
7537 strcat (path, fileName); 7580 StringCbCatA (path, (MAX_PATH * 2), fileName);
7538 } 7581 }
7539 else 7582 else
7540 path[0] = 0; 7583 path[0] = 0;
@@ -7549,9 +7592,9 @@ char *GetProgramConfigPath (char *fileName)
7549 7592
7550 if (SUCCEEDED (SHGetFolderPath (NULL, CSIDL_COMMON_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, path))) 7593 if (SUCCEEDED (SHGetFolderPath (NULL, CSIDL_COMMON_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, path)))
7551 { 7594 {
7552 strcat (path, "\\VeraCrypt\\"); 7595 StringCbCatA (path, (MAX_PATH * 2), "\\VeraCrypt\\");
7553 CreateDirectory (path, NULL); 7596 CreateDirectory (path, NULL);
7554 strcat (path, fileName); 7597 StringCbCatA (path, (MAX_PATH * 2), fileName);
7555 } 7598 }
7556 else 7599 else
7557 path[0] = 0; 7600 path[0] = 0;
@@ -7613,8 +7656,8 @@ void TaskBarIconDisplayBalloonTooltip (HWND hwnd, wchar_t *headline, wchar_t *te
7613 tnid.dwInfoFlags = (warning ? NIIF_WARNING : NIIF_INFO); 7656 tnid.dwInfoFlags = (warning ? NIIF_WARNING : NIIF_INFO);
7614 tnid.uTimeout = (IsOSAtLeast (WIN_VISTA) ? 1000 : 5000); // in ms 7657 tnid.uTimeout = (IsOSAtLeast (WIN_VISTA) ? 1000 : 5000); // in ms
7615 7658
7616 wcsncpy (tnid.szInfoTitle, headline, ARRAYSIZE (tnid.szInfoTitle) - 1); 7659 StringCbCopyW (tnid.szInfoTitle, sizeof(tnid.szInfoTitle), headline);
7617 wcsncpy (tnid.szInfo, text, ARRAYSIZE (tnid.szInfo) - 1); 7660 StringCbCopyW (tnid.szInfo, sizeof(tnid.szInfo),text);
7618 7661
7619 // Display the balloon tooltip quickly twice in a row to avoid the slow and unwanted "fade-in" phase 7662 // Display the balloon tooltip quickly twice in a row to avoid the slow and unwanted "fade-in" phase
7620 Shell_NotifyIconW (NIM_MODIFY, &tnid); 7663 Shell_NotifyIconW (NIM_MODIFY, &tnid);
@@ -7953,7 +7996,7 @@ BOOL ConfigWriteString (char *configKey, char *configValue)
7953BOOL ConfigWriteInt (char *configKey, int configValue) 7996BOOL ConfigWriteInt (char *configKey, int configValue)
7954{ 7997{
7955 char val[32]; 7998 char val[32];
7956 sprintf (val, "%d", configValue); 7999 StringCbPrintfA (val, sizeof(val), "%d", configValue);
7957 return ConfigWriteString (configKey, val); 8000 return ConfigWriteString (configKey, val);
7958} 8001}
7959 8002
@@ -8062,17 +8105,26 @@ BOOL LoadDefaultKeyFilesParam (void)
8062 while (xml = XmlFindElement (xml, "keyfile")) 8105 while (xml = XmlFindElement (xml, "keyfile"))
8063 { 8106 {
8064 kf = (KeyFile *) malloc (sizeof (KeyFile)); 8107 kf = (KeyFile *) malloc (sizeof (KeyFile));
8065 8108 if (kf)
8066 if (XmlGetNodeText (xml, kf->FileName, sizeof (kf->FileName)) != NULL) 8109 {
8067 defaultKeyFilesParam.FirstKeyFile = KeyFileAdd (defaultKeyFilesParam.FirstKeyFile, kf); 8110 if (XmlGetNodeText (xml, kf->FileName, sizeof (kf->FileName)) != NULL)
8111 defaultKeyFilesParam.FirstKeyFile = KeyFileAdd (defaultKeyFilesParam.FirstKeyFile, kf);
8112 else
8113 free (kf);
8114 }
8068 else 8115 else
8069 free (kf); 8116 {
8117 KeyFileRemoveAll (&defaultKeyFilesParam.FirstKeyFile);
8118 status = FALSE;
8119 break;
8120 }
8070 8121
8071 xml++; 8122 xml++;
8072 } 8123 }
8073 8124
8074 free (defaultKeyfilesFile); 8125 free (defaultKeyfilesFile);
8075 KeyFilesEnable = defaultKeyFilesParam.EnableKeyFiles; 8126 if (status)
8127 KeyFilesEnable = defaultKeyFilesParam.EnableKeyFiles;
8076 8128
8077 return status; 8129 return status;
8078} 8130}
@@ -8086,7 +8138,7 @@ void Debug (char *format, ...)
8086 va_list val; 8138 va_list val;
8087 8139
8088 va_start(val, format); 8140 va_start(val, format);
8089 _vsnprintf (buf, sizeof (buf), format, val); 8141 StringCbVPrintfA (buf, sizeof (buf), format, val);
8090 va_end(val); 8142 va_end(val);
8091 8143
8092 OutputDebugString (buf); 8144 OutputDebugString (buf);
@@ -8099,7 +8151,7 @@ void DebugMsgBox (char *format, ...)
8099 va_list val; 8151 va_list val;
8100 8152
8101 va_start(val, format); 8153 va_start(val, format);
8102 _vsnprintf (buf, sizeof (buf), format, val); 8154 StringCbVPrintfA (buf, sizeof (buf), format, val);
8103 va_end(val); 8155 va_end(val);
8104 8156
8105 MessageBox (MainDlg, buf, "VeraCrypt debug", 0); 8157 MessageBox (MainDlg, buf, "VeraCrypt debug", 0);
@@ -8352,7 +8404,18 @@ void Applink (char *dest, BOOL bSendOS, char *extraOutput)
8352 ArrowWaitCursor (); 8404 ArrowWaitCursor ();
8353 8405
8354 // sprintf_s (url, sizeof (url), TC_APPLINK "%s%s&dest=%s", bSendOS ? ("&os=" + GetWindowsEdition()).c_str() : "", extraOutput, dest); 8406 // sprintf_s (url, sizeof (url), TC_APPLINK "%s%s&dest=%s", bSendOS ? ("&os=" + GetWindowsEdition()).c_str() : "", extraOutput, dest);
8355 sprintf_s (url, sizeof (url),"%s", "https://sourceforge.net/projects/veracrypt/"); 8407 if (strcmp(dest, "donate") == 0)
8408 {
8409 StringCbPrintfA (url, sizeof (url),"%s", "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=PWT5LHZWANHY6");
8410 }
8411 else if (strcmp(dest,"localizations") == 0)
8412 {
8413 StringCbPrintfA (url, sizeof (url),"http://sourceforge.net/projects/veracrypt/files/VeraCrypt%%20%s/VeraCrypt_%s_Language_Files.zip/download", VERSION_STRING, VERSION_STRING);
8414 }
8415 else
8416 {
8417 StringCbPrintfA (url, sizeof (url),"%s", "https://sourceforge.net/projects/veracrypt/");
8418 }
8356 ShellExecute (NULL, "open", url, NULL, NULL, SW_SHOWNORMAL); 8419 ShellExecute (NULL, "open", url, NULL, NULL, SW_SHOWNORMAL);
8357 8420
8358 Sleep (200); 8421 Sleep (200);
@@ -8370,10 +8433,10 @@ char *RelativePath2Absolute (char *szFileName)
8370 GetCurrentDirectory (MAX_PATH, path); 8433 GetCurrentDirectory (MAX_PATH, path);
8371 8434
8372 if (path[strlen (path) - 1] != '\\') 8435 if (path[strlen (path) - 1] != '\\')
8373 strcat (path, "\\"); 8436 StringCbCatA (path, (MAX_PATH * 2), "\\");
8374 8437
8375 strcat (path, szFileName); 8438 StringCbCatA (path, (MAX_PATH * 2), szFileName);
8376 strncpy (szFileName, path, MAX_PATH-1); 8439 StringCbCopyA (szFileName, MAX_PATH + 1, path); // szFileName size is always at least (MAX_PATH + 1)
8377 } 8440 }
8378 8441
8379 return szFileName; 8442 return szFileName;
@@ -8463,7 +8526,7 @@ void InconsistencyResolved (char *techInfo)
8463{ 8526{
8464 wchar_t finalMsg[8024]; 8527 wchar_t finalMsg[8024];
8465 8528
8466 wsprintfW (finalMsg, GetString ("INCONSISTENCY_RESOLVED"), techInfo); 8529 StringCbPrintfW (finalMsg, sizeof(finalMsg), GetString ("INCONSISTENCY_RESOLVED"), techInfo);
8467 MessageBoxW (MainDlg, finalMsg, lpszTitle, MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST); 8530 MessageBoxW (MainDlg, finalMsg, lpszTitle, MB_ICONWARNING | MB_SETFOREGROUND | MB_TOPMOST);
8468} 8531}
8469 8532
@@ -8472,7 +8535,7 @@ void ReportUnexpectedState (char *techInfo)
8472{ 8535{
8473 wchar_t finalMsg[8024]; 8536 wchar_t finalMsg[8024];
8474 8537
8475 wsprintfW (finalMsg, GetString ("UNEXPECTED_STATE"), techInfo); 8538 StringCbPrintfW (finalMsg, sizeof(finalMsg), GetString ("UNEXPECTED_STATE"), techInfo);
8476 MessageBoxW (MainDlg, finalMsg, lpszTitle, MB_ICONERROR | MB_SETFOREGROUND | MB_TOPMOST); 8539 MessageBoxW (MainDlg, finalMsg, lpszTitle, MB_ICONERROR | MB_SETFOREGROUND | MB_TOPMOST);
8477} 8540}
8478 8541
@@ -8495,11 +8558,11 @@ int OpenVolume (OpenVolumeContext *context, const char *volumePath, Password *pa
8495 context->HostFileHandle = INVALID_HANDLE_VALUE; 8558 context->HostFileHandle = INVALID_HANDLE_VALUE;
8496 context->TimestampsValid = FALSE; 8559 context->TimestampsValid = FALSE;
8497 8560
8498 CreateFullVolumePath (szDiskFile, volumePath, &context->IsDevice); 8561 CreateFullVolumePath (szDiskFile, sizeof(szDiskFile), volumePath, &context->IsDevice);
8499 8562
8500 if (context->IsDevice) 8563 if (context->IsDevice)
8501 { 8564 {
8502 status = FakeDosNameForDevice (szDiskFile, szDosDevice, szCFDevice, FALSE); 8565 status = FakeDosNameForDevice (szDiskFile, szDosDevice, sizeof(szDosDevice), szCFDevice, sizeof(szCFDevice), FALSE);
8503 if (status != 0) 8566 if (status != 0)
8504 return status; 8567 return status;
8505 8568
@@ -8512,7 +8575,7 @@ int OpenVolume (OpenVolumeContext *context, const char *volumePath, Password *pa
8512 } 8575 }
8513 } 8576 }
8514 else 8577 else
8515 strcpy (szCFDevice, szDiskFile); 8578 StringCbCopyA (szCFDevice, sizeof(szCFDevice), szDiskFile);
8516 8579
8517 if (preserveTimestamps) 8580 if (preserveTimestamps)
8518 write = TRUE; 8581 write = TRUE;
@@ -8888,7 +8951,7 @@ BOOL CALLBACK SecurityTokenPasswordDlgProc (HWND hwndDlg, UINT msg, WPARAM wPara
8888 LocalizeDialog (hwndDlg, "IDD_TOKEN_PASSWORD"); 8951 LocalizeDialog (hwndDlg, "IDD_TOKEN_PASSWORD");
8889 8952
8890 wchar_t s[1024]; 8953 wchar_t s[1024];
8891 wsprintfW (s, GetString ("ENTER_TOKEN_PASSWORD"), Utf8StringToWide (password->c_str()).c_str()); 8954 StringCbPrintfW (s, sizeof(s), GetString ("ENTER_TOKEN_PASSWORD"), Utf8StringToWide (password->c_str()).c_str());
8892 SetWindowTextW (GetDlgItem (hwndDlg, IDT_TOKEN_PASSWORD_INFO), s); 8955 SetWindowTextW (GetDlgItem (hwndDlg, IDT_TOKEN_PASSWORD_INFO), s);
8893 8956
8894 SendMessage (GetDlgItem (hwndDlg, IDC_TOKEN_PASSWORD), EM_LIMITTEXT, SecurityToken::MaxPasswordLength, 0); 8957 SendMessage (GetDlgItem (hwndDlg, IDC_TOKEN_PASSWORD), EM_LIMITTEXT, SecurityToken::MaxPasswordLength, 0);
@@ -9537,15 +9600,15 @@ void CheckFilesystem (int driveNo, BOOL fixErrors)
9537 if (fixErrors && AskWarnYesNo ("FILESYS_REPAIR_CONFIRM_BACKUP") == IDNO) 9600 if (fixErrors && AskWarnYesNo ("FILESYS_REPAIR_CONFIRM_BACKUP") == IDNO)
9538 return; 9601 return;
9539 9602
9540 wsprintfW (msg, GetString (fixErrors ? "REPAIRING_FS" : "CHECKING_FS"), driveRoot); 9603 StringCbPrintfW (msg, sizeof(msg), GetString (fixErrors ? "REPAIRING_FS" : "CHECKING_FS"), driveRoot);
9541 wsprintfW (param, fixErrors ? L"/C echo %s & chkdsk %hs /F /X & pause" : L"/C echo %s & chkdsk %hs & pause", msg, driveRoot); 9604 StringCbPrintfW (param, sizeof(param), fixErrors ? L"/C echo %s & chkdsk %hs /F /X & pause" : L"/C echo %s & chkdsk %hs & pause", msg, driveRoot);
9542 9605
9543 if (GetSystemDirectoryW(cmdPath, MAX_PATH)) 9606 if (GetSystemDirectoryW(cmdPath, MAX_PATH))
9544 { 9607 {
9545 lstrcatW(cmdPath, L"\\cmd.exe"); 9608 StringCbCatW(cmdPath, sizeof(cmdPath), L"\\cmd.exe");
9546 } 9609 }
9547 else 9610 else
9548 lstrcpyW(cmdPath, L"C:\\Windows\\System32\\cmd.exe"); 9611 StringCbCopyW(cmdPath, sizeof(cmdPath), L"C:\\Windows\\System32\\cmd.exe");
9549 9612
9550 ShellExecuteW (NULL, (!IsAdmin() && IsUacSupported()) ? L"runas" : L"open", cmdPath, param, NULL, SW_SHOW); 9613 ShellExecuteW (NULL, (!IsAdmin() && IsUacSupported()) ? L"runas" : L"open", cmdPath, param, NULL, SW_SHOW);
9551} 9614}
@@ -9612,8 +9675,8 @@ BOOL RemoveDeviceWriteProtection (HWND hwndDlg, char *devicePath)
9612 if (GetTempPath (sizeof (temp), temp) == 0) 9675 if (GetTempPath (sizeof (temp), temp) == 0)
9613 return FALSE; 9676 return FALSE;
9614 9677
9615 _snprintf (cmdBatch, sizeof (cmdBatch), "%s\\VeraCrypt_Write_Protection_Removal.cmd", temp); 9678 StringCbPrintfA (cmdBatch, sizeof (cmdBatch), "%s\\VeraCrypt_Write_Protection_Removal.cmd", temp);
9616 _snprintf (diskpartScript, sizeof (diskpartScript), "%s\\VeraCrypt_Write_Protection_Removal.diskpart", temp); 9679 StringCbPrintfA (diskpartScript, sizeof (diskpartScript), "%s\\VeraCrypt_Write_Protection_Removal.diskpart", temp);
9617 9680
9618 FILE *f = fopen (cmdBatch, "w"); 9681 FILE *f = fopen (cmdBatch, "w");
9619 if (!f) 9682 if (!f)
@@ -9674,10 +9737,13 @@ void EnableElevatedCursorChange (HWND parent)
9674 RegisterClassEx (&winClass); 9737 RegisterClassEx (&winClass);
9675 9738
9676 hWnd = CreateWindowEx (WS_EX_TOOLWINDOW | WS_EX_LAYERED, className, "VeraCrypt UAC", 0, 0, 0, GetSystemMetrics (SM_CXSCREEN), GetSystemMetrics (SM_CYSCREEN), parent, NULL, hInst, NULL); 9739 hWnd = CreateWindowEx (WS_EX_TOOLWINDOW | WS_EX_LAYERED, className, "VeraCrypt UAC", 0, 0, 0, GetSystemMetrics (SM_CXSCREEN), GetSystemMetrics (SM_CYSCREEN), parent, NULL, hInst, NULL);
9677 SetLayeredWindowAttributes (hWnd, 0, 1, LWA_ALPHA); 9740 if (hWnd)
9678 ShowWindow (hWnd, SW_SHOWNORMAL); 9741 {
9742 SetLayeredWindowAttributes (hWnd, 0, 1, LWA_ALPHA);
9743 ShowWindow (hWnd, SW_SHOWNORMAL);
9679 9744
9680 DestroyWindow (hWnd); 9745 DestroyWindow (hWnd);
9746 }
9681 UnregisterClass (className, hInst); 9747 UnregisterClass (className, hInst);
9682 } 9748 }
9683} 9749}
@@ -9699,12 +9765,12 @@ BOOL DisableFileCompression (HANDLE file)
9699} 9765}
9700 9766
9701 9767
9702BOOL VolumePathExists (char *volumePath) 9768BOOL VolumePathExists (const char *volumePath)
9703{ 9769{
9704 OPEN_TEST_STRUCT openTest; 9770 OPEN_TEST_STRUCT openTest;
9705 char upperCasePath[TC_MAX_PATH]; 9771 char upperCasePath[TC_MAX_PATH + 1];
9706 9772
9707 UpperCaseCopy (upperCasePath, volumePath); 9773 UpperCaseCopy (upperCasePath, sizeof(upperCasePath), volumePath);
9708 9774
9709 if (strstr (upperCasePath, "\\DEVICE\\") == upperCasePath) 9775 if (strstr (upperCasePath, "\\DEVICE\\") == upperCasePath)
9710 return OpenDevice (volumePath, &openTest, FALSE); 9776 return OpenDevice (volumePath, &openTest, FALSE);
@@ -9732,7 +9798,7 @@ BOOL IsWindowsIsoBurnerAvailable ()
9732 9798
9733 if (SUCCEEDED(SHGetFolderPath (NULL, CSIDL_SYSTEM, NULL, 0, path))) 9799 if (SUCCEEDED(SHGetFolderPath (NULL, CSIDL_SYSTEM, NULL, 0, path)))
9734 { 9800 {
9735 strcat (path, "\\" ISO_BURNER_TOOL); 9801 StringCbCatA (path, MAX_PATH*2, "\\" ISO_BURNER_TOOL);
9736 9802
9737 return (FileExists (path)); 9803 return (FileExists (path));
9738 } 9804 }
@@ -9747,9 +9813,9 @@ BOOL LaunchWindowsIsoBurner (HWND hwnd, const char *isoPath)
9747 int r; 9813 int r;
9748 9814
9749 if (SUCCEEDED(SHGetFolderPath (NULL, CSIDL_SYSTEM, NULL, 0, path))) 9815 if (SUCCEEDED(SHGetFolderPath (NULL, CSIDL_SYSTEM, NULL, 0, path)))
9750 strcat (path, "\\" ISO_BURNER_TOOL); 9816 StringCbCatA (path, MAX_PATH*2, "\\" ISO_BURNER_TOOL);
9751 else 9817 else
9752 strcpy (path, "C:\\Windows\\System32\\" ISO_BURNER_TOOL); 9818 StringCbCopyA (path, MAX_PATH*2, "C:\\Windows\\System32\\" ISO_BURNER_TOOL);
9753 9819
9754 r = (int) ShellExecute (hwnd, "open", path, (string ("\"") + isoPath + "\"").c_str(), NULL, SW_SHOWNORMAL); 9820 r = (int) ShellExecute (hwnd, "open", path, (string ("\"") + isoPath + "\"").c_str(), NULL, SW_SHOWNORMAL);
9755 9821
@@ -9795,7 +9861,7 @@ std::string HarddiskVolumePathToPartitionPath (const std::string &harddiskVolume
9795 swprintf_s (partitionPath, ARRAYSIZE (partitionPath), L"\\Device\\Harddisk%d\\Partition%d", driveNumber, partNumber); 9861 swprintf_s (partitionPath, ARRAYSIZE (partitionPath), L"\\Device\\Harddisk%d\\Partition%d", driveNumber, partNumber);
9796 9862
9797 wchar_t resolvedPath[TC_MAX_PATH]; 9863 wchar_t resolvedPath[TC_MAX_PATH];
9798 if (ResolveSymbolicLink (partitionPath, resolvedPath)) 9864 if (ResolveSymbolicLink (partitionPath, resolvedPath, sizeof(resolvedPath)))
9799 { 9865 {
9800 if (volPath == resolvedPath) 9866 if (volPath == resolvedPath)
9801 return WideToSingleString (partitionPath); 9867 return WideToSingleString (partitionPath);
diff --git a/src/Common/Dlgcode.h b/src/Common/Dlgcode.h
index 588fea41..11686f89 100644
--- a/src/Common/Dlgcode.h
+++ b/src/Common/Dlgcode.h
@@ -222,9 +222,9 @@ typedef struct
222 222
223void cleanup ( void ); 223void cleanup ( void );
224void LowerCaseCopy ( char *lpszDest , const char *lpszSource ); 224void LowerCaseCopy ( char *lpszDest , const char *lpszSource );
225void UpperCaseCopy ( char *lpszDest , const char *lpszSource ); 225void UpperCaseCopy ( char *lpszDest , size_t cbDest, const char *lpszSource );
226void CreateFullVolumePath ( char *lpszDiskFile , const char *lpszFileName , BOOL *bDevice ); 226void CreateFullVolumePath ( char *lpszDiskFile , size_t cbDiskFile, const char *lpszFileName , BOOL *bDevice );
227int FakeDosNameForDevice ( const char *lpszDiskFile , char *lpszDosDevice , char *lpszCFDevice , BOOL bNameOnly ); 227int FakeDosNameForDevice ( const char *lpszDiskFile , char *lpszDosDevice , size_t cbDosDevice, char *lpszCFDevice , size_t cbCFDevice, BOOL bNameOnly );
228int RemoveFakeDosName ( char *lpszDiskFile , char *lpszDosDevice ); 228int RemoveFakeDosName ( char *lpszDiskFile , char *lpszDosDevice );
229void AbortProcess ( char *stringId ); 229void AbortProcess ( char *stringId );
230void AbortProcessSilent ( void ); 230void AbortProcessSilent ( void );
@@ -242,8 +242,8 @@ void CloseStaticModelessWaitDlg (void);
242BOOL IsButtonChecked ( HWND hButton ); 242BOOL IsButtonChecked ( HWND hButton );
243void CheckButton ( HWND hButton ); 243void CheckButton ( HWND hButton );
244void LeftPadString (char *szTmp, int len, int targetLen, char filler); 244void LeftPadString (char *szTmp, int len, int targetLen, char filler);
245void ToSBCS ( LPWSTR lpszText ); 245void ToSBCS ( LPWSTR lpszText, size_t cbSize );
246void ToUNICODE ( char *lpszText ); 246void ToUNICODE ( char *lpszText , size_t cbSize);
247void InitDialog ( HWND hwndDlg ); 247void InitDialog ( HWND hwndDlg );
248void ProcessPaintMessages (HWND hwnd, int maxMessagesToProcess); 248void ProcessPaintMessages (HWND hwnd, int maxMessagesToProcess);
249HDC CreateMemBitmap ( HINSTANCE hInstance , HWND hwnd , char *resource ); 249HDC CreateMemBitmap ( HINSTANCE hInstance , HWND hwnd , char *resource );
@@ -293,7 +293,7 @@ BOOL OpenDevice (const char *lpszPath, OPEN_TEST_STRUCT *driver, BOOL detectFile
293void NotifyDriverOfPortableMode (void); 293void NotifyDriverOfPortableMode (void);
294int GetAvailableFixedDisks ( HWND hComboBox , char *lpszRootPath ); 294int GetAvailableFixedDisks ( HWND hComboBox , char *lpszRootPath );
295int GetAvailableRemovables ( HWND hComboBox , char *lpszRootPath ); 295int GetAvailableRemovables ( HWND hComboBox , char *lpszRootPath );
296int IsSystemDevicePath (char *path, HWND hwndDlg, BOOL bReliableRequired); 296int IsSystemDevicePath (const char *path, HWND hwndDlg, BOOL bReliableRequired);
297BOOL CALLBACK RawDevicesDlgProc ( HWND hwndDlg , UINT msg , WPARAM wParam , LPARAM lParam ); 297BOOL CALLBACK RawDevicesDlgProc ( HWND hwndDlg , UINT msg , WPARAM wParam , LPARAM lParam );
298BOOL TextInfoDialogBox (int nID); 298BOOL TextInfoDialogBox (int nID);
299BOOL CALLBACK TextInfoDialogBoxDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); 299BOOL CALLBACK TextInfoDialogBoxDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
@@ -333,7 +333,7 @@ int GetMountedVolumeDriveNo (char *volname);
333BOOL IsAdmin (void); 333BOOL IsAdmin (void);
334BOOL IsBuiltInAdmin (); 334BOOL IsBuiltInAdmin ();
335BOOL IsUacSupported (); 335BOOL IsUacSupported ();
336BOOL ResolveSymbolicLink (const wchar_t *symLinkName, PWSTR targetName); 336BOOL ResolveSymbolicLink (const wchar_t *symLinkName, PWSTR targetName, size_t cbTargetName);
337int GetDiskDeviceDriveLetter (PWSTR deviceName); 337int GetDiskDeviceDriveLetter (PWSTR deviceName);
338int FileSystemAppearsEmpty (const char *devicePath); 338int FileSystemAppearsEmpty (const char *devicePath);
339__int64 GetStatsFreeSpaceOnPartition (const char *devicePath, float *percent, __int64 *occupiedBytes, BOOL silent); 339__int64 GetStatsFreeSpaceOnPartition (const char *devicePath, float *percent, __int64 *occupiedBytes, BOOL silent);
@@ -346,7 +346,7 @@ BOOL TCCopyFile (char *sourceFileName, char *destinationFile);
346BOOL SaveBufferToFile (const char *inputBuffer, const char *destinationFile, DWORD inputLength, BOOL bAppend); 346BOOL SaveBufferToFile (const char *inputBuffer, const char *destinationFile, DWORD inputLength, BOOL bAppend);
347BOOL TCFlushFile (FILE *f); 347BOOL TCFlushFile (FILE *f);
348BOOL PrintHardCopyTextUTF16 (wchar_t *text, char *title, int byteLen); 348BOOL PrintHardCopyTextUTF16 (wchar_t *text, char *title, int byteLen);
349void GetSpeedString (unsigned __int64 speed, wchar_t *str); 349void GetSpeedString (unsigned __int64 speed, wchar_t *str, size_t cbStr);
350BOOL IsNonInstallMode (); 350BOOL IsNonInstallMode ();
351BOOL DriverUnload (); 351BOOL DriverUnload ();
352LRESULT SetCheckBox (HWND hwndDlg, int dlgItem, BOOL state); 352LRESULT SetCheckBox (HWND hwndDlg, int dlgItem, BOOL state);
@@ -362,7 +362,7 @@ LRESULT ListSubItemSet (HWND list, int index, int subIndex, char *string);
362LRESULT ListSubItemSetW (HWND list, int index, int subIndex, wchar_t *string); 362LRESULT ListSubItemSetW (HWND list, int index, int subIndex, wchar_t *string);
363BOOL GetMountList (MOUNT_LIST_STRUCT *list); 363BOOL GetMountList (MOUNT_LIST_STRUCT *list);
364int GetDriverRefCount (); 364int GetDriverRefCount ();
365void GetSizeString (unsigned __int64 size, wchar_t *str); 365void GetSizeString (unsigned __int64 size, wchar_t *str, size_t cbStr);
366__int64 GetFileSize64 (const char *path); 366__int64 GetFileSize64 (const char *path);
367BOOL LoadInt16 (char *filePath, int *result, __int64 fileOffset); 367BOOL LoadInt16 (char *filePath, int *result, __int64 fileOffset);
368BOOL LoadInt32 (char *filePath, unsigned __int32 *result, __int64 fileOffset); 368BOOL LoadInt32 (char *filePath, unsigned __int32 *result, __int64 fileOffset);
@@ -429,8 +429,8 @@ BOOL CALLBACK FindTCWindowEnum (HWND hwnd, LPARAM lParam);
429BYTE *MapResource (char *resourceType, int resourceId, PDWORD size); 429BYTE *MapResource (char *resourceType, int resourceId, PDWORD size);
430void InconsistencyResolved (char *msg); 430void InconsistencyResolved (char *msg);
431void ReportUnexpectedState (char *techInfo); 431void ReportUnexpectedState (char *techInfo);
432BOOL SelectMultipleFiles (HWND hwndDlg, char *stringId, char *lpszFileName, BOOL keepHistory); 432BOOL SelectMultipleFiles (HWND hwndDlg, const char *stringId, char *lpszFileName, size_t cbFileName, BOOL keepHistory);
433BOOL SelectMultipleFilesNext (char *lpszFileName); 433BOOL SelectMultipleFilesNext (char *lpszFileName, size_t cbFileName);
434void OpenOnlineHelp (); 434void OpenOnlineHelp ();
435BOOL GetPartitionInfo (const char *deviceName, PPARTITION_INFORMATION rpartInfo); 435BOOL GetPartitionInfo (const char *deviceName, PPARTITION_INFORMATION rpartInfo);
436BOOL GetDeviceInfo (const char *deviceName, DISK_PARTITION_INFO_STRUCT *info); 436BOOL GetDeviceInfo (const char *deviceName, DISK_PARTITION_INFO_STRUCT *info);
@@ -464,7 +464,7 @@ int AskNonSysInPlaceEncryptionResume ();
464BOOL RemoveDeviceWriteProtection (HWND hwndDlg, char *devicePath); 464BOOL RemoveDeviceWriteProtection (HWND hwndDlg, char *devicePath);
465void EnableElevatedCursorChange (HWND parent); 465void EnableElevatedCursorChange (HWND parent);
466BOOL DisableFileCompression (HANDLE file); 466BOOL DisableFileCompression (HANDLE file);
467BOOL VolumePathExists (char *volumePath); 467BOOL VolumePathExists (const char *volumePath);
468BOOL IsWindowsIsoBurnerAvailable (); 468BOOL IsWindowsIsoBurnerAvailable ();
469BOOL LaunchWindowsIsoBurner (HWND hwnd, const char *isoPath); 469BOOL LaunchWindowsIsoBurner (HWND hwnd, const char *isoPath);
470BOOL IsApplicationInstalled (const char *appName); 470BOOL IsApplicationInstalled (const char *appName);