[newlib-cygwin/cygwin-3_6-branch] Cygwin: pty: Fix write data handling in pcon_start phase

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


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

commit 25a9e4de1df282cc32534b13cdf267a410a7de86
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>
    (cherry picked from commit c8bbec4c551f9b606305d87a165909facf442e0b)

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 aa48fd017..29f780a39 100644
--- a/winsup/cygwin/fhandler/pty.cc
+++ b/winsup/cygwin/fhandler/pty.cc
@@ -2218,6 +2218,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)
@@ -2227,8 +2229,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