Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src avoid fd_set overrun.
details: https://anonhg.NetBSD.org/src/rev/f58c30c98f57
branches: trunk
changeset: 532139:f58c30c98f57
user: itojun <itojun%NetBSD.org@localhost>
date: Fri May 31 22:10:18 2002 +0000
description:
avoid fd_set overrun.
diffstat:
sbin/rtsol/Makefile | 4 ++--
usr.sbin/rtsold/Makefile | 4 ++--
usr.sbin/rtsold/rtsold.c | 40 ++++++++++++++++++++++++++++++----------
3 files changed, 34 insertions(+), 14 deletions(-)
diffs (124 lines):
diff -r e63d5fbe63e7 -r f58c30c98f57 sbin/rtsol/Makefile
--- a/sbin/rtsol/Makefile Fri May 31 21:43:49 2002 +0000
+++ b/sbin/rtsol/Makefile Fri May 31 22:10:18 2002 +0000
@@ -1,9 +1,9 @@
-# $NetBSD: Makefile,v 1.8 2002/05/31 10:22:11 itojun Exp $
+# $NetBSD: Makefile,v 1.9 2002/05/31 22:10:18 itojun Exp $
PROG= rtsol
SRCS= rtsold.c rtsol.c if.c probe.c dump.c rtsock.c
-CPPFLAGS+=-DINET6 -DHAVE_GETIFADDRS -DHAVE_ARC4RANDOM
+CPPFLAGS+=-DINET6 -DHAVE_GETIFADDRS -DHAVE_ARC4RANDOM -DUSE_RTSOCK
#MAN= rtsold.8
NOMAN= # defined
diff -r e63d5fbe63e7 -r f58c30c98f57 usr.sbin/rtsold/Makefile
--- a/usr.sbin/rtsold/Makefile Fri May 31 21:43:49 2002 +0000
+++ b/usr.sbin/rtsold/Makefile Fri May 31 22:10:18 2002 +0000
@@ -1,9 +1,9 @@
-# $NetBSD: Makefile,v 1.7 2002/05/31 10:22:13 itojun Exp $
+# $NetBSD: Makefile,v 1.8 2002/05/31 22:10:18 itojun Exp $
PROG= rtsold
SRCS= rtsold.c rtsol.c if.c probe.c dump.c rtsock.c
-CPPFLAGS+=-DINET6 -DHAVE_GETIFADDRS -DHAVE_ARC4RANDOM
+CPPFLAGS+=-DINET6 -DHAVE_GETIFADDRS -DHAVE_ARC4RANDOM -DUSE_RTSOCK
MAN= rtsold.8
MLINKS= rtsold.8 rtsol.8
diff -r e63d5fbe63e7 -r f58c30c98f57 usr.sbin/rtsold/rtsold.c
--- a/usr.sbin/rtsold/rtsold.c Fri May 31 21:43:49 2002 +0000
+++ b/usr.sbin/rtsold/rtsold.c Fri May 31 22:10:18 2002 +0000
@@ -1,5 +1,5 @@
-/* $NetBSD: rtsold.c,v 1.14 2002/05/31 10:22:16 itojun Exp $ */
-/* $KAME: rtsold.c,v 1.48 2002/05/31 10:13:57 itojun Exp $ */
+/* $NetBSD: rtsold.c,v 1.15 2002/05/31 22:10:18 itojun Exp $ */
+/* $KAME: rtsold.c,v 1.52 2002/05/31 22:03:31 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -111,8 +111,11 @@
int s, maxfd, ch, once = 0;
struct timeval *timeout;
char *argv0, *opts;
- fd_set fdset;
+ fd_set *fdsetp, *selectfdp;
+ int fdmasks;
+#ifdef USE_RTSOCK
int rtsock;
+#endif
/*
* Initialization
@@ -208,6 +211,7 @@
/*NOTREACHED*/
}
maxfd = s;
+#ifdef USE_RTSOCK
if ((rtsock = rtsock_open()) < 0) {
warnmsg(LOG_ERR, __FUNCTION__, "failed to open a socket");
exit(1);
@@ -215,6 +219,17 @@
}
if (rtsock > maxfd)
maxfd = rtsock;
+#endif
+
+ fdmasks = howmany(maxfd + 1, NFDBITS) * sizeof(fd_mask);
+ if ((fdsetp = malloc(fdmasks)) == NULL) {
+ err(1, "malloc");
+ /*NOTREACHED*/
+ }
+ if ((selectfdp = malloc(fdmasks)) == NULL) {
+ err(1, "malloc");
+ /*NOTREACHED*/
+ }
/* configuration per interface */
if (ifinit()) {
@@ -252,13 +267,16 @@
}
}
- FD_ZERO(&fdset);
- FD_SET(s, &fdset);
- FD_SET(rtsock, &fdset);
+ memset(fdsetp, 0, fdmasks);
+ FD_SET(s, fdsetp);
+#ifdef USE_RTSOCK
+ FD_SET(rtsock, fdsetp);
+#endif
while (1) { /* main loop */
- fd_set select_fd = fdset;
int e;
+ memcpy(selectfdp, fdsetp, fdmasks);
+
if (do_dump) { /* SIGUSR1 */
do_dump = 0;
rtsold_dump_file(dumpfilename);
@@ -281,7 +299,7 @@
if (ifi == NULL)
break;
}
- e = select(maxfd + 1, &select_fd, NULL, NULL, timeout);
+ e = select(maxfd + 1, selectfdp, NULL, NULL, timeout);
if (e < 1) {
if (e < 0 && errno != EINTR) {
warnmsg(LOG_ERR, __FUNCTION__, "select: %s",
@@ -291,9 +309,11 @@
}
/* packet reception */
- if (FD_ISSET(rtsock, &select_fd))
+#ifdef USE_RTSOCK
+ if (FD_ISSET(rtsock, selectfdp))
rtsock_input(rtsock);
- if (FD_ISSET(s, &select_fd))
+#endif
+ if (FD_ISSET(s, selectfdp))
rtsol_input(s);
}
/* NOTREACHED */
Home |
Main Index |
Thread Index |
Old Index