diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1997-12-16 22:07:39 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1997-12-16 22:07:39 +0000 |
commit | 0f171fd05e20dd83adf32030261db40160a2eb69 (patch) | |
tree | 3378796a248c94f98e55aeb46b8a09c90e7e2d8b | |
parent | 45f6df326c4f1176d7994685b33d532fe5d0f713 (diff) |
do not let fd_set overflow
-rw-r--r-- | usr.bin/telnet/network.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/usr.bin/telnet/network.c b/usr.bin/telnet/network.c index 14fecdfa5bd..e7f3d94ffb0 100644 --- a/usr.bin/telnet/network.c +++ b/usr.bin/telnet/network.c @@ -1,4 +1,4 @@ -/* $OpenBSD: network.c,v 1.3 1996/12/12 11:35:59 robin Exp $ */ +/* $OpenBSD: network.c,v 1.4 1997/12/16 22:07:38 deraadt Exp $ */ /* $NetBSD: network.c,v 1.5 1996/02/28 21:04:06 thorpej Exp $ */ /* @@ -39,7 +39,7 @@ static char sccsid[] = "@(#)network.c 8.2 (Berkeley) 12/15/93"; static char rcsid[] = "$NetBSD: network.c,v 1.5 1996/02/28 21:04:06 thorpej Exp $"; #else -static char rcsid[] = "$OpenBSD: network.c,v 1.3 1996/12/12 11:35:59 robin Exp $"; +static char rcsid[] = "$OpenBSD: network.c,v 1.4 1997/12/16 22:07:38 deraadt Exp $"; #endif #endif /* not lint */ @@ -86,23 +86,31 @@ init_network() stilloob() { static struct timeval timeout = { 0 }; - fd_set excepts; + fd_set *fdsp; + int fdsn; int value; + fdsn = howmany(net+1, NFDBITS) * sizeof(fd_mask); + if ((fdsp = (fd_set *)malloc(fdsn)) == NULL) + err(1, "malloc"); + do { - FD_ZERO(&excepts); - FD_SET(net, &excepts); - value = select(net+1, (fd_set *)0, (fd_set *)0, &excepts, &timeout); + memset(fdsp, 0, fdsn); + FD_SET(net, fdsp); + value = select(net+1, (fd_set *)0, (fd_set *)0, fdsp, &timeout); } while ((value == -1) && (errno == EINTR)); if (value < 0) { perror("select"); + free(fdsp); (void) quit(); /* NOTREACHED */ } - if (FD_ISSET(net, &excepts)) { + if (FD_ISSET(net, fdsp)) { + free(fdsp); return 1; } else { + free(fdsp); return 0; } } |