diff options
Diffstat (limited to 'usr.sbin/faithd/ftp.c')
-rw-r--r-- | usr.sbin/faithd/ftp.c | 55 |
1 files changed, 35 insertions, 20 deletions
diff --git a/usr.sbin/faithd/ftp.c b/usr.sbin/faithd/ftp.c index e22e03d5dda..5279d800e43 100644 --- a/usr.sbin/faithd/ftp.c +++ b/usr.sbin/faithd/ftp.c @@ -1,5 +1,5 @@ -/* $OpenBSD: ftp.c,v 1.9 2002/06/24 06:06:25 itojun Exp $ */ -/* $KAME: ftp.c,v 1.18 2002/06/23 14:41:47 itojun Exp $ */ +/* $OpenBSD: ftp.c,v 1.10 2002/09/08 01:20:15 itojun Exp $ */ +/* $KAME: ftp.c,v 1.20 2002/09/08 01:12:30 itojun Exp $ */ /* * Copyright (C) 1997 and 1998 WIDE Project. @@ -83,24 +83,36 @@ ftp_relay(int ctl6, int ctl4) int maxfd = 0; FD_ZERO(&readfds); + if (ctl4 >= FD_SETSIZE) + exit_failure("descriptor too big"); FD_SET(ctl4, &readfds); maxfd = ctl4; + if (ctl6 >= FD_SETSIZE) + exit_failure("descriptor too big"); FD_SET(ctl6, &readfds); maxfd = (ctl6 > maxfd) ? ctl6 : maxfd; if (0 <= port4) { + if (port4 >= FD_SETSIZE) + exit_failure("descriptor too big"); FD_SET(port4, &readfds); maxfd = (port4 > maxfd) ? port4 : maxfd; } if (0 <= port6) { + if (port6 >= FD_SETSIZE) + exit_failure("descriptor too big"); FD_SET(port6, &readfds); maxfd = (port6 > maxfd) ? port6 : maxfd; } #if 0 if (0 <= wport4) { + if (wport4 >= FD_SETSIZE) + exit_failure("descriptor too big"); FD_SET(wport4, &readfds); maxfd = (wport4 > maxfd) ? wport4 : maxfd; } if (0 <= wport6) { + if (wport6 >= FD_SETSIZE) + exit_failure("descriptor too big"); FD_SET(wport6, &readfds); maxfd = (wport6 > maxfd) ? wport6 : maxfd; } @@ -215,7 +227,7 @@ ftp_relay(int ctl6, int ctl4) static int ftp_activeconn() { - int n; + socklen_t n; int error; fd_set set; struct timeval timeout; @@ -223,6 +235,8 @@ ftp_activeconn() /* get active connection from server */ FD_ZERO(&set); + if (wport4 >= FD_SETSIZE) + exit_failure("descriptor too big"); FD_SET(wport4, &set); timeout.tv_sec = 120; timeout.tv_usec = -1; @@ -262,7 +276,7 @@ ftp_activeconn() static int ftp_passiveconn() { - int n; + socklen_t len; int error; fd_set set; struct timeval timeout; @@ -270,12 +284,14 @@ ftp_passiveconn() /* get passive connection from client */ FD_ZERO(&set); + if (wport6 >= FD_SETSIZE) + exit_failure("descriptor too big"); FD_SET(wport6, &set); timeout.tv_sec = 120; timeout.tv_usec = 0; - n = sizeof(data6); + len = sizeof(data6); if (select(wport6 + 1, &set, NULL, NULL, &timeout) == 0 - || (port6 = accept(wport6, (struct sockaddr *)&data6, &n)) < 0) { + || (port6 = accept(wport6, (struct sockaddr *)&data6, &len)) < 0) { close(wport6); wport6 = -1; syslog(LOG_INFO, "passive mode data connection failed"); @@ -309,8 +325,7 @@ ftp_passiveconn() static int ftp_copy(int src, int dst) { - int error, atmark; - int n; + int error, atmark, n; /* OOB data handling */ error = ioctl(src, SIOCATMARK, &atmark); @@ -347,8 +362,8 @@ ftp_copy(int src, int dst) static int ftp_copyresult(int src, int dst, enum state state) { - int error, atmark; - int n; + int error, atmark, n; + socklen_t len; char *param; int code; char *a, *p; @@ -517,8 +532,8 @@ passivefail: /* * addr from dst, port from wport6 */ - n = sizeof(data6); - error = getsockname(wport6, (struct sockaddr *)&data6, &n); + len = sizeof(data6); + error = getsockname(wport6, (struct sockaddr *)&data6, &len); if (error == -1) { close(wport6); wport6 = -1; @@ -527,8 +542,8 @@ passivefail: sin6 = (struct sockaddr_in6 *)&data6; port = sin6->sin6_port; - n = sizeof(data6); - error = getsockname(dst, (struct sockaddr *)&data6, &n); + len = sizeof(data6); + error = getsockname(dst, (struct sockaddr *)&data6, &len); if (error == -1) { close(wport6); wport6 = -1; @@ -576,8 +591,8 @@ passivefail: static int ftp_copycommand(int src, int dst, enum state *state) { - int error, atmark; - int n; + int error, atmark, n; + socklen_t len; unsigned int af, hal, ho[16], pal, po[2]; char *a, *p, *q; char cmd[5], *param; @@ -692,8 +707,8 @@ ftp_copycommand(int src, int dst, enum state *state) sendport: /* get ready for active data connection */ - n = sizeof(data4); - error = getsockname(dst, (struct sockaddr *)&data4, &n); + len = sizeof(data4); + error = getsockname(dst, (struct sockaddr *)&data4, &len); if (error == -1) { lprtfail: n = snprintf(sbuf, sizeof(sbuf), @@ -725,8 +740,8 @@ lprtfail: } /* transmit PORT */ - n = sizeof(data4); - error = getsockname(wport4, (struct sockaddr *)&data4, &n); + len = sizeof(data4); + error = getsockname(wport4, (struct sockaddr *)&data4, &len); if (error == -1) { close(wport4); wport4 = -1; |