https://git.reactos.org/?p=reactos.git;a=commitdiff;h=84b3fecb263e7d342c73d…
commit 84b3fecb263e7d342c73ddaf53fc3e753f2cb34b
Author: George Bișoc <george.bisoc(a)reactos.org>
AuthorDate: Mon Apr 19 17:18:51 2021 +0200
Commit: George Bișoc <george.bisoc(a)reactos.org>
CommitDate: Thu Apr 22 13:30:55 2021 +0200
[MSGINA] Determine which kind of dialog box is before terminating it
Do a sanity check onto the dialog box type before terminating it. As it stands now, a
call of PostQuitMessage() is invoked even when the dialog box is modal. This is illegal
due to the fact that the shutdown dialog box is initiated by the "Security" main
window thus WlxDialogBoxParam.
A call to PostQuitMessage onto a modal dialog box leads to a undefined behaviour, as
it'll not just terminate the thread but also eventually killing the Winlogon process
whose the thread belongs to.
CORE-17535
---
dll/win32/msgina/shutdown.c | 39 +++++++++++++++++++++++++++++++++------
1 file changed, 33 insertions(+), 6 deletions(-)
diff --git a/dll/win32/msgina/shutdown.c b/dll/win32/msgina/shutdown.c
index 6ea696d5031..d2478b2df02 100644
--- a/dll/win32/msgina/shutdown.c
+++ b/dll/win32/msgina/shutdown.c
@@ -61,6 +61,7 @@ typedef struct _SHUTDOWN_DLG_CONTEXT
BOOL bReasonUI;
BOOL bFriendlyUI;
BOOL bIsButtonHot[NUMBER_OF_BUTTONS];
+ BOOL bIsDialogModal;
WNDPROC OldButtonProc;
} SHUTDOWN_DLG_CONTEXT, *PSHUTDOWN_DLG_CONTEXT;
@@ -1058,8 +1059,16 @@ ShutdownDialogProc(
if (!pContext->bCloseDlg)
{
pContext->bCloseDlg = TRUE;
- DestroyWindow(hDlg);
- PostQuitMessage(0);
+
+ if (pContext->bIsDialogModal)
+ {
+ EndDialog(hDlg, 0);
+ }
+ else
+ {
+ DestroyWindow(hDlg);
+ PostQuitMessage(0);
+ }
}
}
return FALSE;
@@ -1079,8 +1088,16 @@ ShutdownDialogProc(
case WM_CLOSE:
pContext->bCloseDlg = TRUE;
- DestroyWindow(hDlg);
- PostQuitMessage(IDCANCEL);
+
+ if (pContext->bIsDialogModal)
+ {
+ EndDialog(hDlg, IDCANCEL);
+ }
+ else
+ {
+ DestroyWindow(hDlg);
+ PostQuitMessage(IDCANCEL);
+ }
break;
case WM_COMMAND:
@@ -1105,8 +1122,16 @@ ShutdownDialogProc(
case IDCANCEL:
case IDHELP:
pContext->bCloseDlg = TRUE;
- DestroyWindow(hDlg);
- PostQuitMessage(LOWORD(wParam));
+
+ if (pContext->bIsDialogModal)
+ {
+ EndDialog(hDlg, LOWORD(wParam));
+ }
+ else
+ {
+ DestroyWindow(hDlg);
+ PostQuitMessage(LOWORD(wParam));
+ }
break;
case IDC_SHUTDOWN_ACTION:
@@ -1189,6 +1214,7 @@ ShutdownDialog(
if (pgContext->hWlx && pgContext->pWlxFuncs &&
!Context.bFriendlyUI)
{
+ Context.bIsDialogModal = TRUE;
ret = pgContext->pWlxFuncs->WlxDialogBoxParam(pgContext->hWlx,
pgContext->hDllInstance,
MAKEINTRESOURCEW(Context.bReasonUI
? IDD_SHUTDOWN_REASON : IDD_SHUTDOWN),
@@ -1210,6 +1236,7 @@ ShutdownDialog(
}
}
+ Context.bIsDialogModal = FALSE;
hDlg = CreateDialogParamW(pgContext->hDllInstance,
MAKEINTRESOURCEW(Context.bReasonUI ?
IDD_SHUTDOWN_REASON : ShutdownDialogId),
hwndDlg,