From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7868) id 92BA93858403; Fri, 2 Feb 2024 16:21:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 92BA93858403 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1706890872; bh=DoAQbm9ydTMvmWu0EKAXaErrs8smwSt4g2wlY54YvzY=; h=From:To:Subject:Date:From; b=x9bJCsGESAIEIiW7ykqtl/nq9/LW7eqSzjravS2m8Oh21r1iTMpfH02T7V9x+n0ZS hZ67f93xBHXx77u/O2NCWbSCKLCZvy19dhgBpjhjC6nsyUeTohALsDVpr85P46EaBZ MYfJMazrEZGBQhatjSQf2C5gh6Cz54+lXABcBB1Y= 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: Avoid slipping past disable_master_thread check. X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/master X-Git-Oldrev: 084f848ab9a51d0125491a6f2a7a741f9df73218 X-Git-Newrev: c2be9bf5eb687389e4d0385839f2f5b78bb820be Message-Id: <20240202162112.92BA93858403@sourceware.org> Date: Fri, 2 Feb 2024 16:21:12 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3Dc2be9bf5eb6= 87389e4d0385839f2f5b78bb820be commit c2be9bf5eb687389e4d0385839f2f5b78bb820be 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 ();