From 0979b3a68b820cd60a0c2618c2ac89f288eb341d Mon Sep 17 00:00:00 2001 From: Amos Jeffries Date: Sat, 12 Jun 2010 22:53:08 +1200 Subject: [PATCH] Restrict limited select() I/O loop below FD_SETSIZE. Henrik informs that loosp using fd_set() (select and win32-select) must be kept below FD_SETSIZE or they can hang Squid or cause out-of-bounds memory errors. NP: Squid-2 does not appear to limit select() like this. May need fixing too. --- src/tools.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/tools.cc b/src/tools.cc index c88ee054f7..998d51dbb3 100644 --- a/src/tools.cc +++ b/src/tools.cc @@ -888,7 +888,13 @@ setMaxFD(void) if (getrlimit(RLIMIT_NOFILE, &rl) < 0) { debugs(50, DBG_CRITICAL, "setrlimit: RLIMIT_NOFILE: " << xstrerror()); } else if (Config.max_filedescriptors > 0) { - rl.rlim_cur = Config.max_filedescriptors; +#if USE_SELECT || USE_SELECT_WIN32 + /* select() breaks if this gets set too big */ + if (Config.max_filedescriptors > FD_SETSIZE) + rl.rlim_cur = FD_SETSIZE; + else +#endif + rl.rlim_cur = Config.max_filedescriptors; if (rl.rlim_cur > rl.rlim_max) rl.rlim_max = rl.rlim_cur; if (setrlimit(RLIMIT_NOFILE, &rl)) { -- 2.47.3