From d074de9004fdcc008ebe253e4a5ade1b5b1c5d53 Mon Sep 17 00:00:00 2001 From: itojun Date: Sat, 7 Oct 2000 06:42:40 +0000 Subject: [PATCH] avoid fd_set overflow --- usr.sbin/mtrace6/mtrace6.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/usr.sbin/mtrace6/mtrace6.c b/usr.sbin/mtrace6/mtrace6.c index 4bc47917e299..0d6d61919687 100644 --- a/usr.sbin/mtrace6/mtrace6.c +++ b/usr.sbin/mtrace6/mtrace6.c @@ -1,4 +1,4 @@ -/* $NetBSD: mtrace6.c,v 1.3 2000/02/26 11:44:28 itojun Exp $ */ +/* $NetBSD: mtrace6.c,v 1.4 2000/10/07 06:42:40 itojun Exp $ */ /* * Copyright (C) 1999 WIDE Project. @@ -34,6 +34,7 @@ #include #include #include +#include #include #if defined(__FreeBSD__) && __FreeBSD__ >= 3 @@ -216,7 +217,8 @@ mtrace_loop() { int nsoc, fromlen, rcvcc; struct timeval tv, tv_wait; - struct fd_set fds; + struct fd_set *fdsp; + size_t nfdsp; struct sockaddr_storage from_ss; struct sockaddr *from_sock = (struct sockaddr *)&from_ss; @@ -234,11 +236,16 @@ mtrace_loop() tv_wait.tv_sec = waittime; tv_wait.tv_usec = 0; - FD_ZERO(&fds); - FD_SET(mldsoc, &fds); + nfdsp = howmany(mldsoc + 1, NFDBITS); + fdsp = malloc(nfdsp); + if (!fdsp) + err(1, "malloc"); + memset(fdsp, 0, nfdsp); + FD_SET(mldsoc, fdsp); - if ((nsoc = select(mldsoc + 1, &fds, NULL, NULL, &tv_wait)) < 0) + if ((nsoc = select(mldsoc + 1, fdsp, NULL, NULL, &tv_wait)) < 0) err(1, "select"); + free(fdsp); if (nsoc == 0) { printf("Timeout\n");