271ab6
Description: fix CVE-2012-6687 in bundled libfcgi
271ab6
Origin: https://bugs.launchpad.net/ubuntu/+source/libfcgi/+bug/933417
271ab6
Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=815840
271ab6
Forwarded: https://rt.cpan.org/Ticket/Display.html?id=118405
271ab6
271ab6
--- a/os_unix.c
271ab6
+++ b/os_unix.c
271ab6
@@ -36,6 +36,7 @@
271ab6
 #include <sys/time.h>
271ab6
 #include <sys/un.h>
271ab6
 #include <signal.h>
271ab6
+#include <poll.h>
271ab6
 
271ab6
 #ifdef HAVE_NETDB_H
271ab6
 #include <netdb.h>
271ab6
@@ -97,6 +98,9 @@
271ab6
 static int shutdownPending = FALSE;
271ab6
 static int shutdownNow = FALSE;
271ab6
 
271ab6
+static int libfcgiOsClosePollTimeout = 2000;
271ab6
+static int libfcgiIsAfUnixKeeperPollTimeout = 2000;
271ab6
+
271ab6
 void OS_ShutdownPending()
271ab6
 {
271ab6
     shutdownPending = TRUE;
271ab6
@@ -162,6 +166,16 @@
271ab6
     if(libInitialized)
271ab6
         return 0;
271ab6
 
271ab6
+    char *libfcgiOsClosePollTimeoutStr = getenv( "LIBFCGI_OS_CLOSE_POLL_TIMEOUT" );
271ab6
+    if(libfcgiOsClosePollTimeoutStr) {
271ab6
+        libfcgiOsClosePollTimeout = atoi(libfcgiOsClosePollTimeoutStr);
271ab6
+    }
271ab6
+
271ab6
+    char *libfcgiIsAfUnixKeeperPollTimeoutStr = getenv( "LIBFCGI_IS_AF_UNIX_KEEPER_POLL_TIMEOUT" );
271ab6
+    if(libfcgiIsAfUnixKeeperPollTimeoutStr) {
271ab6
+        libfcgiIsAfUnixKeeperPollTimeout = atoi(libfcgiIsAfUnixKeeperPollTimeoutStr);
271ab6
+    }
271ab6
+
271ab6
     asyncIoTable = (AioInfo *)malloc(asyncIoTableSize * sizeof(AioInfo));
271ab6
     if(asyncIoTable == NULL) {
271ab6
         errno = ENOMEM;
271ab6
@@ -751,19 +765,16 @@
271ab6
     {
271ab6
         if (shutdown(fd, 1) == 0)
271ab6
         {
271ab6
-            struct timeval tv;
271ab6
-            fd_set rfds;
271ab6
+            struct pollfd pfd;
271ab6
             int rv;
271ab6
             char trash[1024];
271ab6
 
271ab6
-            FD_ZERO(&rfds);
271ab6
+            pfd.fd = fd;
271ab6
+            pfd.events = POLLIN;
271ab6
 
271ab6
             do 
271ab6
             {
271ab6
-                FD_SET(fd, &rfds);
271ab6
-                tv.tv_sec = 2;
271ab6
-                tv.tv_usec = 0;
271ab6
-                rv = select(fd + 1, &rfds, NULL, NULL, &tv;;
271ab6
+                rv = poll(&pfd, 1, libfcgiOsClosePollTimeout);
271ab6
             }
271ab6
             while (rv > 0 && read(fd, trash, sizeof(trash)) > 0);
271ab6
         }
271ab6
@@ -1113,13 +1124,11 @@
271ab6
  */
271ab6
 static int is_af_unix_keeper(const int fd)
271ab6
 {
271ab6
-    struct timeval tval = { READABLE_UNIX_FD_DROP_DEAD_TIMEVAL };
271ab6
-    fd_set read_fds;
271ab6
-
271ab6
-    FD_ZERO(&read_fds);
271ab6
-    FD_SET(fd, &read_fds);
271ab6
+    struct pollfd pfd;
271ab6
+    pfd.fd = fd;
271ab6
+    pfd.events = POLLIN;
271ab6
 
271ab6
-    return select(fd + 1, &read_fds, NULL, NULL, &tval) >= 0 && FD_ISSET(fd, &read_fds);
271ab6
+    return poll(&pfd, 1, libfcgiIsAfUnixKeeperPollTimeout) >= 0 && (pfd.revents & POLLIN);
271ab6
 }
271ab6
 
271ab6
 /*