- (djm) Use ttyname() to determine name of tty returned by openpty()

rather then risking overflow. Patch from Marek Michalkiewicz
   <marekm@amelek.gda.pl>
This commit is contained in:
Damien Miller 2001-02-18 12:49:35 +11:00
parent b3ffc5f1d4
commit 99e924357e
2 changed files with 11 additions and 4 deletions

View File

@ -9,6 +9,9 @@
Miskiewicz <misiek@pld.ORG.PL> Miskiewicz <misiek@pld.ORG.PL>
- (djm) Robustify EGD/PRNGd code in face of socket closures. Patch from - (djm) Robustify EGD/PRNGd code in face of socket closures. Patch from
Todd C. Miller <Todd.Miller@courtesan.com> Todd C. Miller <Todd.Miller@courtesan.com>
- (djm) Use ttyname() to determine name of tty returned by openpty()
rather then risking overflow. Patch from Marek Michalkiewicz
<marekm@amelek.gda.pl>
20010217 20010217
- (bal) OpenBSD Sync: - (bal) OpenBSD Sync:
@ -4016,4 +4019,4 @@
- Wrote replacements for strlcpy and mkdtemp - Wrote replacements for strlcpy and mkdtemp
- Released 1.0pre1 - Released 1.0pre1
$Id: ChangeLog,v 1.787 2001/02/18 01:44:29 djm Exp $ $Id: ChangeLog,v 1.788 2001/02/18 01:49:35 djm Exp $

10
pty.c
View File

@ -49,15 +49,19 @@ pty_allocate(int *ptyfd, int *ttyfd, char *namebuf, int namebuflen)
{ {
#if defined(HAVE_OPENPTY) || defined(BSD4_4) #if defined(HAVE_OPENPTY) || defined(BSD4_4)
/* openpty(3) exists in OSF/1 and some other os'es */ /* openpty(3) exists in OSF/1 and some other os'es */
char buf[64]; char *name;
int i; int i;
i = openpty(ptyfd, ttyfd, buf, NULL, NULL); i = openpty(ptyfd, ttyfd, NULL, NULL, NULL);
if (i < 0) { if (i < 0) {
error("openpty: %.100s", strerror(errno)); error("openpty: %.100s", strerror(errno));
return 0; return 0;
} }
strlcpy(namebuf, buf, namebuflen); /* possible truncation */ name = ttyname(*ttyfd);
if (!name)
fatal("openpty returns device for which ttyname fails.");
strlcpy(namebuf, name, namebuflen); /* possible truncation */
return 1; return 1;
#else /* HAVE_OPENPTY */ #else /* HAVE_OPENPTY */
#ifdef HAVE__GETPTY #ifdef HAVE__GETPTY