Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-1-5]: src/usr.sbin/traceroute6 Pullup 1.14 [itojun]:



details:   https://anonhg.NetBSD.org/src/rev/05f7911e1363
branches:  netbsd-1-5
changeset: 489861:05f7911e1363
user:      tv <tv%NetBSD.org@localhost>
date:      Wed Oct 18 02:03:03 2000 +0000

description:
Pullup 1.14 [itojun]:
avoid fd_set size overflow.  from deraadt@openbsd, sync with kame.

diffstat:

 usr.sbin/traceroute6/traceroute6.c |  39 +++++++++++++++++++++++++++++--------
 1 files changed, 30 insertions(+), 9 deletions(-)

diffs (73 lines):

diff -r 0f3039a5e81a -r 05f7911e1363 usr.sbin/traceroute6/traceroute6.c
--- a/usr.sbin/traceroute6/traceroute6.c        Wed Oct 18 02:02:48 2000 +0000
+++ b/usr.sbin/traceroute6/traceroute6.c        Wed Oct 18 02:03:03 2000 +0000
@@ -1,5 +1,5 @@
-/*     $NetBSD: traceroute6.c,v 1.11.2.2 2000/07/27 16:25:18 itojun Exp $      */
-/*     $KAME: traceroute6.c,v 1.30 2000/06/30 18:56:01 itojun Exp $    */
+/*     $NetBSD: traceroute6.c,v 1.11.2.3 2000/10/18 02:03:03 tv 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 @@
 #else
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: traceroute6.c,v 1.11.2.2 2000/07/27 16:25:18 itojun Exp $");
+__RCSID("$NetBSD: traceroute6.c,v 1.11.2.3 2000/10/18 02:03:03 tv Exp $");
 #endif
 #endif
 
@@ -268,6 +268,9 @@
 #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 @@
        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



Home | Main Index | Thread Index | Old Index