public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
From: Takashi Yano <tyan0@sourceware.org>
To: cygwin-cvs@sourceware.org
Subject: [newlib-cygwin/cygwin-3_3-branch] Cygwin: console, pty: Fix segfault in child_info_spawn::worker().
Date: Thu, 10 Mar 2022 11:49:47 +0000 (GMT)	[thread overview]
Message-ID: <20220310114947.4A6AA3857C42@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=7dadbf800505a94079901370e737d3de28673c6e

commit 7dadbf800505a94079901370e737d3de28673c6e
Author: Takashi Yano <takashi.yano@nifty.ne.jp>
Date:   Thu Mar 10 20:20:00 2022 +0900

    Cygwin: console, pty: Fix segfault in child_info_spawn::worker().
    
    - After the commit "Cygwin: pty, console: Fix handle leak which
      occurs on exec() error.", startxwin cannot start X due to the
      error "Failed to activate virtual core keyboard: 2". The problem
      is access violation in the code retrieving the pgid of the ctty.
      This patch fixes the issue.
    
      Addresses: https://cygwin.com/pipermail/cygwin/2022-March/251013.html

Diff:
---
 winsup/cygwin/fhandler.h | 8 ++++++--
 winsup/cygwin/spawn.cc   | 2 +-
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h
index 18bc694d8..3fe127426 100644
--- a/winsup/cygwin/fhandler.h
+++ b/winsup/cygwin/fhandler.h
@@ -1915,6 +1915,7 @@ class fhandler_termios: public fhandler_base
   };
 
  public:
+  virtual pid_t tc_getpgid () { return 0; };
   tty_min*& tc () {return _tc;}
   fhandler_termios () :
   fhandler_base ()
@@ -2158,9 +2159,10 @@ private:
 			       const handle_set_t *p);
 
  public:
-  static pid_t tc_getpgid ()
+  pid_t tc_getpgid ()
   {
-    return shared_console_info ? shared_console_info->tty_min_state.getpgid () : myself->pgid;
+    return shared_console_info ?
+      shared_console_info->tty_min_state.getpgid () : 0;
   }
   fhandler_console (fh_devices);
   static console_state *open_shared_console (HWND hw, HANDLE& h)
@@ -2341,6 +2343,8 @@ class fhandler_pty_slave: public fhandler_pty_common
   void fch_close_handles ();
 
  public:
+  pid_t tc_getpgid () { return _tc ? _tc->pgid : 0; }
+
   struct handle_set_t
   {
     HANDLE from_master_nat;
diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc
index 3b54309a2..fb3d09d84 100644
--- a/winsup/cygwin/spawn.cc
+++ b/winsup/cygwin/spawn.cc
@@ -564,7 +564,7 @@ child_info_spawn::worker (const char *prog_arg, const char *const *argv,
 	 because the Ctrl-C event is sent to all processes in the console, unless
 	 they ignore it explicitely.  CREATE_NEW_PROCESS_GROUP does that for us. */
       pid_t ctty_pgid =
-	::cygheap->ctty ? ::cygheap->ctty->tc ()->getpgid () : 0;
+	::cygheap->ctty ? ::cygheap->ctty->tc_getpgid () : 0;
       if (!iscygwin () && ctty_pgid && ctty_pgid != myself->pgid)
 	c_flags |= CREATE_NEW_PROCESS_GROUP;
       refresh_cygheap ();


                 reply	other threads:[~2022-03-10 11:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220310114947.4A6AA3857C42@sourceware.org \
    --to=tyan0@sourceware.org \
    --cc=cygwin-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).