diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1998-01-23 03:54:06 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1998-01-23 03:54:06 +0000 |
commit | 7d4f9e2237e8e3847688484b4fe81181eef7ac6b (patch) | |
tree | d55aae24a4c55c63058df972e182875f5f05a6a7 /gnu | |
parent | a911936af4a9df244d448d45c97891f07298e690 (diff) |
Fix usage of select(2) to deal correctly with a high-numbered fd.
This change will be in sudo 1.5.5 but you saw it here first...
Diffstat (limited to 'gnu')
-rw-r--r-- | gnu/usr.bin/sudo/sudo/tgetpass.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/gnu/usr.bin/sudo/sudo/tgetpass.c b/gnu/usr.bin/sudo/sudo/tgetpass.c index e129c98a53b..1f7c5bc7537 100644 --- a/gnu/usr.bin/sudo/sudo/tgetpass.c +++ b/gnu/usr.bin/sudo/sudo/tgetpass.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tgetpass.c,v 1.5 1998/01/13 05:30:31 millert Exp $ */ +/* $OpenBSD: tgetpass.c,v 1.6 1998/01/23 03:54:05 millert Exp $ */ /* * CU sudo version 1.5.4 @@ -116,7 +116,7 @@ char * tgetpass(prompt, timeout, user, host) int n, echo; FILE *input, *output; static char buf[_PASSWD_LEN + 1]; - fd_set readfds; + fd_set *readfds; struct timeval tv; char *p; @@ -201,8 +201,14 @@ char * tgetpass(prompt, timeout, user, host) */ if (timeout > 0) { /* setup for select(2) */ - FD_ZERO(&readfds); - FD_SET(fileno(input), &readfds); + n = howmany(fileno(input) + 1, NFDBITS) * sizeof(fd_mask); + if ((readfds = (fd_set *) malloc(n)) == NULL) { + (void) fprintf(stderr, "Cannot allocate memory: "); + perror(""); + return(NULL); + } + (void) memset((VOID *)readfds, 0, n); + FD_SET(fileno(input), readfds); /* set timeout for select */ tv.tv_sec = timeout; @@ -212,12 +218,13 @@ char * tgetpass(prompt, timeout, user, host) * get password or return empty string if nothing to read by timeout */ buf[0] = '\0'; - if (select(fileno(input) + 1, &readfds, 0, 0, &tv) > 0 && + if (select(fileno(input) + 1, readfds, 0, 0, &tv) > 0 && fgets(buf, sizeof(buf), input)) { n = strlen(buf); if (buf[n - 1] == '\n') buf[n - 1] = '\0'; } + (void) free(readfds); } else { buf[0] = '\0'; if (fgets(buf, sizeof(buf), input)) { |