Module Name:    src
Committed By:   kamil
Date:           Sun Jun 24 09:30:26 UTC 2018

Modified Files:
        src/lib/libutil: pty.c

Log Message:
Fix stack use after scope in libutil/pty

The pt variable's elements are used after the end of the pt scope.
A move of pt to outer scope fixes this.

Detected with MKSANITIZER/ASan with tmux(1), a forkpty(3) user.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/lib/libutil/pty.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libutil/pty.c
diff -u src/lib/libutil/pty.c:1.31 src/lib/libutil/pty.c:1.32
--- src/lib/libutil/pty.c:1.31	Fri Feb 20 16:44:06 2009
+++ src/lib/libutil/pty.c	Sun Jun 24 09:30:26 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: pty.c,v 1.31 2009/02/20 16:44:06 christos Exp $	*/
+/*	$NetBSD: pty.c,v 1.32 2018/06/24 09:30:26 kamil Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993, 1994
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)pty.c	8.3 (Berkeley) 5/16/94";
 #else
-__RCSID("$NetBSD: pty.c,v 1.31 2009/02/20 16:44:06 christos Exp $");
+__RCSID("$NetBSD: pty.c,v 1.32 2018/06/24 09:30:26 kamil Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -70,6 +70,7 @@ openpty(int *amaster, int *aslave, char 
 	mode_t mode;
 	struct group grs, *grp;
 	char grbuf[1024];
+	struct ptmget pt;
 
 	_DIAGASSERT(amaster != NULL);
 	_DIAGASSERT(aslave != NULL);
@@ -78,7 +79,6 @@ openpty(int *amaster, int *aslave, char 
 	/* winp may be NULL */
 
 	if ((master = open("/dev/ptm", O_RDWR)) != -1) {
-		struct ptmget pt;
 		if (ioctl(master, TIOCPTMGET, &pt) != -1) {
 			(void)close(master);
 			master = pt.cfd;

Reply via email to