summaryrefslogtreecommitdiffstats
path: root/lib/libc/net/rcmd.c
diff options
context:
space:
mode:
authorcsgr <csgr@FreeBSD.org>1994-09-08 20:55:02 +0000
committercsgr <csgr@FreeBSD.org>1994-09-08 20:55:02 +0000
commit7ca8cf71da0aa32305b0f45ca0738b7cc8ac01e8 (patch)
tree5d85436f66736696100d517c5221208faff47b98 /lib/libc/net/rcmd.c
parent8be34115cca0d773bc44b3143d17eddf3030f0c9 (diff)
downloadFreeBSD-src-7ca8cf71da0aa32305b0f45ca0738b7cc8ac01e8.zip
FreeBSD-src-7ca8cf71da0aa32305b0f45ca0738b7cc8ac01e8.tar.gz
Based on fix from 1.1.5.1:
>From: jtk@atria.com (John T. Kohl) in rcmd: It calls select() with a hardcoded "number of file descriptors" argument of 32, rather than computing it based on the sockets about which it cares. - Now we work out the nfds arg, and do some error checking Submitted by: Geoff.
Diffstat (limited to 'lib/libc/net/rcmd.c')
-rw-r--r--lib/libc/net/rcmd.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/libc/net/rcmd.c b/lib/libc/net/rcmd.c
index 279b9bd..40f1c19 100644
--- a/lib/libc/net/rcmd.c
+++ b/lib/libc/net/rcmd.c
@@ -52,6 +52,8 @@ static char sccsid[] = "@(#)rcmd.c 8.3 (Berkeley) 3/26/94";
#include <ctype.h>
#include <string.h>
+#define max(a, b) ((a > b) ? a : b)
+
int __ivaliduser __P((FILE *, u_long, const char *, const char *));
static int __icheckhost __P((u_long, char *));
@@ -131,6 +133,7 @@ rcmd(ahost, rport, locuser, remuser, cmd, fd2p)
char num[8];
int s2 = rresvport(&lport), s3;
int len = sizeof(from);
+ int nfds;
if (s2 < 0)
goto bad;
@@ -143,11 +146,17 @@ rcmd(ahost, rport, locuser, remuser, cmd, fd2p)
(void)close(s2);
goto bad;
}
+ nfds = max(s, s2)+1;
+ if(nfds > FD_SETSIZE) {
+ fprintf(stderr, "rcmd: too many files\n");
+ (void)close(s2);
+ goto bad;
+ }
FD_ZERO(&reads);
FD_SET(s, &reads);
FD_SET(s2, &reads);
errno = 0;
- if (select(32, &reads, 0, 0, 0) < 1 || !FD_ISSET(s2, &reads)) {
+ if (select(nfds, &reads, 0, 0, 0) < 1 || !FD_ISSET(s2, &reads)){
if (errno != 0)
(void)fprintf(stderr,
"rcmd: select (setting up stderr): %s\n",
OpenPOWER on IntegriCloud