diff options
-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)) { |