Skip to content

Commit

Permalink
Cygwin: console: Avoid slipping past disable_master_thread check.
Browse files Browse the repository at this point in the history
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.

Fixes: d4aacd5 ("Cygwin: console: Add missing input_mutex guard.")
Signed-off-by: Takashi Yano <[email protected]>
  • Loading branch information
tyan0 authored and dscho committed Feb 3, 2024
1 parent de45537 commit 370e8e2
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions winsup/cygwin/fhandler/console.cc
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,12 @@ fhandler_console::cons_master_thread (handle_set_t *p, tty *ttyp)
}

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 = 0;
switch (cygwait (p->input_handle, (DWORD) 0))
{
Expand Down Expand Up @@ -4545,8 +4551,6 @@ fhandler_console::set_disable_master_thread (bool x, fhandler_console *cons)
return;
}
const _minor_t unit = cons->get_minor ();
if (con.disable_master_thread == x)
return;
cons->acquire_input_mutex (mutex_timeout);
con.disable_master_thread = x;
cons->release_input_mutex ();
Expand Down

0 comments on commit 370e8e2

Please sign in to comment.