[newlib-cygwin] Cygwin: pty: Fix write data handling in pcon_start phase

Takashi Yano tyan0@sourceware.org
Mon Apr 6 12:18:53 GMT 2026


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

commit c8bbec4c551f9b606305d87a165909facf442e0b
Author: Takashi Yano <takashi.yano@nifty.ne.jp>
Date:   Wed Mar 25 19:32:16 2026 +0900

    Cygwin: pty: Fix write data handling in pcon_start phase
    
    If the 'for' loop in pcon_start handling in master write() does not
    break, 'ptr' and 'len' loose the chance to fixup the value. In this
    case, all data in 'ptr' are processed, so the 'len' should be 0.
    1 byte is consistently consumed in each iteration in the 'for' loop,
    so this patch fixups 'ptr' and 'len' in every iterations instead of
    fixing-up at break.
    
    Fixes: 9d7440036580 ("Cygwin: pty: Fix handling of data after CSI6n response")
    Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
    Reviewed-by: Johannes Schindelin <johannes.schindelin@gmx.de>

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

diff --git a/winsup/cygwin/fhandler/pty.cc b/winsup/cygwin/fhandler/pty.cc
index 60b8256f4..3c6b90ef5 100644
--- a/winsup/cygwin/fhandler/pty.cc
+++ b/winsup/cygwin/fhandler/pty.cc
@@ -2235,6 +2235,8 @@ fhandler_pty_master::write (const void *ptr, size_t len)
 	    }
 	  else
 	    line_edit (p + i, 1, ti, &ret);
+	  len = orig_len - i - 1;
+	  ptr = p + i + 1;
 	  if (state == 1 && p[i] == 'R')
 	    state = 2;
 	  if (state == 2)
@@ -2244,8 +2246,6 @@ fhandler_pty_master::write (const void *ptr, size_t len)
 		 the response sequence should not be written. */
 	      if (!get_ttyp ()->req_xfer_input)
 		WriteFile (to_slave_nat, wpbuf, ixput, &n, NULL);
-	      len = orig_len - i - 1;
-	      ptr = p + i + 1;
 	      ixput = 0;
 	      state = 0;
 	      get_ttyp ()->req_xfer_input = false;


More information about the Cygwin-cvs mailing list