avoid fd_set size overflow. from deraadt@openbsd, sync with kame.

This commit is contained in:
itojun 2000-10-07 06:41:37 +00:00
parent c0de460728
commit 829f1b8451
2 changed files with 34 additions and 10 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.3 2000/02/25 08:52:04 mycroft Exp $
# $NetBSD: Makefile,v 1.4 2000/10/07 06:41:37 itojun Exp $
PROG= traceroute6
MAN= traceroute6.8
@ -10,4 +10,7 @@ CPPFLAGS+=-DINET6 -DIPSEC
LDADD+= -lipsec
DPADD+= ${LIBIPSEC}
# it seems that, if we use poll(2), the timing changes. commented out for now
#CPPFLAGS+=-DHAVE_POLL
.include <bsd.prog.mk>

View File

@ -1,5 +1,5 @@
/* $NetBSD: traceroute6.c,v 1.13 2000/07/07 12:22:32 itojun Exp $ */
/* $KAME: traceroute6.c,v 1.32 2000/07/07 12:21:34 itojun Exp $ */
/* $NetBSD: traceroute6.c,v 1.14 2000/10/07 06:41:37 itojun Exp $ */
/* $KAME: traceroute6.c,v 1.33 2000/10/07 06:22:55 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -79,7 +79,7 @@ static char sccsid[] = "@(#)traceroute.c 8.1 (Berkeley) 6/6/93";
#else
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: traceroute6.c,v 1.13 2000/07/07 12:22:32 itojun Exp $");
__RCSID("$NetBSD: traceroute6.c,v 1.14 2000/10/07 06:41:37 itojun Exp $");
#endif
#endif
@ -268,6 +268,9 @@ __RCSID("$NetBSD: traceroute6.c,v 1.13 2000/07/07 12:22:32 itojun Exp $");
#include <netdb.h>
#include <stdio.h>
#include <err.h>
#ifdef HAVE_POLL
#include <poll.h>
#endif
#include <errno.h>
#include <stdlib.h>
#include <string.h>
@ -873,18 +876,36 @@ wait_for_reply(sock, mhdr)
int sock;
struct msghdr *mhdr;
{
fd_set fds;
struct timeval wait;
#ifdef HAVE_POLL
struct pollfd pfd[1];
int cc = 0;
FD_ZERO(&fds);
FD_SET(sock, &fds);
wait.tv_sec = waittime; wait.tv_usec = 0;
pfd[0].fd = sock;
pfd[0].events = POLLIN;
pfd[0].revents = 0;
if (select(sock+1, &fds, (fd_set *)0, (fd_set *)0, &wait) > 0)
if (poll(pfd, 1, waittime * 1000) > 0)
cc = recvmsg(rcvsock, mhdr, 0);
return(cc);
#else
fd_set *fdsp;
struct timeval wait;
int cc = 0, fdsn;
fdsn = howmany(sock+1, NFDBITS) * sizeof(fd_mask);
if ((fdsp = (fd_set *)malloc(fdsn)) == NULL)
err(1, "malloc");
memset(fdsp, 0, fdsn);
FD_SET(sock, fdsp);
wait.tv_sec = waittime; wait.tv_usec = 0;
if (select(sock+1, fdsp, (fd_set *)0, (fd_set *)0, &wait) > 0)
cc = recvmsg(rcvsock, mhdr, 0);
free(fdsp);
return(cc);
#endif
}
#ifdef IPSEC