diff options
author | Damien Miller <djm@mindrot.org> | 2001-02-18 12:49:35 +1100 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2001-02-18 12:49:35 +1100 |
commit | 99e924357eaf5a3f63028d741071370e22746e9c (patch) | |
tree | 2cfd1a65b3df469378dcc1a5ec15dc88bb02b2ef /pty.c | |
parent | b3ffc5f1d4f630521e5ad4787db1f691942b8592 (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.c | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -49,15 +49,19 @@ pty_allocate(int *ptyfd, int *ttyfd, char *namebuf, int namebuflen) { #if defined(HAVE_OPENPTY) || defined(BSD4_4) /* openpty(3) exists in OSF/1 and some other os'es */ - char buf[64]; + char *name; int i; - i = openpty(ptyfd, ttyfd, buf, NULL, NULL); + i = openpty(ptyfd, ttyfd, NULL, NULL, NULL); if (i < 0) { error("openpty: %.100s", strerror(errno)); 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; #else /* HAVE_OPENPTY */ #ifdef HAVE__GETPTY |