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

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Takashi Yano
- Accessing shared_console_info before initialization causes access
  violation because 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() when it is
  called from close(). This patch makes sure that shared_console_info
  is not NULL before calling request_xterm_mode_output().
---
 winsup/cygwin/fhandler_console.cc | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc
index 42040a971..328424a7d 100644
--- a/winsup/cygwin/fhandler_console.cc
+++ b/winsup/cygwin/fhandler_console.cc
@@ -1159,18 +1159,17 @@ fhandler_console::close ()
 
   acquire_output_mutex (INFINITE);
 
-  if (shared_console_info && myself->pid == con.owner &&
-      wincap.has_con_24bit_colors () && !con_is_legacy)
-    request_xterm_mode_output (false);
-
-  /* Restore console mode if this is the last closure. */
-  OBJECT_BASIC_INFORMATION obi;
-  NTSTATUS status;
-  status = NtQueryObject (get_handle (), ObjectBasicInformation,
-  &obi, sizeof obi, NULL);
-  if (NT_SUCCESS (status) && obi.HandleCount == 1)
-    if (wincap.has_con_24bit_colors ())
-      request_xterm_mode_output (false);
+  if (shared_console_info && wincap.has_con_24bit_colors ())
+    {
+      /* Restore console mode if this is the last closure. */
+      OBJECT_BASIC_INFORMATION obi;
+      NTSTATUS status;
+      status = NtQueryObject (get_handle (), ObjectBasicInformation,
+      &obi, sizeof obi, NULL);
+      if ((NT_SUCCESS (status) && obi.HandleCount == 1)
+  || myself->pid == con.owner)
+ request_xterm_mode_output (false);
+    }
 
   release_output_mutex ();
 
--
2.21.0

Reply | Threaded
Open this post in threaded view
|

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

Corinna Vinschen-2
On Feb 25 01:12, Takashi Yano wrote:
> - Accessing shared_console_info before initialization causes access
>   violation because 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() when it is
>   called from close(). This patch makes sure that shared_console_info
>   is not NULL before calling request_xterm_mode_output().
> ---
>  winsup/cygwin/fhandler_console.cc | 23 +++++++++++------------
>  1 file changed, 11 insertions(+), 12 deletions(-)

Pushed.


Thanks,
Corinna

--
Corinna Vinschen
Cygwin Maintainer

signature.asc (849 bytes) Download Attachment