From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7868) id 8DF5A3858403; Fri, 2 Feb 2024 16:20:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8DF5A3858403 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1706890852; bh=AmWG5xNRFXpJc5ORuhbP7JgwESR26sblPjY2kOYPWzQ=; h=From:To:Subject:Date:From; b=kWT+57NEijot9tGl4/jNNCcFZeDtaPZPTqc6fM4TUrA4VoUtUBdKy6iiRG3Bd9xKD uEVBpB6zCrfLKE5HEJtyNf1OOsFU+DLNLiokmCjLyyRsIrFgXIMpXwf1viRT8Lr3yD 842aoMoNhOsOJR2dJUXFAMEim11dL9LTLZaTQXQc= 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-3_5-branch] Cygwin: console: Avoid slipping past disable_master_thread check. X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/cygwin-3_5-branch X-Git-Oldrev: aa73e115242612bf8b5f8670c0c7d398693d1d84 X-Git-Newrev: 9bcfd0604533764f3ebfa5015e182f6db7c8922d Message-Id: <20240202162052.8DF5A3858403@sourceware.org> Date: Fri, 2 Feb 2024 16:20:52 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D9bcfd060453= 3764f3ebfa5015e182f6db7c8922d commit 9bcfd0604533764f3ebfa5015e182f6db7c8922d Author: Takashi Yano Date: Sat Feb 3 00:54:23 2024 +0900 Cygwin: console: Avoid slipping past disable_master_thread check. =20 If disable_master_thread flag is set between the code checking that flag not be set and the code acquiring input_mutex, input record is processed once after setting disable_master_thread flag. This patch prevents that. =20 Fixes: d4aacd50e6cf ("Cygwin: console: Add missing input_mutex guard.") Signed-off-by: Takashi Yano Diff: --- winsup/cygwin/fhandler/console.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/winsup/cygwin/fhandler/console.cc b/winsup/cygwin/fhandler/con= sole.cc index 6a42b4949..1c8d383cd 100644 --- a/winsup/cygwin/fhandler/console.cc +++ b/winsup/cygwin/fhandler/console.cc @@ -420,6 +420,12 @@ fhandler_console::cons_master_thread (handle_set_t *p,= tty *ttyp) } =20 WaitForSingleObject (p->input_mutex, mutex_timeout); + /* Ensure accessing input recored is not disabled. */ + if (con.disable_master_thread) + { + ReleaseMutex (p->input_mutex); + continue; + } total_read =3D 0; switch (cygwait (p->input_handle, (DWORD) 0)) { @@ -4545,8 +4551,6 @@ fhandler_console::set_disable_master_thread (bool x, = fhandler_console *cons) return; } const _minor_t unit =3D cons->get_minor (); - if (con.disable_master_thread =3D=3D x) - return; cons->acquire_input_mutex (mutex_timeout); con.disable_master_thread =3D x; cons->release_input_mutex ();