From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7868) id 7CB9B385C318; Sun, 3 Jul 2022 02:04:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7CB9B385C318 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Takashi Yano To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin] Cygwin: console: Fix new bugs in cons_master_thread(). X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/master X-Git-Oldrev: 746c8116dd4f4397ceeac0513c5af6018e9f522e X-Git-Newrev: 2c2c2b631bf2a11bfa335611077a774a98650afb Message-Id: <20220703020436.7CB9B385C318@sourceware.org> Date: Sun, 3 Jul 2022 02:04:36 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 03 Jul 2022 02:04:37 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D2c2c2b631bf= 2a11bfa335611077a774a98650afb commit 2c2c2b631bf2a11bfa335611077a774a98650afb Author: Takashi Yano Date: Sun Jul 3 10:38:13 2022 +0900 Cygwin: console: Fix new bugs in cons_master_thread(). =20 - 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_con= sole.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 =3D 0; - while (cygwait (p->input_handle, (DWORD) 0) =3D=3D WAIT_OBJECT_0) + while (cygwait (p->input_handle, (DWORD) 0) =3D=3D 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 =3D 0; - while (cygwait (p->input_handle, (DWORD) 0) =3D=3D WAIT_OBJECT_0) + while (cygwait (p->input_handle, (DWORD) 0) =3D=3D 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 >=3D n) { /* Something is wrong. Giving up. */ acquire_attach_mutex (mutex_timeout); - WriteConsoleInputW (p->input_handle, input_tmp, n, &n); - n =3D 0; - while (n < total_read) + DWORD l =3D 0; + while (l < n) { DWORD len; - WriteConsoleInputW (p->input_handle, input_rec + n, - min (total_read - n, inrec_size1), &len); - n +=3D len; + WriteConsoleInputW (p->input_handle, input_tmp + l, + min (n - l, inrec_size1), &len); + l +=3D len; } release_attach_mutex (); goto skip_writeback;