summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtur Grabowski <art@cvs.openbsd.org>2000-10-06 10:58:20 +0000
committerArtur Grabowski <art@cvs.openbsd.org>2000-10-06 10:58:20 +0000
commit97e98307ffc3f7ea7933b81620c0fa0898d7747b (patch)
tree023e709ab2d7e5ecea2a219729b37f5e1f6e813b
parent1c91100a7942ff31b1fa5e3c8e09c3306b1776bc (diff)
Avoid fd_set overflow. (just like in ping).
-rw-r--r--sbin/ping6/ping6.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/sbin/ping6/ping6.c b/sbin/ping6/ping6.c
index 3a2ed343dac..81961082a67 100644
--- a/sbin/ping6/ping6.c
+++ b/sbin/ping6/ping6.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ping6.c,v 1.11 2000/08/14 02:50:04 itojun Exp $ */
+/* $OpenBSD: ping6.c,v 1.12 2000/10/06 10:58:19 art Exp $ */
/* $KAME: ping6.c,v 1.74 2000/08/14 02:48:14 itojun Exp $ */
/*
@@ -280,7 +280,8 @@ main(argc, argv)
struct sockaddr_in6 from;
struct timeval timeout;
struct addrinfo hints;
- fd_set fdset;
+ fd_set *fdmaskp;
+ int fdmasks;
register int cc, i;
int ch, fromlen, hold, packlen, preload, optval, ret_ga;
u_char *datap, *packet;
@@ -924,9 +925,10 @@ main(argc, argv)
(void)setitimer(ITIMER_REAL, &itimer, NULL);
}
- FD_ZERO(&fdset);
- timeout.tv_sec = 0;
- timeout.tv_usec = 10000;
+ fdmasks = howmany(s+1, NFDBITS);
+ if ((fdmaskp = malloc(fdmasks)) == NULL)
+ err(1, "malloc");
+
for (;;) {
struct msghdr m;
struct cmsghdr *cm;
@@ -935,8 +937,11 @@ main(argc, argv)
if (options & F_FLOOD) {
pinger();
- FD_SET(s, &fdset);
- if (select(s + 1, &fdset, NULL, NULL, &timeout) < 1)
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 10000;
+ memset(fdmaskp, 0, fdmasks);
+ FD_SET(s, fdmaskp);
+ if (select(s + 1, fdmaskp, NULL, NULL, &timeout) < 1)
continue;
}
fromlen = sizeof(from);