From 794318ceff42d722690e5cf02d2e00d193642ef3 Mon Sep 17 00:00:00 2001 From: itojun Date: Sat, 7 Oct 2000 06:50:43 +0000 Subject: [PATCH] avoid fd_set overflow. see openbsd select(2). --- sbin/ping/ping.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/sbin/ping/ping.c b/sbin/ping/ping.c index 8e929cbb2a74..2e25b352b568 100644 --- a/sbin/ping/ping.c +++ b/sbin/ping/ping.c @@ -1,4 +1,4 @@ -/* $NetBSD: ping.c,v 1.55 2000/01/31 14:24:23 itojun Exp $ */ +/* $NetBSD: ping.c,v 1.56 2000/10/07 06:50:43 itojun Exp $ */ /* * Copyright (c) 1989, 1993 @@ -62,7 +62,7 @@ #include #ifndef lint -__RCSID("$NetBSD: ping.c,v 1.55 2000/01/31 14:24:23 itojun Exp $"); +__RCSID("$NetBSD: ping.c,v 1.56 2000/10/07 06:50:43 itojun Exp $"); #endif #include @@ -666,8 +666,8 @@ doit(void) int fromlen; double sec, last, d_last; struct timeval timeout; - fd_set fdmask; - + fd_set *fdmaskp; + size_t nfdmask; (void)gettimeofday(&clear_cache,0); if (maxwait != 0) { @@ -678,7 +678,10 @@ doit(void) d_last = 365*24*60*60; } - FD_ZERO(&fdmask); + nfdmask = howmany(s + 1, NFDBITS); + if ((fdmaskp = malloc(nfdmask)) == NULL) + err(1, "malloc"); + memset(fdmaskp, 0, nfdmask); do { (void)gettimeofday(&now,0); @@ -713,8 +716,8 @@ doit(void) sec_to_timeval(sec, &timeout); - FD_SET(s, &fdmask); - cc = select(s+1, &fdmask, 0, 0, &timeout); + FD_SET(s, fdmaskp); + cc = select(s+1, fdmaskp, 0, 0, &timeout); if (cc <= 0) { if (cc < 0) { if (errno == EINTR) @@ -742,6 +745,7 @@ doit(void) } while (nreceived < npackets && (nreceived == 0 || !(pingflags & F_ONCE))); + free(fdmaskp); finish(0); }