summaryrefslogtreecommitdiff
path: root/src/common/compat.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2004-12-01 03:15:59 +0000
committerNick Mathewson <nickm@torproject.org>2004-12-01 03:15:59 +0000
commit6e88abf418684ccaf4a1d7146b0129857a3864fe (patch)
tree40fe96c95f262f00fdf714759553f42eb45429eb /src/common/compat.c
parentbde1d5bfb2a6c1c39d51ff807e2d13ce6e8a30ce (diff)
downloadtor-6e88abf418684ccaf4a1d7146b0129857a3864fe.tar.gz
tor-6e88abf418684ccaf4a1d7146b0129857a3864fe.zip
If we are using select, make sure we stay within FD_SETSIZE.
svn:r3051
Diffstat (limited to 'src/common/compat.c')
-rw-r--r--src/common/compat.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/common/compat.c b/src/common/compat.c
index 528f0beed0..16e1bee4b6 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -241,6 +241,11 @@ tor_socketpair(int family, int type, int protocol, int fd[2])
listener = socket(AF_INET, type, 0);
if (listener == -1)
return -1;
+ if (!SOCKET_IS_POLLABLE(listener)) {
+ log_fn(LOG_WARN, "Too many connections; can't open socketpair");
+ tor_close_socket(listener);
+ return -1;
+ }
memset(&listen_addr, 0, sizeof(listen_addr));
listen_addr.sin_family = AF_INET;
listen_addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
@@ -254,6 +259,10 @@ tor_socketpair(int family, int type, int protocol, int fd[2])
connector = socket(AF_INET, type, 0);
if (connector == -1)
goto tidy_up_and_fail;
+ if (!SOCKET_IS_POLLABLE(connector)) {
+ log_fn(LOG_WARN, "Too many connections; can't open socketpair");
+ goto tidy_up_and_fail;
+ }
/* We want to find out the port number to connect to. */
size = sizeof(connect_addr);
if (getsockname(listener, (struct sockaddr *) &connect_addr, &size) == -1)
@@ -268,6 +277,10 @@ tor_socketpair(int family, int type, int protocol, int fd[2])
acceptor = accept(listener, (struct sockaddr *) &listen_addr, &size);
if (acceptor == -1)
goto tidy_up_and_fail;
+ if (!SOCKET_IS_POLLABLE(acceptor)) {
+ log_fn(LOG_WARN, "Too many connections; can't open socketpair");
+ goto tidy_up_and_fail;
+ }
if (size != sizeof(listen_addr))
goto abort_tidy_up_and_fail;
tor_close_socket(listener);