diff options
author | 1999-12-06 12:10:12 +0000 | |
---|---|---|
committer | 1999-12-06 12:10:12 +0000 | |
commit | a83369d6527c958a069dbd0c0def1612c1d8777b (patch) | |
tree | a39473e30921ebd5ea1c71c3f1e90af08f4ccb16 | |
parent | display great hatred towards strcpy (diff) | |
download | wireguard-openbsd-a83369d6527c958a069dbd0c0def1612c1d8777b.tar.xz wireguard-openbsd-a83369d6527c958a069dbd0c0def1612c1d8777b.zip |
use openpty() if it exists (it does on BSD4_4)
-rw-r--r-- | usr.bin/ssh/pty.c | 20 | ||||
-rw-r--r-- | usr.bin/ssh/pty.h | 4 | ||||
-rw-r--r-- | usr.bin/ssh/sshd.c | 5 |
3 files changed, 16 insertions, 13 deletions
diff --git a/usr.bin/ssh/pty.c b/usr.bin/ssh/pty.c index d52591507d1..055e7959bb9 100644 --- a/usr.bin/ssh/pty.c +++ b/usr.bin/ssh/pty.c @@ -14,7 +14,7 @@ */ #include "includes.h" -RCSID("$Id: pty.c,v 1.8 1999/11/24 19:53:48 markus Exp $"); +RCSID("$Id: pty.c,v 1.9 1999/12/06 12:10:12 deraadt Exp $"); #include "pty.h" #include "ssh.h" @@ -36,17 +36,19 @@ RCSID("$Id: pty.c,v 1.8 1999/11/24 19:53:48 markus Exp $"); */ int -pty_allocate(int *ptyfd, int *ttyfd, char *namebuf) +pty_allocate(int *ptyfd, int *ttyfd, char *namebuf, int namebuflen) { -#ifdef HAVE_OPENPTY +#if defined(HAVE_OPENPTY) || defined(BSD4_4) /* openpty(3) exists in OSF/1 and some other os'es */ + char buf[64]; int i; - i = openpty(ptyfd, ttyfd, namebuf, NULL, NULL); + i = openpty(ptyfd, ttyfd, buf, NULL, NULL); if (i < 0) { error("openpty: %.100s", strerror(errno)); return 0; } + strlcpy(namebuf, buf, namebuflen); /* possible truncation */ return 1; #else /* HAVE_OPENPTY */ #ifdef HAVE__GETPTY @@ -61,7 +63,7 @@ pty_allocate(int *ptyfd, int *ttyfd, char *namebuf) error("_getpty: %.100s", strerror(errno)); return 0; } - strcpy(namebuf, slave); + strlcpy(namebuf, slave, namebuflen); /* Open the slave side. */ *ttyfd = open(namebuf, O_RDWR | O_NOCTTY); if (*ttyfd < 0) { @@ -95,7 +97,7 @@ pty_allocate(int *ptyfd, int *ttyfd, char *namebuf) pts = ptsname(ptm); if (pts == NULL) error("Slave pty side name could not be obtained."); - strcpy(namebuf, pts); + strlcpy(namebuf, pts, namebuflen); *ptyfd = ptm; /* Open the slave side. */ @@ -126,7 +128,7 @@ pty_allocate(int *ptyfd, int *ttyfd, char *namebuf) name = ttyname(*ptyfd); if (!name) fatal("Open of /dev/ptc returns device for which ttyname fails."); - strcpy(namebuf, name); + strlcpy(namebuf, name, namebuflen); *ttyfd = open(name, O_RDWR | O_NOCTTY); if (*ttyfd < 0) { error("Could not open pty slave side %.100s: %.100s", @@ -150,8 +152,8 @@ pty_allocate(int *ptyfd, int *ttyfd, char *namebuf) *ptyfd = open(buf, O_RDWR | O_NOCTTY); if (*ptyfd < 0) continue; - snprintf(namebuf, sizeof buf, "/dev/tty%c%c", ptymajors[i / num_minors], - ptyminors[i % num_minors]); + snprintf(namebuf, sizeof namebuflen, "/dev/tty%c%c", + ptymajors[i / num_minors], ptyminors[i % num_minors]); /* Open the slave side. */ *ttyfd = open(namebuf, O_RDWR | O_NOCTTY); diff --git a/usr.bin/ssh/pty.h b/usr.bin/ssh/pty.h index 49c7d1bca85..58d1184a3aa 100644 --- a/usr.bin/ssh/pty.h +++ b/usr.bin/ssh/pty.h @@ -13,7 +13,7 @@ * tty. */ -/* RCSID("$Id: pty.h,v 1.3 1999/11/24 19:53:49 markus Exp $"); */ +/* RCSID("$Id: pty.h,v 1.4 1999/12/06 12:10:12 deraadt Exp $"); */ #ifndef PTY_H #define PTY_H @@ -24,7 +24,7 @@ * descriptors for the pty and tty sides and the name of the tty side are * returned (the buffer must be able to hold at least 64 characters). */ -int pty_allocate(int *ptyfd, int *ttyfd, char *ttyname); +int pty_allocate(int *ptyfd, int *ttyfd, char *ttyname, int ttynamelen); /* * Releases the tty. Its ownership is returned to root, and permissions to diff --git a/usr.bin/ssh/sshd.c b/usr.bin/ssh/sshd.c index 27977aafb87..90a3a8c7105 100644 --- a/usr.bin/ssh/sshd.c +++ b/usr.bin/ssh/sshd.c @@ -11,7 +11,7 @@ */ #include "includes.h" -RCSID("$Id: sshd.c,v 1.66 1999/11/24 19:53:53 markus Exp $"); +RCSID("$Id: sshd.c,v 1.67 1999/12/06 12:10:12 deraadt Exp $"); #include "xmalloc.h" #include "rsa.h" @@ -1525,7 +1525,8 @@ do_authenticated(struct passwd * pw) debug("Allocating pty."); /* Allocate a pty and open it. */ - if (!pty_allocate(&ptyfd, &ttyfd, ttyname)) { + if (!pty_allocate(&ptyfd, &ttyfd, ttyname, + sizeof(ttyname))) { error("Failed to allocate pty."); goto fail; } |