From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7868) id 4A6AA3857C42; Thu, 10 Mar 2022 11:49:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4A6AA3857C42 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Takashi Yano To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin/cygwin-3_3-branch] Cygwin: console, pty: Fix segfault in child_info_spawn::worker(). X-Act-Checkin: newlib-cygwin X-Git-Author: Takashi Yano X-Git-Refname: refs/heads/cygwin-3_3-branch X-Git-Oldrev: 46c7e2f793cd6ef991fa9c887cec1cfb13263e8f X-Git-Newrev: 7dadbf800505a94079901370e737d3de28673c6e Message-Id: <20220310114947.4A6AA3857C42@sourceware.org> Date: Thu, 10 Mar 2022 11:49:47 +0000 (GMT) X-BeenThere: cygwin-cvs@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin core component git logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Mar 2022 11:49:47 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D7dadbf80050= 5a94079901370e737d3de28673c6e commit 7dadbf800505a94079901370e737d3de28673c6e Author: Takashi Yano Date: Thu Mar 10 20:20:00 2022 +0900 Cygwin: console, pty: Fix segfault in child_info_spawn::worker(). =20 - 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. =20 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 }; =20 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); =20 public: - static pid_t tc_getpgid () + pid_t tc_getpgid () { - return shared_console_info ? shared_console_info->tty_min_state.getpgi= d () : 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 (); =20 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 c= har *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 =3D - ::cygheap->ctty ? ::cygheap->ctty->tc ()->getpgid () : 0; + ::cygheap->ctty ? ::cygheap->ctty->tc_getpgid () : 0; if (!iscygwin () && ctty_pgid && ctty_pgid !=3D myself->pgid) c_flags |=3D CREATE_NEW_PROCESS_GROUP; refresh_cygheap ();