From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 67471 invoked by alias); 13 Nov 2019 09:28:33 -0000 Mailing-List: contact cygwin-cvs-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: cygwin-cvs-owner@cygwin.com Received: (qmail 67438 invoked by uid 9078); 13 Nov 2019 09:28:33 -0000 Date: Wed, 13 Nov 2019 09:28:00 -0000 Message-ID: <20191113092833.67436.qmail@sourceware.org> Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: console: Revise the code checking if the console is legacy. X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/master X-Git-Oldrev: 7ef4290a98edca60cfbab44327384f8ad6b471da X-Git-Newrev: 8f8522c82a43c926119a5764ff009e4e5c26bbdf X-SW-Source: 2019-q4/txt/msg00029.txt.bz2 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=8f8522c82a43c926119a5764ff009e4e5c26bbdf commit 8f8522c82a43c926119a5764ff009e4e5c26bbdf Author: Takashi Yano Date: Wed Nov 13 03:04:59 2019 +0900 Cygwin: console: Revise the code checking if the console is legacy. - Accessing shared_console_info before initializing causes access violation in checking if the console is legacy mode. This patch fixes this issue. This solves the problem reported in: https://www.cygwin.com/ml/cygwin-patches/2019-q4/msg00099.html Diff: --- winsup/cygwin/fhandler_console.cc | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc index d875ad6..0b1c82f 100644 --- a/winsup/cygwin/fhandler_console.cc +++ b/winsup/cygwin/fhandler_console.cc @@ -56,6 +56,7 @@ details. */ #define srBottom ((con.scroll_region.Bottom < 0) ? \ con.b.srWindow.Bottom : \ con.b.srWindow.Top + con.scroll_region.Bottom) +#define con_is_legacy (shared_console_info && con.is_legacy) const unsigned fhandler_console::MAX_WRITE_CHARS = 16384; @@ -309,7 +310,7 @@ fhandler_console::set_cursor_maybe () { con.fillin (get_output_handle ()); /* Nothing to do for xterm compatible mode. */ - if (wincap.has_con_24bit_colors () && !con.is_legacy) + if (wincap.has_con_24bit_colors () && !con_is_legacy) return; if (con.dwLastCursorPosition.X != con.b.dwCursorPosition.X || con.dwLastCursorPosition.Y != con.b.dwCursorPosition.Y) @@ -349,7 +350,7 @@ fhandler_console::send_winch_maybe () { con.scroll_region.Top = 0; con.scroll_region.Bottom = -1; - if (wincap.has_con_24bit_colors () && !con.is_legacy) + if (wincap.has_con_24bit_colors () && !con_is_legacy) fix_tab_position (get_output_handle (), con.dwWinSize.X); get_ttyp ()->kill_pgrp (SIGWINCH); return true; @@ -483,7 +484,7 @@ sig_exit: fhandler_console::input_states fhandler_console::process_input_message (void) { - if (wincap.has_con_24bit_colors () && !con.is_legacy) + if (wincap.has_con_24bit_colors () && !con_is_legacy) { DWORD dwMode; /* Enable xterm compatible mode in input */ @@ -589,7 +590,7 @@ fhandler_console::process_input_message (void) } /* Allow Ctrl-Space to emit ^@ */ else if (input_rec[i].Event.KeyEvent.wVirtualKeyCode - == ((wincap.has_con_24bit_colors () && !con.is_legacy) ? + == ((wincap.has_con_24bit_colors () && !con_is_legacy) ? '2' : VK_SPACE) && (ctrl_key_state & CTRL_PRESSED) && !(ctrl_key_state & ALT_PRESSED)) @@ -1029,7 +1030,7 @@ fhandler_console::open (int flags, mode_t) else con.is_legacy = false; /* Enable xterm compatible mode in input */ - if (!con.is_legacy) + if (!con_is_legacy) { GetConsoleMode (get_handle (), &dwMode); dwMode |= ENABLE_VIRTUAL_TERMINAL_INPUT; @@ -1037,14 +1038,14 @@ fhandler_console::open (int flags, mode_t) con.is_legacy = true; } extern int sawTERM; - if (con.is_legacy && !sawTERM) + if (con_is_legacy && !sawTERM) setenv ("TERM", "cygwin", 1); } DWORD cflags; if (GetConsoleMode (get_handle (), &cflags)) SetConsoleMode (get_handle (), ENABLE_WINDOW_INPUT - | ((wincap.has_con_24bit_colors () && !con.is_legacy) ? + | ((wincap.has_con_24bit_colors () && !con_is_legacy) ? 0 : ENABLE_MOUSE_INPUT) | cflags); @@ -1074,7 +1075,7 @@ fhandler_console::close () output_mutex = NULL; if (shared_console_info && getpid () == con.owner && - wincap.has_con_24bit_colors () && !con.is_legacy) + wincap.has_con_24bit_colors () && !con_is_legacy) { DWORD dwMode; /* Disable xterm compatible mode in input */ @@ -1221,7 +1222,7 @@ fhandler_console::output_tcsetattr (int, struct termios const *t) acquire_output_mutex (INFINITE); DWORD flags = ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT; /* If system has 24 bit color capability, use xterm compatible mode. */ - if (wincap.has_con_24bit_colors () && !con.is_legacy) + if (wincap.has_con_24bit_colors () && !con_is_legacy) { flags |= ENABLE_VIRTUAL_TERMINAL_PROCESSING; if (!(t->c_oflag & OPOST) || !(t->c_oflag & ONLCR)) @@ -1286,10 +1287,10 @@ fhandler_console::input_tcsetattr (int, struct termios const *t) } flags |= ENABLE_WINDOW_INPUT | - ((wincap.has_con_24bit_colors () && !con.is_legacy) ? + ((wincap.has_con_24bit_colors () && !con_is_legacy) ? 0 : ENABLE_MOUSE_INPUT); /* if system has 24 bit color capability, use xterm compatible mode. */ - if (wincap.has_con_24bit_colors () && !con.is_legacy) + if (wincap.has_con_24bit_colors () && !con_is_legacy) flags |= ENABLE_VIRTUAL_TERMINAL_INPUT; int res; @@ -1663,7 +1664,7 @@ bool fhandler_console::write_console (PWCHAR buf, DWORD len, DWORD& done) { bool need_fix_tab_position = false; /* Check if screen will be alternated. */ - if (wincap.has_con_24bit_colors () && !con.is_legacy + if (wincap.has_con_24bit_colors () && !con_is_legacy && memmem (buf, len*sizeof (WCHAR), L"\033[?1049", 7*sizeof (WCHAR))) need_fix_tab_position = true; @@ -2511,7 +2512,7 @@ fhandler_console::write_normal (const unsigned char *src, memset (&ps, 0, sizeof ps); while (found < end && found - src < CONVERT_LIMIT - && ((wincap.has_con_24bit_colors () && !con.is_legacy) + && ((wincap.has_con_24bit_colors () && !con_is_legacy) || base_chars[*found] == NOR) ) { switch (ret = f_mbtowc (_REENT, NULL, (const char *) found, @@ -2972,7 +2973,7 @@ fhandler_console::fixup_after_fork_exec (bool execing) { set_unit (); setup_io_mutex (); - if (wincap.has_con_24bit_colors () && !con.is_legacy) + if (wincap.has_con_24bit_colors () && !con_is_legacy) { DWORD dwMode; /* Disable xterm compatible mode in input */