gnu: Add fcgi.
[jackhill/guix/guix.git] / gnu / packages / patches / fcgi-2.4.0-poll.patch
1 Taken from http://pkgs.fedoraproject.org/cgit/rpms/fcgi.git/plain/fcgi-2.4.0-poll.patch
2 Fixes CVE-2012-6687.
3
4 Author: Anton Kortunov <toshic.toshic@gmail.com>
5 Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/libfcgi/+bug/933417
6 Description: use poll in os_unix.c instead of select to avoid problem with > 1024 connections
7 Forwarded: yes, fastcgi-developers@mailman.fastcgi.com
8
9 diff --git a/libfcgi/os_unix.c b/libfcgi/os_unix.c
10 index 73e6a7f..af35aee 100755
11 --- a/libfcgi/os_unix.c
12 +++ b/libfcgi/os_unix.c
13 @@ -42,6 +42,7 @@ static const char rcsid[] = "$Id: os_unix.c,v 1.37 2002/03/05 19:14:49 robs Exp
14 #include <sys/time.h>
15 #include <sys/un.h>
16 #include <signal.h>
17 +#include <poll.h>
18
19 #ifdef HAVE_NETDB_H
20 #include <netdb.h>
21 @@ -103,6 +104,9 @@ static int volatile maxFd = -1;
22 static int shutdownPending = FALSE;
23 static int shutdownNow = FALSE;
24
25 +static int libfcgiOsClosePollTimeout = 2000;
26 +static int libfcgiIsAfUnixKeeperPollTimeout = 2000;
27 +
28 void OS_ShutdownPending()
29 {
30 shutdownPending = TRUE;
31 @@ -168,6 +172,16 @@ int OS_LibInit(int stdioFds[3])
32 if(libInitialized)
33 return 0;
34
35 + char *libfcgiOsClosePollTimeoutStr = getenv( "LIBFCGI_OS_CLOSE_POLL_TIMEOUT" );
36 + if(libfcgiOsClosePollTimeoutStr) {
37 + libfcgiOsClosePollTimeout = atoi(libfcgiOsClosePollTimeoutStr);
38 + }
39 +
40 + char *libfcgiIsAfUnixKeeperPollTimeoutStr = getenv( "LIBFCGI_IS_AF_UNIX_KEEPER_POLL_TIMEOUT" );
41 + if(libfcgiIsAfUnixKeeperPollTimeoutStr) {
42 + libfcgiIsAfUnixKeeperPollTimeout = atoi(libfcgiIsAfUnixKeeperPollTimeoutStr);
43 + }
44 +
45 asyncIoTable = (AioInfo *)malloc(asyncIoTableSize * sizeof(AioInfo));
46 if(asyncIoTable == NULL) {
47 errno = ENOMEM;
48 @@ -755,19 +769,16 @@ int OS_Close(int fd)
49
50 if (shutdown(fd, 1) == 0)
51 {
52 - struct timeval tv;
53 - fd_set rfds;
54 + struct pollfd pfd;
55 int rv;
56 char trash[1024];
57
58 - FD_ZERO(&rfds);
59 + pfd.fd = fd;
60 + pfd.events = POLLIN;
61
62 do
63 {
64 - FD_SET(fd, &rfds);
65 - tv.tv_sec = 2;
66 - tv.tv_usec = 0;
67 - rv = select(fd + 1, &rfds, NULL, NULL, &tv);
68 + rv = poll(&pfd, 1, libfcgiOsClosePollTimeout);
69 }
70 while (rv > 0 && read(fd, trash, sizeof(trash)) > 0);
71 }
72 @@ -1116,13 +1127,11 @@ static int is_reasonable_accept_errno (const int error)
73 */
74 static int is_af_unix_keeper(const int fd)
75 {
76 - struct timeval tval = { READABLE_UNIX_FD_DROP_DEAD_TIMEVAL };
77 - fd_set read_fds;
78 -
79 - FD_ZERO(&read_fds);
80 - FD_SET(fd, &read_fds);
81 + struct pollfd pfd;
82 + pfd.fd = fd;
83 + pfd.events = POLLIN;
84
85 - return select(fd + 1, &read_fds, NULL, NULL, &tval) >= 0 && FD_ISSET(fd, &read_fds);
86 + return poll(&pfd, 1, libfcgiIsAfUnixKeeperPollTimeout) >= 0 && (pfd.revents & POLLIN);
87 }
88
89 /*