summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakashi Yano <takashi.yano@nifty.ne.jp>2019-09-18 23:29:17 +0900
committerKen Brown <kbrown@cornell.edu>2019-09-20 16:18:47 -0400
commit831b1569dc8a1ab9a9767f525eca17fccdb3e0d0 (patch)
tree435f0a2db1e1e7244bf2bd810ba8e511d2696b71
parent1a44ad03e0f723e9479d090c43444bce2798a35d (diff)
downloadcygnal-831b1569dc8a1ab9a9767f525eca17fccdb3e0d0.tar.gz
cygnal-831b1569dc8a1ab9a9767f525eca17fccdb3e0d0.tar.bz2
cygnal-831b1569dc8a1ab9a9767f525eca17fccdb3e0d0.zip
Cygwin: pty: Avoid potential segfault in PTY code when ppid = 1.
-rw-r--r--winsup/cygwin/fhandler_tty.cc11
1 files 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;