From 5e84ab064300f940e0c95de0200db98fa6fe6af3 Mon Sep 17 00:00:00 2001 From: "Alexander V. Chernikov" Date: Mon, 2 Nov 2015 23:56:33 +0300 Subject: [PATCH 1/1] Emit error and reject sockets not fitting in FD_SETSIZE limit. --- sysdep/unix/io.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/sysdep/unix/io.c b/sysdep/unix/io.c index 0724667..5049b63 100644 --- a/sysdep/unix/io.c +++ b/sysdep/unix/io.c @@ -1328,6 +1328,17 @@ sk_passive_connected(sock *s, int type) log(L_WARN "SOCK: Cannot get remote IP address for TCP<"); } + if (fd >= FD_SETSIZE) + { + log(L_ERR "SOCK: Incoming connection from %I%J (port %d) %s (%d)", + t->daddr, ipa_is_link_local(t->daddr) ? t->iface : NULL, + t->dport, "rejected due to FD_SETSIZE limit", FD_SETSIZE); + close(t->fd); + t->fd = -1; + rfree(t); + return 1; + } + if (sk_setup(t) < 0) { /* FIXME: Call err_hook instead ? */ @@ -1404,6 +1415,12 @@ sk_open(sock *s) if (fd < 0) ERR("socket"); + if (fd >= FD_SETSIZE) + { + log(L_ERR "Socket setup failed due to FD_SETSIZE limit (%d)", FD_SETSIZE); + ERR2("FD_SETSIZE limit reached"); + } + s->af = af; s->fd = fd; -- 2.6.1