summaryrefslogtreecommitdiff
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
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>
-rw-r--r--ChangeLog5
-rw-r--r--pty.c10
2 files changed, 11 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index b0da442c9..130a8f395 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -9,6 +9,9 @@
9 Miskiewicz <misiek@pld.ORG.PL> 9 Miskiewicz <misiek@pld.ORG.PL>
10 - (djm) Robustify EGD/PRNGd code in face of socket closures. Patch from 10 - (djm) Robustify EGD/PRNGd code in face of socket closures. Patch from
11 Todd C. Miller <Todd.Miller@courtesan.com> 11 Todd C. Miller <Todd.Miller@courtesan.com>
12 - (djm) Use ttyname() to determine name of tty returned by openpty()
13 rather then risking overflow. Patch from Marek Michalkiewicz
14 <marekm@amelek.gda.pl>
12 15
1320010217 1620010217
14 - (bal) OpenBSD Sync: 17 - (bal) OpenBSD Sync:
@@ -4016,4 +4019,4 @@
4016 - Wrote replacements for strlcpy and mkdtemp 4019 - Wrote replacements for strlcpy and mkdtemp
4017 - Released 1.0pre1 4020 - Released 1.0pre1
4018 4021
4019$Id: ChangeLog,v 1.787 2001/02/18 01:44:29 djm Exp $ 4022$Id: ChangeLog,v 1.788 2001/02/18 01:49:35 djm Exp $
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