summaryrefslogtreecommitdiff
path: root/pty.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2001-02-18 12:49:35 +1100
committerDamien Miller <djm@mindrot.org>2001-02-18 12:49:35 +1100
commit99e924357eaf5a3f63028d741071370e22746e9c (patch)
tree2cfd1a65b3df469378dcc1a5ec15dc88bb02b2ef /pty.c
parentb3ffc5f1d4f630521e5ad4787db1f691942b8592 (diff)
- (djm) Use ttyname() to determine name of tty returned by openpty()
rather then risking overflow. Patch from Marek Michalkiewicz <marekm@amelek.gda.pl>
Diffstat (limited to 'pty.c')
-rw-r--r--pty.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/pty.c b/pty.c
index e71bceb80..4b9370ce5 100644
--- a/pty.c
+++ b/pty.c
@@ -49,15 +49,19 @@ pty_allocate(int *ptyfd, int *ttyfd, char *namebuf, int namebuflen)
49{ 49{
50#if defined(HAVE_OPENPTY) || defined(BSD4_4) 50#if defined(HAVE_OPENPTY) || defined(BSD4_4)
51 /* openpty(3) exists in OSF/1 and some other os'es */ 51 /* openpty(3) exists in OSF/1 and some other os'es */
52 char buf[64]; 52 char *name;
53 int i; 53 int i;
54 54
55 i = openpty(ptyfd, ttyfd, buf, NULL, NULL); 55 i = openpty(ptyfd, ttyfd, NULL, NULL, NULL);
56 if (i < 0) { 56 if (i < 0) {
57 error("openpty: %.100s", strerror(errno)); 57 error("openpty: %.100s", strerror(errno));
58 return 0; 58 return 0;
59 } 59 }
60 strlcpy(namebuf, buf, namebuflen); /* possible truncation */ 60 name = ttyname(*ttyfd);
61 if (!name)
62 fatal("openpty returns device for which ttyname fails.");
63
64 strlcpy(namebuf, name, namebuflen); /* possible truncation */
61 return 1; 65 return 1;
62#else /* HAVE_OPENPTY */ 66#else /* HAVE_OPENPTY */
63#ifdef HAVE__GETPTY 67#ifdef HAVE__GETPTY