From 06b8f6ed654fa2a5dbe6994eb70cc432265d5fdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Sun, 5 Apr 2015 23:42:26 +0000 Subject: [PATCH] [KERNEL32] - Use the correct console critical section when setting console control handlers. - Hold the console critical section in FreeConsole (so that we avoid freeing the console while also running code in the console control dispatcher...). svn path=/trunk/; revision=67069 --- .../win32/kernel32/client/console/console.c | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/reactos/dll/win32/kernel32/client/console/console.c b/reactos/dll/win32/kernel32/client/console/console.c index 72251cb2814..1fb23bade29 100644 --- a/reactos/dll/win32/kernel32/client/console/console.c +++ b/reactos/dll/win32/kernel32/client/console/console.c @@ -1346,15 +1346,19 @@ WINAPI DECLSPEC_HOTPATCH FreeConsole(VOID) { + BOOL Success = TRUE; CONSOLE_API_MESSAGE ApiMessage; PCONSOLE_FREECONSOLE FreeConsoleRequest = &ApiMessage.Data.FreeConsoleRequest; HANDLE ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle; + RtlEnterCriticalSection(&ConsoleLock); + /* We must have a non-trivial handle to close */ if (ConsoleHandle == NULL) // IsConsoleHandle(ConsoleHandle) { SetLastError(ERROR_INVALID_PARAMETER); - return FALSE; + Success = FALSE; + goto Quit; } /* Set up the data to send to the Console Server */ @@ -1370,7 +1374,8 @@ FreeConsole(VOID) if (!NT_SUCCESS(ApiMessage.Status)) { BaseSetLastNTError(ApiMessage.Status); - return FALSE; + Success = FALSE; + goto Quit; } /* Reset the console handle */ @@ -1380,7 +1385,9 @@ FreeConsole(VOID) CloseHandle(InputWaitHandle); InputWaitHandle = INVALID_HANDLE_VALUE; - return TRUE; +Quit: + RtlLeaveCriticalSection(&ConsoleLock); + return Success; } @@ -2007,18 +2014,15 @@ SetConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine, { BOOL Ret; - RtlEnterCriticalSection(&BaseDllDirectoryLock); - if (Add) - { - Ret = AddConsoleCtrlHandler(HandlerRoutine); - } - else - { - Ret = RemoveConsoleCtrlHandler(HandlerRoutine); - } + RtlEnterCriticalSection(&ConsoleLock); - RtlLeaveCriticalSection(&BaseDllDirectoryLock); - return(Ret); + if (Add) + Ret = AddConsoleCtrlHandler(HandlerRoutine); + else + Ret = RemoveConsoleCtrlHandler(HandlerRoutine); + + RtlLeaveCriticalSection(&ConsoleLock); + return Ret; }