This is the mail archive of the
cygwin-patches
mailing list for the Cygwin project.
[PATCH 1/5] Cygwin: pty: Avoid potential segfault in PTY code when ppid = 1.
- 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: Wed, 18 Sep 2019 23:29:17 +0900
- Subject: [PATCH 1/5] Cygwin: pty: Avoid potential segfault in PTY code when ppid = 1.
- Dkim-filter: OpenDKIM Filter v2.10.3 conuserg-06.nifty.com x8IETKDt031962
- References: <20190918142921.835-1-takashi.yano@nifty.ne.jp>
---
winsup/cygwin/fhandler_tty.cc | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index 659e7b595..2a1c34f7d 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -137,9 +137,16 @@ force_attach_to_pcon (HANDLE h)
/* If the process is running on a console,
the parent process should be attached
to the same console. */
- pinfo p (myself->ppid);
+ DWORD attach_wpid;
+ if (myself->ppid == 1)
+ attach_wpid = ATTACH_PARENT_PROCESS;
+ else
+ {
+ pinfo p (myself->ppid);
+ attach_wpid = p->dwProcessId;
+ }
FreeConsole ();
- if (AttachConsole (p->dwProcessId))
+ if (AttachConsole (attach_wpid))
{
pcon_attached_to = -1;
attach_done = true;
--
2.21.0