This is the mail archive of the
cygwin-patches
mailing list for the Cygwin project.
[PATCH] Cygwin: console: Fix segfault on shared_console_info access.
- From: Takashi Yano <takashi dot yano at nifty dot ne dot jp>
- To: cygwin-patches at cygwin dot com
- Cc: Takashi Yano <takashi dot yano at nifty dot ne dot jp>
- Date: Sat, 22 Feb 2020 04:10:00 +0900
- Subject: [PATCH] Cygwin: console: Fix segfault on shared_console_info access.
- Dkim-filter: OpenDKIM Filter v2.10.3 conuserg-04.nifty.com 01LJA4Ep006137
- Accessing shared_console_info accidentaly causes segmentation
fault when it is a NULL pointer. The cause of the problem reported
in https://cygwin.com/ml/cygwin/2020-02/msg00197.html is this NULL
pointer access in request_xterm_mode_output(). This patch fixes
the issue.
---
winsup/cygwin/fhandler_console.cc | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc
index 42040a971..e298dd60c 100644
--- a/winsup/cygwin/fhandler_console.cc
+++ b/winsup/cygwin/fhandler_console.cc
@@ -256,7 +256,8 @@ fhandler_console::request_xterm_mode_input (bool req)
return;
if (req)
{
- if (InterlockedIncrement (&con.xterm_mode_input) == 1)
+ if (!shared_console_info ||
+ InterlockedIncrement (&con.xterm_mode_input) == 1)
{
DWORD dwMode;
GetConsoleMode (get_handle (), &dwMode);
@@ -266,7 +267,8 @@ fhandler_console::request_xterm_mode_input (bool req)
}
else
{
- if (InterlockedDecrement (&con.xterm_mode_input) == 0)
+ if (!shared_console_info ||
+ InterlockedDecrement (&con.xterm_mode_input) == 0)
{
DWORD dwMode;
GetConsoleMode (get_handle (), &dwMode);
@@ -283,7 +285,8 @@ fhandler_console::request_xterm_mode_output (bool req)
return;
if (req)
{
- if (InterlockedExchange (&con.xterm_mode_output, 1) == 0)
+ if (!shared_console_info ||
+ InterlockedExchange (&con.xterm_mode_output, 1) == 0)
{
DWORD dwMode;
GetConsoleMode (get_output_handle (), &dwMode);
@@ -293,7 +296,8 @@ fhandler_console::request_xterm_mode_output (bool req)
}
else
{
- if (InterlockedExchange (&con.xterm_mode_output, 0) == 1)
+ if (!shared_console_info ||
+ InterlockedExchange (&con.xterm_mode_output, 0) == 1)
{
DWORD dwMode;
GetConsoleMode (get_output_handle (), &dwMode);
--
2.21.0