From cb80bdf6d5c2e232e751187f86b6fa68d959fcf9 Mon Sep 17 00:00:00 2001 From: Ben Lindstrom Date: Mon, 5 Mar 2001 07:06:12 +0000 Subject: [PATCH] - millert@cvs.openbsd.org 2001/03/03 21:40:30 [sftp-server.c] Dynamically allocate fd_set; deraadt@ OK --- ChangeLog | 5 ++++- sftp-server.c | 26 +++++++++++++++----------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 512343f7a..13dc9bef5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -128,6 +128,9 @@ [ssh-keyscan.c] Dynamically allocate read_wait and its copies. Since maxfd is based on resource limits it is often (usually?) larger than FD_SETSIZE. + - millert@cvs.openbsd.org 2001/03/03 21:40:30 + [sftp-server.c] + Dynamically allocate fd_set; deraadt@ OK 20010304 - (bal) Remove make-ssh-known-hosts.1 since it's no longer valid. @@ -4320,4 +4323,4 @@ - Wrote replacements for strlcpy and mkdtemp - Released 1.0pre1 -$Id: ChangeLog,v 1.890 2001/03/05 07:04:38 mouring Exp $ +$Id: ChangeLog,v 1.891 2001/03/05 07:06:12 mouring Exp $ diff --git a/sftp-server.c b/sftp-server.c index c8daeea1e..2b1a7e3e5 100644 --- a/sftp-server.c +++ b/sftp-server.c @@ -22,7 +22,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "includes.h" -RCSID("$OpenBSD: sftp-server.c,v 1.20 2001/02/21 09:12:56 deraadt Exp $"); +RCSID("$OpenBSD: sftp-server.c,v 1.21 2001/03/03 21:40:30 millert Exp $"); #include "buffer.h" #include "bufaux.h" @@ -940,9 +940,9 @@ process(void) int main(int ac, char **av) { - fd_set rset, wset; + fd_set *rset, *wset; int in, out, max; - ssize_t len, olen; + ssize_t len, olen, set_size; __progname = get_progname(av[0]); handle_init(); @@ -963,23 +963,27 @@ main(int ac, char **av) buffer_init(&iqueue); buffer_init(&oqueue); - for (;;) { - FD_ZERO(&rset); - FD_ZERO(&wset); + set_size = howmany(max + 1, NFDBITS) * sizeof(fd_mask); + rset = (fd_set *)xmalloc(set_size); + wset = (fd_set *)xmalloc(set_size); - FD_SET(in, &rset); + for (;;) { + memset(rset, 0, set_size); + memset(wset, 0, set_size); + + FD_SET(in, rset); olen = buffer_len(&oqueue); if (olen > 0) - FD_SET(out, &wset); + FD_SET(out, wset); - if (select(max+1, &rset, &wset, NULL, NULL) < 0) { + if (select(max+1, rset, wset, NULL, NULL) < 0) { if (errno == EINTR) continue; exit(2); } /* copy stdin to iqueue */ - if (FD_ISSET(in, &rset)) { + if (FD_ISSET(in, rset)) { char buf[4*4096]; len = read(in, buf, sizeof buf); if (len == 0) { @@ -993,7 +997,7 @@ main(int ac, char **av) } } /* send oqueue to stdout */ - if (FD_ISSET(out, &wset)) { + if (FD_ISSET(out, wset)) { len = write(out, buffer_ptr(&oqueue), olen); if (len < 0) { error("write error");