|
Lines 41-57
Link Here
|
| 41 |
pty_allocate(int *ptyfd, int *ttyfd, char *namebuf, int namebuflen) |
41 |
pty_allocate(int *ptyfd, int *ttyfd, char *namebuf, int namebuflen) |
| 42 |
{ |
42 |
{ |
| 43 |
/* openpty(3) exists in OSF/1 and some other os'es */ |
43 |
/* openpty(3) exists in OSF/1 and some other os'es */ |
| 44 |
char *name; |
44 |
/* |
|
|
45 |
* ttyname() may fail due to different sshd code paths. However, |
| 46 |
* we can just get the tty name from openpty() and avoid ttyname(). |
| 47 |
*/ |
| 48 |
char name[64]; |
| 45 |
int i; |
49 |
int i; |
| 46 |
|
50 |
|
| 47 |
i = openpty(ptyfd, ttyfd, NULL, NULL, NULL); |
51 |
i = openpty(ptyfd, ttyfd, name, NULL, NULL); |
| 48 |
if (i < 0) { |
52 |
if (i < 0) { |
| 49 |
error("openpty: %.100s", strerror(errno)); |
53 |
error("openpty: %.100s", strerror(errno)); |
| 50 |
return 0; |
54 |
return 0; |
| 51 |
} |
55 |
} |
| 52 |
name = ttyname(*ttyfd); |
|
|
| 53 |
if (!name) |
| 54 |
fatal("openpty returns device for which ttyname fails."); |
| 55 |
|
56 |
|
| 56 |
strlcpy(namebuf, name, namebuflen); /* possible truncation */ |
57 |
strlcpy(namebuf, name, namebuflen); /* possible truncation */ |
| 57 |
return 1; |
58 |
return 1; |