public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
From: Takashi Yano <takashi.yano@nifty.ne.jp>
To: cygwin-patches@cygwin.com
Subject: [PATCH] Cygwin: console: Fix new bugs in cons_master_thread().
Date: Sun,  3 Jul 2022 11:04:01 +0900	[thread overview]
Message-ID: <20220703020401.452-1-takashi.yano@nifty.ne.jp> (raw)

- The previous commit for console introduced new bugs in error
  handling in cons_master_thread(). This patch fixes that.
---
 winsup/cygwin/fhandler_console.cc | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc
index c95716c5f..848c96772 100644
--- a/winsup/cygwin/fhandler_console.cc
+++ b/winsup/cygwin/fhandler_console.cc
@@ -361,7 +361,8 @@ fhandler_console::cons_master_thread (handle_set_t *p, tty *ttyp)
 	{
 	case WAIT_OBJECT_0:
 	  total_read = 0;
-	  while (cygwait (p->input_handle, (DWORD) 0) == WAIT_OBJECT_0)
+	  while (cygwait (p->input_handle, (DWORD) 0) == WAIT_OBJECT_0
+		 && total_read < inrec_size)
 	    {
 	      DWORD len;
 	      ReadConsoleInputW (p->input_handle, input_rec + total_read,
@@ -477,7 +478,8 @@ remove_record:
 	      /* Try to fix */
 	      acquire_attach_mutex (mutex_timeout);
 	      n = 0;
-	      while (cygwait (p->input_handle, (DWORD) 0) == WAIT_OBJECT_0)
+	      while (cygwait (p->input_handle, (DWORD) 0) == WAIT_OBJECT_0
+		     && n < inrec_size)
 		{
 		  DWORD len;
 		  ReadConsoleInputW (p->input_handle, input_tmp + n,
@@ -492,14 +494,13 @@ remove_record:
 		    if (total_read + j - i >= n)
 		      { /* Something is wrong. Giving up. */
 			acquire_attach_mutex (mutex_timeout);
-			WriteConsoleInputW (p->input_handle, input_tmp, n, &n);
-			n = 0;
-			while (n < total_read)
+			DWORD l = 0;
+			while (l < n)
 			  {
 			    DWORD len;
-			    WriteConsoleInputW (p->input_handle, input_rec + n,
-				      min (total_read - n, inrec_size1), &len);
-			    n += len;
+			    WriteConsoleInputW (p->input_handle, input_tmp + l,
+					      min (n - l, inrec_size1), &len);
+			    l += len;
 			  }
 			release_attach_mutex ();
 			goto skip_writeback;
-- 
2.36.1


                 reply	other threads:[~2022-07-03  2:04 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220703020401.452-1-takashi.yano@nifty.ne.jp \
    --to=takashi.yano@nifty.ne.jp \
    --cc=cygwin-patches@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).