summaryrefslogtreecommitdiff
path: root/usr.bin/ssh/pty.c
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1999-12-06 12:10:13 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1999-12-06 12:10:13 +0000
commita8021a4383495f7d7cbf25ac52378e30817e4ebd (patch)
treedb25366077c1db747211dc80dcc856dc96d3ddb4 /usr.bin/ssh/pty.c
parent48cffe96c55ebc8216341935f9ce5b181da10480 (diff)
use openpty() if it exists (it does on BSD4_4)
Diffstat (limited to 'usr.bin/ssh/pty.c')
-rw-r--r--usr.bin/ssh/pty.c20
1 files changed, 11 insertions, 9 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);