Skip to content

Commit 06b8f6e

Browse files
committed
[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
1 parent 5cdf75a commit 06b8f6e

File tree

1 file changed

+14
-10
lines changed
  • reactos/dll/win32/kernel32/client/console

1 file changed

+14
-10
lines changed

reactos/dll/win32/kernel32/client/console/console.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,15 +1346,19 @@ WINAPI
13461346
DECLSPEC_HOTPATCH
13471347
FreeConsole(VOID)
13481348
{
1349+
BOOL Success = TRUE;
13491350
CONSOLE_API_MESSAGE ApiMessage;
13501351
PCONSOLE_FREECONSOLE FreeConsoleRequest = &ApiMessage.Data.FreeConsoleRequest;
13511352
HANDLE ConsoleHandle = NtCurrentPeb()->ProcessParameters->ConsoleHandle;
13521353

1354+
RtlEnterCriticalSection(&ConsoleLock);
1355+
13531356
/* We must have a non-trivial handle to close */
13541357
if (ConsoleHandle == NULL) // IsConsoleHandle(ConsoleHandle)
13551358
{
13561359
SetLastError(ERROR_INVALID_PARAMETER);
1357-
return FALSE;
1360+
Success = FALSE;
1361+
goto Quit;
13581362
}
13591363

13601364
/* Set up the data to send to the Console Server */
@@ -1370,7 +1374,8 @@ FreeConsole(VOID)
13701374
if (!NT_SUCCESS(ApiMessage.Status))
13711375
{
13721376
BaseSetLastNTError(ApiMessage.Status);
1373-
return FALSE;
1377+
Success = FALSE;
1378+
goto Quit;
13741379
}
13751380

13761381
/* Reset the console handle */
@@ -1380,7 +1385,9 @@ FreeConsole(VOID)
13801385
CloseHandle(InputWaitHandle);
13811386
InputWaitHandle = INVALID_HANDLE_VALUE;
13821387

1383-
return TRUE;
1388+
Quit:
1389+
RtlLeaveCriticalSection(&ConsoleLock);
1390+
return Success;
13841391
}
13851392

13861393

@@ -2007,18 +2014,15 @@ SetConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine,
20072014
{
20082015
BOOL Ret;
20092016

2010-
RtlEnterCriticalSection(&BaseDllDirectoryLock);
2017+
RtlEnterCriticalSection(&ConsoleLock);
2018+
20112019
if (Add)
2012-
{
20132020
Ret = AddConsoleCtrlHandler(HandlerRoutine);
2014-
}
20152021
else
2016-
{
20172022
Ret = RemoveConsoleCtrlHandler(HandlerRoutine);
2018-
}
20192023

2020-
RtlLeaveCriticalSection(&BaseDllDirectoryLock);
2021-
return(Ret);
2024+
RtlLeaveCriticalSection(&ConsoleLock);
2025+
return Ret;
20222026
}
20232027

20242028

0 commit comments

Comments
 (0)