[PATCH] kernel32: Always uninitialize the terminal for the console shell process

Andrew Eikum aeikum at codeweavers.com
Tue Nov 17 09:41:43 CST 2015


The terminal raw IO check and the console shell process check are used
separately to initialize the terminal in different ways. However, if
either check fails during uninitialization, then no uninitialization
will occur at all and modified terminfo settings will remain instead
of being restored. We should check each condition individually and
uninitialize each part as required.

This fixes Bug 25843.

Signed-off-by: Andrew Eikum <aeikum at codeweavers.com>
---

I'm not very familiar with this kind of code, so additional review
would be nice.

 dlls/kernel32/console.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/dlls/kernel32/console.c b/dlls/kernel32/console.c
index 363e763..51d6e60 100644
--- a/dlls/kernel32/console.c
+++ b/dlls/kernel32/console.c
@@ -211,15 +211,18 @@ static BOOL put_console_into_raw_mode(int fd)
 static BOOL restore_console_mode(HANDLE hin)
 {
     int         fd;
-    BOOL        ret;
+    BOOL        ret = TRUE;
+
+    if (S_termios_raw)
+    {
+        if ((fd = get_console_bare_fd(hin)) == -1) return FALSE;
+        ret = tcsetattr(fd, TCSANOW, &S_termios) >= 0;
+        close(fd);
+    }
+
+    if (RtlGetCurrentPeb()->ProcessParameters->ConsoleHandle == KERNEL32_CONSOLE_SHELL)
+        TERM_Exit();
 
-    if (!S_termios_raw ||
-        RtlGetCurrentPeb()->ProcessParameters->ConsoleHandle != KERNEL32_CONSOLE_SHELL)
-        return TRUE;
-    if ((fd = get_console_bare_fd(hin)) == -1) return FALSE;
-    ret = tcsetattr(fd, TCSANOW, &S_termios) >= 0;
-    close(fd);
-    TERM_Exit();
     return ret;
 }
 
-- 
2.6.2




More information about the wine-patches mailing list