VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Common/Dlgcode.c
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2015-11-26 00:34:30 +0100
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2015-11-26 01:44:54 +0100
commit59611b8b378238e5a589a87061d06fe4f337d1a0 (patch)
tree5d16a47f96e70cd7c581880193b48f73c38485bc /src/Common/Dlgcode.c
parent90bd57fe40e66fc829ecb01482d32d604b0df19c (diff)
downloadVeraCrypt-59611b8b378238e5a589a87061d06fe4f337d1a0.tar.gz
VeraCrypt-59611b8b378238e5a589a87061d06fe4f337d1a0.zip
Windows: solve crash caused by system function FormatMessage failure on rare cases.
Diffstat (limited to 'src/Common/Dlgcode.c')
-rw-r--r--src/Common/Dlgcode.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/Common/Dlgcode.c b/src/Common/Dlgcode.c
index 48dc1dd2..73957fec 100644
--- a/src/Common/Dlgcode.c
+++ b/src/Common/Dlgcode.c
@@ -570,6 +570,8 @@ DWORD handleWin32Error (HWND hwndDlg, const char* srcPos)
{
PWSTR lpMsgBuf;
DWORD dwError = GetLastError ();
+ wchar_t szErrorValue[32];
+ wchar_t* pszDesc;
if (Silent || dwError == 0 || dwError == ERROR_INVALID_WINDOW_HANDLE)
return dwError;
@@ -583,7 +585,7 @@ DWORD handleWin32Error (HWND hwndDlg, const char* srcPos)
}
FormatMessageW (
- FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
+ FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
dwError,
MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
@@ -592,8 +594,16 @@ DWORD handleWin32Error (HWND hwndDlg, const char* srcPos)
NULL
);
- MessageBoxW (hwndDlg, AppendSrcPos (lpMsgBuf, srcPos).c_str (), lpszTitle, ICON_HAND);
- LocalFree (lpMsgBuf);
+ if (lpMsgBuf)
+ pszDesc = (wchar_t*) lpMsgBuf;
+ else
+ {
+ StringCbPrintfW (szErrorValue, sizeof (szErrorValue), L"Error 0x%.8X", dwError);
+ pszDesc = szErrorValue;
+ }
+
+ MessageBoxW (hwndDlg, AppendSrcPos (pszDesc, srcPos).c_str (), lpszTitle, ICON_HAND);
+ if (lpMsgBuf) LocalFree (lpMsgBuf);
// User-friendly hardware error explanation
if (IsDiskError (dwError))
@@ -612,7 +622,7 @@ BOOL translateWin32Error (wchar_t *lpszMsgBuf, int nWSizeOfBuf)
{
DWORD dwError = GetLastError ();
- if (FormatMessageW (FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError,
+ if (FormatMessageW (FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dwError,
MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
lpszMsgBuf, nWSizeOfBuf, NULL))
{