diff options
Diffstat (limited to 'src/Common/Language.c')
-rw-r--r-- | src/Common/Language.c | 50 |
1 files changed, 34 insertions, 16 deletions
diff --git a/src/Common/Language.c b/src/Common/Language.c index b146f820..3ec95dba 100644 --- a/src/Common/Language.c +++ b/src/Common/Language.c | |||
@@ -26,6 +26,8 @@ | |||
26 | #include "../Setup/Resource.h" | 26 | #include "../Setup/Resource.h" |
27 | #endif | 27 | #endif |
28 | 28 | ||
29 | #include <Strsafe.h> | ||
30 | |||
29 | BOOL LocalizationActive; | 31 | BOOL LocalizationActive; |
30 | int LocalizationSerialNo; | 32 | int LocalizationSerialNo; |
31 | 33 | ||
@@ -68,8 +70,9 @@ static char *MapNextLanguageFile () | |||
68 | GetModuleFileNameW (NULL, f, sizeof (f) / sizeof (f[0])); | 70 | GetModuleFileNameW (NULL, f, sizeof (f) / sizeof (f[0])); |
69 | t = wcsrchr (f, L'\\'); | 71 | t = wcsrchr (f, L'\\'); |
70 | if (t == NULL) return NULL; | 72 | if (t == NULL) return NULL; |
71 | 73 | ||
72 | wcscpy (t, L"\\Language*.xml"); | 74 | *t = 0; |
75 | StringCbCatW (f, sizeof(f), L"\\Language*.xml"); | ||
73 | 76 | ||
74 | LanguageFileFindHandle = FindFirstFileW (f, &find); | 77 | LanguageFileFindHandle = FindFirstFileW (f, &find); |
75 | } | 78 | } |
@@ -88,14 +91,29 @@ static char *MapNextLanguageFile () | |||
88 | 91 | ||
89 | GetModuleFileNameW (NULL, f, sizeof (f) / sizeof(f[0])); | 92 | GetModuleFileNameW (NULL, f, sizeof (f) / sizeof(f[0])); |
90 | t = wcsrchr (f, L'\\'); | 93 | t = wcsrchr (f, L'\\'); |
91 | wcscpy (t + 1, find.cFileName); | 94 | if (t == NULL) |
95 | { | ||
96 | free(LanguageFileBuffer); | ||
97 | return NULL; | ||
98 | } | ||
99 | |||
100 | t[1] = 0; | ||
101 | StringCbCatW (f, sizeof(f),find.cFileName); | ||
92 | 102 | ||
93 | file = CreateFileW (f, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); | 103 | file = CreateFileW (f, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); |
94 | if (file == INVALID_HANDLE_VALUE) return NULL; | 104 | if (file == INVALID_HANDLE_VALUE) |
105 | { | ||
106 | free(LanguageFileBuffer); | ||
107 | return NULL; | ||
108 | } | ||
95 | 109 | ||
96 | ReadFile (file, LanguageFileBuffer, find.nFileSizeLow, &read, NULL); | 110 | ReadFile (file, LanguageFileBuffer, find.nFileSizeLow, &read, NULL); |
97 | CloseHandle (file); | 111 | CloseHandle (file); |
98 | if (read != find.nFileSizeLow) return NULL; | 112 | if (read != find.nFileSizeLow) |
113 | { | ||
114 | free(LanguageFileBuffer); | ||
115 | return NULL; | ||
116 | } | ||
99 | 117 | ||
100 | return LanguageFileBuffer; | 118 | return LanguageFileBuffer; |
101 | } | 119 | } |
@@ -130,7 +148,7 @@ BOOL LoadLanguageFile () | |||
130 | ClearDictionaryPool (); | 148 | ClearDictionaryPool (); |
131 | 149 | ||
132 | if (PreferredLangId[0] != 0) | 150 | if (PreferredLangId[0] != 0) |
133 | strcpy (langId, PreferredLangId); | 151 | StringCbCopyA (langId, sizeof(langId), PreferredLangId); |
134 | 152 | ||
135 | // Parse all available language files until preferred language is found | 153 | // Parse all available language files until preferred language is found |
136 | for (res = MapFirstLanguageFile (); res != NULL; res = MapNextLanguageFile ()) | 154 | for (res = MapFirstLanguageFile (); res != NULL; res = MapNextLanguageFile ()) |
@@ -147,7 +165,7 @@ BOOL LoadLanguageFile () | |||
147 | if (defaultLangParsed && strcmp (attr, VERSION_STRING) && strcmp (attr, "DEBUG")) | 165 | if (defaultLangParsed && strcmp (attr, VERSION_STRING) && strcmp (attr, "DEBUG")) |
148 | { | 166 | { |
149 | wchar_t m[2048]; | 167 | wchar_t m[2048]; |
150 | swprintf (m, L"The installed language pack is incompatible with this version of VeraCrypt (the language pack is for VeraCrypt %hs). A newer version may be available at www.idrix.fr.\n\nTo prevent this message from being displayed, do any of the following:\n\n- Select 'Settings' > 'Language'; then select 'English' and click 'OK'.\n\n- Remove or replace the language pack with a compatible version (the language pack may reside e.g. in 'C:\\Program Files\\VeraCrypt' or '%%LOCALAPPDATA%%\\VirtualStore\\Program Files\\VeraCrypt', etc.)", attr); | 168 | StringCbPrintfW (m, sizeof(m), L"The installed language pack is incompatible with this version of VeraCrypt (the language pack is for VeraCrypt %hs). A newer version may be available at www.idrix.fr.\n\nTo prevent this message from being displayed, do any of the following:\n\n- Select 'Settings' > 'Language'; then select 'English' and click 'OK'.\n\n- Remove or replace the language pack with a compatible version (the language pack may reside e.g. in 'C:\\Program Files\\VeraCrypt' or '%%LOCALAPPDATA%%\\VirtualStore\\Program Files\\VeraCrypt', etc.)", attr); |
151 | MessageBoxW (NULL, m, L"VeraCrypt", MB_ICONERROR); | 169 | MessageBoxW (NULL, m, L"VeraCrypt", MB_ICONERROR); |
152 | continue; | 170 | continue; |
153 | } | 171 | } |
@@ -189,7 +207,7 @@ BOOL LoadLanguageFile () | |||
189 | XmlGetAttributeText (xml, "size", attr, sizeof (attr)); | 207 | XmlGetAttributeText (xml, "size", attr, sizeof (attr)); |
190 | sscanf (attr, "%d", &font.Size); | 208 | sscanf (attr, "%d", &font.Size); |
191 | 209 | ||
192 | strcpy (attr, "font_"); | 210 | StringCbCopyA (attr, sizeof(attr), "font_"); |
193 | XmlGetAttributeText (xml, "class", attr + 5, sizeof (attr) - 5); | 211 | XmlGetAttributeText (xml, "class", attr + 5, sizeof (attr) - 5); |
194 | AddDictionaryEntry ( | 212 | AddDictionaryEntry ( |
195 | AddPoolData ((void *) attr, strlen (attr) + 1), 0, | 213 | AddPoolData ((void *) attr, strlen (attr) + 1), 0, |
@@ -375,13 +393,13 @@ BOOL CALLBACK LanguageDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa | |||
375 | // Language pack version | 393 | // Language pack version |
376 | if (!ActiveLangPackVersion[0] || memcmp (ActiveLangPackVersion, "0.0.0", 5) == 0) | 394 | if (!ActiveLangPackVersion[0] || memcmp (ActiveLangPackVersion, "0.0.0", 5) == 0) |
377 | { | 395 | { |
378 | swprintf (szVers, GetString("LANG_PACK_VERSION"), L"--"); | 396 | StringCbPrintfW (szVers, sizeof(szVers), GetString("LANG_PACK_VERSION"), L"--"); |
379 | } | 397 | } |
380 | else | 398 | else |
381 | { | 399 | { |
382 | nLen = MultiByteToWideChar (CP_UTF8, 0, ActiveLangPackVersion, -1, wversion, sizeof (wversion) / sizeof(wversion[0])); | 400 | nLen = MultiByteToWideChar (CP_UTF8, 0, ActiveLangPackVersion, -1, wversion, sizeof (wversion) / sizeof(wversion[0])); |
383 | if (nLen != 0 && nLen != ERROR_NO_UNICODE_TRANSLATION) | 401 | if (nLen != 0 && nLen != ERROR_NO_UNICODE_TRANSLATION) |
384 | swprintf (szVers, GetString("LANG_PACK_VERSION"), wversion); | 402 | StringCbPrintfW (szVers, sizeof(szVers),GetString("LANG_PACK_VERSION"), wversion); |
385 | } | 403 | } |
386 | SetWindowTextW (GetDlgItem (hwndDlg, IDC_LANGPACK_VERSION), szVers); | 404 | SetWindowTextW (GetDlgItem (hwndDlg, IDC_LANGPACK_VERSION), szVers); |
387 | 405 | ||
@@ -394,7 +412,7 @@ BOOL CALLBACK LanguageDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa | |||
394 | } | 412 | } |
395 | } | 413 | } |
396 | 414 | ||
397 | strcpy (lastLangId, attr); | 415 | StringCbCopyA (lastLangId, sizeof(lastLangId),attr); |
398 | langCount++; | 416 | langCount++; |
399 | } | 417 | } |
400 | } | 418 | } |
@@ -410,7 +428,7 @@ BOOL CALLBACK LanguageDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa | |||
410 | EndDialog (hwndDlg, IDCANCEL); | 428 | EndDialog (hwndDlg, IDCANCEL); |
411 | 429 | ||
412 | if (langCount == 2) | 430 | if (langCount == 2) |
413 | strcpy (PreferredLangId, lastLangId); | 431 | StringCbCopyA (PreferredLangId, sizeof(PreferredLangId), lastLangId); |
414 | 432 | ||
415 | EndDialog (hwndDlg, IDOK); | 433 | EndDialog (hwndDlg, IDOK); |
416 | } | 434 | } |
@@ -446,7 +464,7 @@ BOOL CALLBACK LanguageDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa | |||
446 | } | 464 | } |
447 | 465 | ||
448 | if (SendDlgItemMessage (hwndDlg, IDC_LANGLIST, LB_GETCOUNT, 0, 0) > 1) | 466 | if (SendDlgItemMessage (hwndDlg, IDC_LANGLIST, LB_GETCOUNT, 0, 0) > 1) |
449 | strcpy (PreferredLangId, l); | 467 | StringCbCopyA (PreferredLangId, sizeof(PreferredLangId), l); |
450 | } | 468 | } |
451 | } | 469 | } |
452 | 470 | ||
@@ -465,7 +483,7 @@ BOOL CALLBACK LanguageDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPa | |||
465 | char tmpstr [256]; | 483 | char tmpstr [256]; |
466 | 484 | ||
467 | if (strlen (ActiveLangPackVersion) > 0 && strlen (GetPreferredLangId()) > 0) | 485 | if (strlen (ActiveLangPackVersion) > 0 && strlen (GetPreferredLangId()) > 0) |
468 | sprintf (tmpstr, "&langpackversion=%s&lang=%s", ActiveLangPackVersion, GetPreferredLangId()); | 486 | StringCbPrintfA (tmpstr, sizeof(tmpstr), "&langpackversion=%s&lang=%s", ActiveLangPackVersion, GetPreferredLangId()); |
469 | else | 487 | else |
470 | tmpstr[0] = 0; | 488 | tmpstr[0] = 0; |
471 | 489 | ||
@@ -488,7 +506,7 @@ char *GetPreferredLangId () | |||
488 | 506 | ||
489 | void SetPreferredLangId (char *langId) | 507 | void SetPreferredLangId (char *langId) |
490 | { | 508 | { |
491 | strncpy (PreferredLangId, langId, 5); | 509 | StringCbCopyA (PreferredLangId, sizeof(PreferredLangId), langId); |
492 | } | 510 | } |
493 | 511 | ||
494 | 512 | ||
@@ -503,7 +521,7 @@ wchar_t *GetString (const char *stringId) | |||
503 | WCHAR *str = (WCHAR *) GetDictionaryValue (stringId); | 521 | WCHAR *str = (WCHAR *) GetDictionaryValue (stringId); |
504 | if (str != NULL) return str; | 522 | if (str != NULL) return str; |
505 | 523 | ||
506 | wsprintfW (UnknownString, UNKNOWN_STRING_ID L"%hs" UNKNOWN_STRING_ID, stringId); | 524 | StringCbPrintfW (UnknownString, sizeof(UnknownString), UNKNOWN_STRING_ID L"%hs" UNKNOWN_STRING_ID, stringId); |
507 | return UnknownString; | 525 | return UnknownString; |
508 | } | 526 | } |
509 | 527 | ||