diff options
author | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2002-06-07 16:42:08 +0000 |
---|---|---|
committer | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2002-06-07 16:42:08 +0000 |
commit | 0789cf33529fb3d1ab4f0d12251a6c8cfc5a44f6 (patch) | |
tree | 67292ed62705bedcec5bd38f1fb510eac7ac52d4 /usr.sbin | |
parent | 429940db10521cedcfc7580aee589a7a551bf048 (diff) |
avoid fd_set overrun. sync w/kame
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/route6d/route6d.c | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/usr.sbin/route6d/route6d.c b/usr.sbin/route6d/route6d.c index 91342d74632..fc32b198f1a 100644 --- a/usr.sbin/route6d/route6d.c +++ b/usr.sbin/route6d/route6d.c @@ -1,5 +1,5 @@ -/* $OpenBSD: route6d.c,v 1.28 2002/05/29 23:09:03 itojun Exp $ */ -/* $KAME: route6d.c,v 1.81 2002/02/25 02:27:22 itojun Exp $ */ +/* $OpenBSD: route6d.c,v 1.29 2002/06/07 16:42:07 itojun Exp $ */ +/* $KAME: route6d.c,v 1.85 2002/06/07 16:39:41 itojun Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -31,7 +31,7 @@ */ #if 0 -static char _rcsid[] = "$OpenBSD: route6d.c,v 1.28 2002/05/29 23:09:03 itojun Exp $"; +static char _rcsid[] = "$OpenBSD: route6d.c,v 1.29 2002/06/07 16:42:07 itojun Exp $"; #endif #include <stdio.h> @@ -135,7 +135,9 @@ int nifc; /* number of valid ifc's */ struct ifc **index2ifc; int nindex2ifc; struct ifc *loopifcp = NULL; /* pointing to loopback */ -fd_set sockvec; /* vector to select() for receiving */ +fd_set *sockvecp; /* vector to select() for receiving */ +fd_set *recvecp; +int fdmasks; int rtsock; /* the routing socket */ int ripsock; /* socket to send/receive RIP datagram */ int maxfd; /* maximum fd for select() */ @@ -424,8 +426,6 @@ main(argc, argv) sigemptyset(&mask); sigaddset(&mask, SIGALRM); while (1) { - fd_set recvec; - if (seenalrm) { ripalarm(); seenalrm = 0; @@ -442,8 +442,8 @@ main(argc, argv) continue; } - FD_COPY(&sockvec, &recvec); - switch (select(maxfd + 1, &recvec, 0, 0, 0)) { + memcpy(recvecp, sockvecp, fdmasks); + switch (select(maxfd + 1, recvecp, 0, 0, 0)) { case -1: if (errno != EINTR) { fatal("select"); @@ -453,12 +453,12 @@ main(argc, argv) case 0: continue; default: - if (FD_ISSET(ripsock, &recvec)) { + if (FD_ISSET(ripsock, recvecp)) { sigprocmask(SIG_BLOCK, &mask, &omask); riprecv(); sigprocmask(SIG_SETMASK, &omask, NULL); } - if (FD_ISSET(rtsock, &recvec)) { + if (FD_ISSET(rtsock, recvecp)) { sigprocmask(SIG_BLOCK, &mask, &omask); rtrecv(); sigprocmask(SIG_SETMASK, &omask, NULL); @@ -636,12 +636,6 @@ init() } memcpy(&ripsin, res->ai_addr, res->ai_addrlen); -#ifdef FD_ZERO - FD_ZERO(&sockvec); -#else - memset(&sockvec, 0, sizeof(sockvec)); -#endif - FD_SET(ripsock, &sockvec); maxfd = ripsock; if (nflag == 0) { @@ -649,11 +643,24 @@ init() fatal("route socket"); /*NOTREACHED*/ } - FD_SET(rtsock, &sockvec); if (rtsock > maxfd) maxfd = rtsock; } else rtsock = -1; /*just for safety */ + + fdmasks = howmany(maxfd + 1, NFDBITS) * sizeof(fd_mask); + if ((sockvecp = malloc(fdmasks)) == NULL) { + fatal("malloc"); + /*NOTREACHED*/ + } + if ((recvecp = malloc(fdmasks)) == NULL) { + fatal("malloc"); + /*NOTREACHED*/ + } + memset(sockvecp, 0, fdmasks); + FD_SET(ripsock, sockvecp); + if (rtsock >= 0) + FD_SET(rtsock, sockvecp); } #define RIPSIZE(n) \ |