From c46024fa2df5d190137a4ba909a7aea0aef515ea Mon Sep 17 00:00:00 2001 From: Bram Matthys Date: Sun, 26 Feb 2012 10:09:25 +0100 Subject: [PATCH] - Make the accept code check if the fd is within bounds instead of relying on OpenFiles to be correct. This fixes a crash when f.e. 3rd party modules have files open but don't increase OpenFiles. Might also fix a curl crash, though nobody ever reported one. --- Changes | 4 ++++ src/s_bsd.c | 13 ++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Changes b/Changes index 7038c3630..dc93ad80a 100644 --- a/Changes +++ b/Changes @@ -2361,3 +2361,7 @@ - Get rid of networks/ directory, and all references to it. Suggested by katsklaw and others (#4056). - Added doc/example.es.conf, translated by Severus_Snape. +- Make the accept code check if the fd is within bounds instead of relying + on OpenFiles to be correct. This fixes a crash when f.e. 3rd party modules + have files open but don't increase OpenFiles. Might also fix a curl crash, + though nobody ever reported one. diff --git a/src/s_bsd.c b/src/s_bsd.c index d002a0255..46bc6a371 100644 --- a/src/s_bsd.c +++ b/src/s_bsd.c @@ -1775,7 +1775,18 @@ int read_message(time_t delay, fdlist *listp) break; } ircstp->is_ac++; - if (++OpenFiles >= MAXCLIENTS) + /* We now check: + * 1) The number of open files, which is the limit imposed by the + * user during ./Config (MAXCONNECTIONS minus a few). + * 2) If the fd number exceeds FD_SETSIZE, which is not + * permitted as otherwise FD_SET() and FD_CLR() will fail + * in read_message() + * Note that the value of FD_SETSIZE may be (much) higher than + * MAXCLIENTS/MAXCONNECTIONS. They are not necessarily the same! + * Check #2 can be removed if poll() is used. + * FIXME: Figure out why I need a FD_SETSIZE-4 here? still have crashes with -1... + */ + if ((++OpenFiles >= MAXCLIENTS) || (fd > FD_SETSIZE-4)) { ircstp->is_ref++; if (last_allinuse < TStime() - 15)