From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id F30E03851C09; Sun, 31 May 2020 08:39:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F30E03851C09 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: Discard some unsupported escape sequences. X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano via Cygwin-patches X-Git-Refname: refs/heads/master X-Git-Oldrev: 0f7193f4fbbfdde52fe21639ca582a32a63eb851 X-Git-Newrev: 4527541ec66af8d82bb9dba5d25afdf489d71271 Message-Id: <20200531083920.F30E03851C09@sourceware.org> Date: Sun, 31 May 2020 08:39:20 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 31 May 2020 08:39:21 -0000 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=4527541ec66af8d82bb9dba5d25afdf489d71271 commit 4527541ec66af8d82bb9dba5d25afdf489d71271 Author: Takashi Yano via Cygwin-patches Date: Sun May 31 14:53:18 2020 +0900 Cygwin: console: Discard some unsupported escape sequences. - If the cygwin vim is started from a non-cygwin process which is executed in pseudo console, shift key and ctrl key do not work. In this case, vim is executed under /dev/cons*. If vim outputs escape sequence which is not supported by pseudo console, the escape sequence is leaked into the parent pty. This causes unexpected results. This patch fixes the issue by discarding "CSI > Pm m". "OSC 10;? BEL/ST" and "OSC 11;? BEL/ST" are discarded as well. Diff: --- winsup/cygwin/fhandler_console.cc | 54 +++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc index 5cb4343ea..dd979fb8e 100644 --- a/winsup/cygwin/fhandler_console.cc +++ b/winsup/cygwin/fhandler_console.cc @@ -2186,6 +2186,14 @@ fhandler_console::char_command (char c) /* Just send the sequence */ wpbuf.send (get_output_handle ()); break; + case 'm': + if (con.saw_greater_than_sign) + break; /* Ignore unsupported CSI > Pm m */ + /* Text attribute settings */ + wpbuf.put (c); + /* Just send the sequence */ + wpbuf.send (get_output_handle ()); + break; default: /* Other escape sequences */ wpbuf.put (c); @@ -3077,6 +3085,13 @@ fhandler_console::write (const void *vsrc, size_t len) con.state = normal; wpbuf.empty(); } + else if (*src == ']') /* OSC Operating System Command */ + { + wpbuf.put (*src); + con.rarg = 0; + con.my_title_buf[0] = '\0'; + con.state = gotrsquare; + } else if (wincap.has_con_24bit_colors () && !con_is_legacy) { if (*src == 'c') /* RIS Full reset */ @@ -3095,13 +3110,6 @@ fhandler_console::write (const void *vsrc, size_t len) con.state = normal; wpbuf.empty(); } - else if (*src == ']') /* OSC Operating System Command */ - { - wpbuf.put (*src); - con.rarg = 0; - con.my_title_buf[0] = '\0'; - con.state = gotrsquare; - } else if (*src == '(') /* Designate G0 character set */ { wpbuf.put (*src); @@ -3179,7 +3187,8 @@ fhandler_console::write (const void *vsrc, size_t len) con.rarg = con.rarg * 10 + (*src - '0'); else if (*src == ';' && (con.rarg == 2 || con.rarg == 0)) con.state = gettitle; - else if (*src == ';' && (con.rarg == 4 || con.rarg == 104)) + else if (*src == ';' && (con.rarg == 4 || con.rarg == 104 + || (con.rarg >= 10 && con.rarg <= 19))) con.state = eatpalette; else con.state = eattitle; @@ -3189,10 +3198,13 @@ fhandler_console::write (const void *vsrc, size_t len) case eattitle: case gettitle: { + wpbuf.put (*src); int n = strlen (con.my_title_buf); if (*src < ' ') { - if (*src == '\007' && con.state == gettitle) + if (wincap.has_con_24bit_colors () && !con_is_legacy) + wpbuf.send (get_output_handle ()); + else if (*src == '\007' && con.state == gettitle) set_console_title (con.my_title_buf); con.state = normal; wpbuf.empty(); @@ -3201,27 +3213,37 @@ fhandler_console::write (const void *vsrc, size_t len) { con.my_title_buf[n++] = *src; con.my_title_buf[n] = '\0'; - wpbuf.put (*src); } src++; break; } case eatpalette: - if (*src == '\033') - { - wpbuf.put (*src); - con.state = endpalette; - } + wpbuf.put (*src); + if (*src == '?') + con.saw_question_mark = true; + else if (*src == '\033') + con.state = endpalette; else if (*src == '\a') { + /* Send OSC Ps; Pt BEL other than OSC Ps; ? BEL */ + if (wincap.has_con_24bit_colors () && !con_is_legacy + && !con.saw_question_mark) + wpbuf.send (get_output_handle ()); con.state = normal; wpbuf.empty(); } src++; break; case endpalette: + wpbuf.put (*src); if (*src == '\\') - con.state = normal; + { + /* Send OSC Ps; Pt ST other than OSC Ps; ? ST */ + if (wincap.has_con_24bit_colors () && !con_is_legacy + && !con.saw_question_mark) + wpbuf.send (get_output_handle ()); + con.state = normal; + } else /* Sequence error (abort) */ con.state = normal;