summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErik M. Bray <erik.m.bray@gmail.com>2017-11-07 14:44:49 +0100
committerCorinna Vinschen <corinna@vinschen.de>2017-11-07 16:08:14 +0100
commit1c50e0d1abd5cc790e72572af6fd6b03f7d1c594 (patch)
tree0abf9704bba55cd39a774f99c1a3add5a5ce77f6
parent1f42dc2bcf58d3b8629eb13d53de3f69fc314b47 (diff)
downloadcygnal-1c50e0d1abd5cc790e72572af6fd6b03f7d1c594.tar.gz
cygnal-1c50e0d1abd5cc790e72572af6fd6b03f7d1c594.tar.bz2
cygnal-1c50e0d1abd5cc790e72572af6fd6b03f7d1c594.zip
Fix two bugs in the limit of large numbers of sockets:
* Fix the maximum number of sockets allowed in the session to 2048, instead of making it relative to sizeof(wsa_event). The original choice of 2048 was in order to fit the wsa_events array in the .cygwin_dll_common shared section, but there is still enough room to grow there to have 2048 sockets on 64-bit as well. * Return an error and set errno=ENOBUF if a socket can't be created due to this limit being reached. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
-rw-r--r--winsup/cygwin/fhandler_socket.cc11
1 files changed, 9 insertions, 2 deletions
diff --git a/winsup/cygwin/fhandler_socket.cc b/winsup/cygwin/fhandler_socket.cc
index 7a6dbdc41..185fd51ff 100644
--- a/winsup/cygwin/fhandler_socket.cc
+++ b/winsup/cygwin/fhandler_socket.cc
@@ -496,7 +496,7 @@ fhandler_socket::af_local_set_secret (char *buf)
/* Maximum number of concurrently opened sockets from all Cygwin processes
per session. Note that shared sockets (through dup/fork/exec) are
counted as one socket. */
-#define NUM_SOCKS (32768 / sizeof (wsa_event))
+#define NUM_SOCKS 2048U
#define LOCK_EVENTS \
if (wsock_mtx && \
@@ -623,7 +623,14 @@ fhandler_socket::init_events ()
NtClose (wsock_mtx);
return false;
}
- wsock_events = search_wsa_event_slot (new_serial_number);
+ if (!(wsock_events = search_wsa_event_slot (new_serial_number)));
+ {
+ set_errno (ENOBUFS);
+ NtClose (wsock_evt);
+ NtClose (wsock_mtx);
+ return false;
+ }
+
/* sock type not yet set here. */
if (pc.dev == FH_UDP || pc.dev == FH_DGRAM)
wsock_events->events = FD_WRITE;