]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Restrict limited select() I/O loop below FD_SETSIZE.
authorAmos Jeffries <squid3@treenet.co.nz>
Sat, 12 Jun 2010 10:53:08 +0000 (22:53 +1200)
committerAmos Jeffries <squid3@treenet.co.nz>
Sat, 12 Jun 2010 10:53:08 +0000 (22:53 +1200)
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

index c88ee054f7056cffc0da54fd91b69eec6f3b6c5e..998d51dbb3861337a2c92a52ad8671cb6bd4275c 100644 (file)
@@ -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)) {