https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=a2e8a63c90e3427a4e6f4e5a52754626fdf87599

commit a2e8a63c90e3427a4e6f4e5a52754626fdf87599
Author: Takashi Yano <[email protected]>
Date:   Fri Dec 19 13:19:40 2025 +0900

    Cygwin: pty: Make ESC sequence parser in pty_master_fwd_thread durable
    
    If the ESC comes when the state is not zero due to a broken ESC
    sequence, the second ESC sequence cannot be handled properly.
    With this patch, ESC that come in the middle of another sequence
    make the state machine start parsing new ESC secuence.
    
    Fixes: 10d083c745dd ("Cygwin: pty: Inherit typeahead data between two input 
pipes.")
    Suggested-by: Johannes Schindelin <[email protected]>
    Signed-off-by: Takashi Yano <[email protected]>

Diff:
---
 winsup/cygwin/fhandler/pty.cc | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/winsup/cygwin/fhandler/pty.cc b/winsup/cygwin/fhandler/pty.cc
index 3b0b4f073..c558b62b2 100644
--- a/winsup/cygwin/fhandler/pty.cc
+++ b/winsup/cygwin/fhandler/pty.cc
@@ -2710,6 +2710,12 @@ fhandler_pty_master::pty_master_fwd_thread (const 
master_fwd_thread_param_t *p)
              }
            else if (state == 4)
              continue;
+           else if (outbuf[i] == '\033')
+             {
+               start_at = i;
+               state = 1;
+               continue;
+             }
            else
              {
                state = 0;
@@ -2772,6 +2778,12 @@ fhandler_pty_master::pty_master_fwd_thread (const 
master_fwd_thread_param_t *p)
                i = start_at - 1;
                continue;
              }
+           else if (outbuf[i] == '\033')
+             {
+               start_at = i;
+               state = 1;
+               continue;
+             }
            else
              state = 0;

Reply via email to