public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin] Cygwin: pty: Avoid potential segfault in PTY code when ppid = 1.
@ 2019-09-20 21:59 Ken Brown
  0 siblings, 0 replies; only message in thread
From: Ken Brown @ 2019-09-20 21:59 UTC (permalink / raw)
  To: cygwin-cvs

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

commit 831b1569dc8a1ab9a9767f525eca17fccdb3e0d0
Author: Takashi Yano <takashi.yano@nifty.ne.jp>
Date:   Wed Sep 18 23:29:17 2019 +0900

    Cygwin: pty: Avoid potential segfault in PTY code when ppid = 1.

Diff:
---
 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 659e7b5..2a1c34f 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;


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-09-20 21:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-20 21:59 [newlib-cygwin] Cygwin: pty: Avoid potential segfault in PTY code when ppid = 1 Ken Brown

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).