avoid fd_set overflow. see openbsd select(2).
XXX should we use poll(2)?
This commit is contained in:
parent
794318ceff
commit
6626345485
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: traceroute.c,v 1.40 2000/09/30 12:44:37 sommerfeld Exp $ */
|
/* $NetBSD: traceroute.c,v 1.41 2000/10/07 06:53:41 itojun Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1988, 1989, 1991, 1994, 1995, 1996, 1997
|
* Copyright (c) 1988, 1989, 1991, 1994, 1995, 1996, 1997
|
||||||
|
@ -29,7 +29,7 @@ static const char rcsid[] =
|
||||||
#else
|
#else
|
||||||
__COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1991, 1994, 1995, 1996, 1997\n\
|
__COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1991, 1994, 1995, 1996, 1997\n\
|
||||||
The Regents of the University of California. All rights reserved.\n");
|
The Regents of the University of California. All rights reserved.\n");
|
||||||
__RCSID("$NetBSD: traceroute.c,v 1.40 2000/09/30 12:44:37 sommerfeld Exp $");
|
__RCSID("$NetBSD: traceroute.c,v 1.41 2000/10/07 06:53:41 itojun Exp $");
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1004,22 +1004,29 @@ int
|
||||||
wait_for_reply(register int sock, register struct sockaddr_in *fromp,
|
wait_for_reply(register int sock, register struct sockaddr_in *fromp,
|
||||||
register struct timeval *tp)
|
register struct timeval *tp)
|
||||||
{
|
{
|
||||||
fd_set fds;
|
fd_set *fdsp;
|
||||||
|
size_t nfds;
|
||||||
struct timeval now, wait;
|
struct timeval now, wait;
|
||||||
struct timezone tz;
|
struct timezone tz;
|
||||||
register int cc = 0;
|
register int cc = 0;
|
||||||
int fromlen = sizeof(*fromp);
|
int fromlen = sizeof(*fromp);
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
FD_ZERO(&fds);
|
nfds = howmany(sock + 1, NFDBITS);
|
||||||
FD_SET(sock, &fds);
|
if ((fdsp = malloc(nfds)) == NULL) {
|
||||||
|
Fprintf(stderr, "%s: malloc: %s\n", prog, strerror(errno));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
memset(fdsp, 0, nfds);
|
||||||
|
FD_SET(sock, fdsp);
|
||||||
|
|
||||||
wait.tv_sec = tp->tv_sec + waittime;
|
wait.tv_sec = tp->tv_sec + waittime;
|
||||||
wait.tv_usec = tp->tv_usec;
|
wait.tv_usec = tp->tv_usec;
|
||||||
(void)gettimeofday(&now, &tz);
|
(void)gettimeofday(&now, &tz);
|
||||||
tvsub(&wait, &now);
|
tvsub(&wait, &now);
|
||||||
|
|
||||||
retval = select(sock + 1, &fds, NULL, NULL, &wait);
|
retval = select(sock + 1, fdsp, NULL, NULL, &wait);
|
||||||
|
free(fdsp);
|
||||||
if (retval < 0) {
|
if (retval < 0) {
|
||||||
/* If we continue, we probably just flood the remote host. */
|
/* If we continue, we probably just flood the remote host. */
|
||||||
Fprintf(stderr, "%s: select: %s\n", prog, strerror(errno));
|
Fprintf(stderr, "%s: select: %s\n", prog, strerror(errno));
|
||||||
|
|
Loading…
Reference in New Issue