public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin] Cygwin: console: Fix new bugs in cons_master_thread().
@ 2022-07-03 2:04 Takashi Yano
0 siblings, 0 replies; only message in thread
From: Takashi Yano @ 2022-07-03 2:04 UTC (permalink / raw)
To: cygwin-cvs
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=2c2c2b631bf2a11bfa335611077a774a98650afb
commit 2c2c2b631bf2a11bfa335611077a774a98650afb
Author: Takashi Yano <takashi.yano@nifty.ne.jp>
Date: Sun Jul 3 10:38:13 2022 +0900
Cygwin: console: Fix new bugs in cons_master_thread().
- The previous commit for console introduced new bugs in error
handling in cons_master_thread(). This patch fixes that.
Diff:
---
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 4f462e3e8..52031fe31 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,
@@ -478,7 +479,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,
@@ -493,14 +495,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;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-07-03 2:04 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-03 2:04 [newlib-cygwin] Cygwin: console: Fix new bugs in cons_master_thread() Takashi Yano
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).