diff options
author | Takashi Yano <takashi.yano@nifty.ne.jp> | 2024-07-03 22:35:20 +0900 |
---|---|---|
committer | Takashi Yano <takashi.yano@nifty.ne.jp> | 2024-07-03 23:17:33 +0900 |
commit | f7a77d014693a88b8a3dbecfd792956e99a7323e (patch) | |
tree | 928285cd6565873cae68299e47c29e13201ab617 /winsup/cygwin | |
parent | a5ffae145514df36ed134d3f36cedb9f81f743ea (diff) | |
download | newlib-f7a77d014693a88b8a3dbecfd792956e99a7323e.zip newlib-f7a77d014693a88b8a3dbecfd792956e99a7323e.tar.gz newlib-f7a77d014693a88b8a3dbecfd792956e99a7323e.tar.bz2 |
Cygwin: console: Fix conflict on shared names between sessions.
Previously, shared names in the console were created using get_minor().
However, get_minor() was not unique to the console across sessions.
This is because EnumWindows(), which is used to look for console windows,
cannot enumerate windows across sessions. This causes conflict on the
shared names between sessions (e.g. sessions of different users,
different services, a service and a user session, etc.).
With this patch, GetConsoleWindow() is used instead of get_minor().
GetConsoleWindow() has been used for the name of shared memory, which
should be unique to each console.
Addresses: https://cygwin.com/pipermail/cygwin/2024-April/255893.html
Fixes: ff4440fcf768 ("Cygwin: console: Introduce new thread which handles input signal.");
Reported-by: Johannes Khoshnazar-Thoma <johannes@johannesthoma.com>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Diffstat (limited to 'winsup/cygwin')
-rw-r--r-- | winsup/cygwin/fhandler/console.cc | 15 | ||||
-rw-r--r-- | winsup/cygwin/release/3.5.4 | 3 |
2 files changed, 14 insertions, 4 deletions
diff --git a/winsup/cygwin/fhandler/console.cc b/winsup/cygwin/fhandler/console.cc index dbf6ce8..7945a32 100644 --- a/winsup/cygwin/fhandler/console.cc +++ b/winsup/cygwin/fhandler/console.cc @@ -66,6 +66,13 @@ static struct fhandler_base::rabuf_t con_ra; in xterm compatible mode */ static wchar_t last_char; +static char * +cons_shared_name (char *ret_buf, const char *str, HWND hw) +{ + __small_sprintf (ret_buf, "%s.%p", str, hw); + return ret_buf; +} + DWORD fhandler_console::attach_console (pid_t owner, bool *err) { @@ -922,7 +929,7 @@ fhandler_console::setup_io_mutex (void) res = WAIT_FAILED; if (!input_mutex || WAIT_FAILED == (res = acquire_input_mutex (0))) { - shared_name (buf, "cygcons.input.mutex", get_minor ()); + cons_shared_name (buf, "cygcons.input.mutex", GetConsoleWindow ()); input_mutex = OpenMutex (MAXIMUM_ALLOWED, TRUE, buf); if (!input_mutex) input_mutex = CreateMutex (&sec_none, FALSE, buf); @@ -938,7 +945,7 @@ fhandler_console::setup_io_mutex (void) res = WAIT_FAILED; if (!output_mutex || WAIT_FAILED == (res = acquire_output_mutex (0))) { - shared_name (buf, "cygcons.output.mutex", get_minor ()); + cons_shared_name (buf, "cygcons.output.mutex", GetConsoleWindow ()); output_mutex = OpenMutex (MAXIMUM_ALLOWED, TRUE, buf); if (!output_mutex) output_mutex = CreateMutex (&sec_none, FALSE, buf); @@ -1853,7 +1860,7 @@ fhandler_console::open (int flags, mode_t) if (GetModuleHandle ("ConEmuHk64.dll")) hook_conemu_cygwin_connector (); char name[MAX_PATH]; - shared_name (name, CONS_THREAD_SYNC, get_minor ()); + cons_shared_name (name, CONS_THREAD_SYNC, GetConsoleWindow ()); thread_sync_event = CreateEvent(NULL, FALSE, FALSE, name); if (thread_sync_event) { @@ -1922,7 +1929,7 @@ fhandler_console::close () if (master_thread_started) { char name[MAX_PATH]; - shared_name (name, CONS_THREAD_SYNC, get_minor ()); + cons_shared_name (name, CONS_THREAD_SYNC, GetConsoleWindow ()); thread_sync_event = OpenEvent (MAXIMUM_ALLOWED, FALSE, name); if (thread_sync_event) { diff --git a/winsup/cygwin/release/3.5.4 b/winsup/cygwin/release/3.5.4 index 17db611..c95ef46 100644 --- a/winsup/cygwin/release/3.5.4 +++ b/winsup/cygwin/release/3.5.4 @@ -19,3 +19,6 @@ Fixes: - Fix a problem that pty slave hangs on writing when pty master stops to read. Addresses: https://cygwin.com/pipermail/cygwin/2024-June/256178.html + +- Fix conflict on shared name in console between sessions. + Addresses: https://cygwin.com/pipermail/cygwin/2024-April/255893.html |