This is the mail archive of the cygwin-patches mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Cygwin: console: Fix segfault on shared_console_info access.


- 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]