avoid fd_set overflow. see openbsd select(2).
This commit is contained in:
parent
d074de9004
commit
794318ceff
|
@ -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
|
* Copyright (c) 1989, 1993
|
||||||
|
@ -62,7 +62,7 @@
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
#ifndef lint
|
#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
|
#endif
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -666,8 +666,8 @@ doit(void)
|
||||||
int fromlen;
|
int fromlen;
|
||||||
double sec, last, d_last;
|
double sec, last, d_last;
|
||||||
struct timeval timeout;
|
struct timeval timeout;
|
||||||
fd_set fdmask;
|
fd_set *fdmaskp;
|
||||||
|
size_t nfdmask;
|
||||||
|
|
||||||
(void)gettimeofday(&clear_cache,0);
|
(void)gettimeofday(&clear_cache,0);
|
||||||
if (maxwait != 0) {
|
if (maxwait != 0) {
|
||||||
|
@ -678,7 +678,10 @@ doit(void)
|
||||||
d_last = 365*24*60*60;
|
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 {
|
do {
|
||||||
(void)gettimeofday(&now,0);
|
(void)gettimeofday(&now,0);
|
||||||
|
|
||||||
|
@ -713,8 +716,8 @@ doit(void)
|
||||||
|
|
||||||
sec_to_timeval(sec, &timeout);
|
sec_to_timeval(sec, &timeout);
|
||||||
|
|
||||||
FD_SET(s, &fdmask);
|
FD_SET(s, fdmaskp);
|
||||||
cc = select(s+1, &fdmask, 0, 0, &timeout);
|
cc = select(s+1, fdmaskp, 0, 0, &timeout);
|
||||||
if (cc <= 0) {
|
if (cc <= 0) {
|
||||||
if (cc < 0) {
|
if (cc < 0) {
|
||||||
if (errno == EINTR)
|
if (errno == EINTR)
|
||||||
|
@ -742,6 +745,7 @@ doit(void)
|
||||||
|
|
||||||
} while (nreceived < npackets
|
} while (nreceived < npackets
|
||||||
&& (nreceived == 0 || !(pingflags & F_ONCE)));
|
&& (nreceived == 0 || !(pingflags & F_ONCE)));
|
||||||
|
free(fdmaskp);
|
||||||
|
|
||||||
finish(0);
|
finish(0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue