~ubuntu-branches/ubuntu/precise/libfcgi/precise-security

« back to all changes in this revision

Viewing changes to libfcgi/os_unix.c

  • Committer: Package Import Robot
  • Author(s): Joe Damato
  • Date: 2015-02-05 16:28:53 UTC
  • Revision ID: package-import@ubuntu.com-20150205162853-j2vhdqv0y408n493
Tags: 2.4.0-8.1ubuntu0.1
Applying patch to swap select with poll to handle more than 1024
connections and avoid data corruption or a segfault. (LP: #1418778).

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
#include <sys/time.h>
43
43
#include <sys/un.h>
44
44
#include <signal.h>
 
45
#include <poll.h>
45
46
 
46
47
#ifdef HAVE_NETDB_H
47
48
#include <netdb.h>
103
104
static int shutdownPending = FALSE;
104
105
static int shutdownNow = FALSE;
105
106
 
 
107
static int libfcgiOsClosePollTimeout = 2000;
 
108
static int libfcgiIsAfUnixKeeperPollTimeout = 2000;
 
109
 
106
110
void OS_ShutdownPending()
107
111
{
108
112
    shutdownPending = TRUE;
168
172
    if(libInitialized)
169
173
        return 0;
170
174
 
 
175
    char *libfcgiOsClosePollTimeoutStr = getenv( "LIBFCGI_OS_CLOSE_POLL_TIMEOUT" );
 
176
    if(libfcgiOsClosePollTimeoutStr) {
 
177
        libfcgiOsClosePollTimeout = atoi(libfcgiOsClosePollTimeoutStr);
 
178
    }
 
179
 
 
180
    char *libfcgiIsAfUnixKeeperPollTimeoutStr = getenv( "LIBFCGI_IS_AF_UNIX_KEEPER_POLL_TIMEOUT" );
 
181
    if(libfcgiIsAfUnixKeeperPollTimeoutStr) {
 
182
        libfcgiIsAfUnixKeeperPollTimeout = atoi(libfcgiIsAfUnixKeeperPollTimeoutStr);
 
183
    }
 
184
 
171
185
    asyncIoTable = (AioInfo *)malloc(asyncIoTableSize * sizeof(AioInfo));
172
186
    if(asyncIoTable == NULL) {
173
187
        errno = ENOMEM;
755
769
 
756
770
    if (shutdown(fd, 1) == 0)
757
771
    {
758
 
        struct timeval tv;
759
 
        fd_set rfds;
 
772
        struct pollfd pfd;
760
773
        int rv;
761
774
        char trash[1024];
762
775
 
763
 
        FD_ZERO(&rfds);
 
776
        pfd.fd = fd;
 
777
        pfd.events = POLLIN;
764
778
 
765
779
        do 
766
780
        {
767
 
            FD_SET(fd, &rfds);
768
 
            tv.tv_sec = 2;
769
 
            tv.tv_usec = 0;
770
 
            rv = select(fd + 1, &rfds, NULL, NULL, &tv);
 
781
            rv = poll(&pfd, 1, libfcgiOsClosePollTimeout);
771
782
        }
772
783
        while (rv > 0 && read(fd, trash, sizeof(trash)) > 0);
773
784
    }
1116
1127
 */
1117
1128
static int is_af_unix_keeper(const int fd)
1118
1129
{
1119
 
    struct timeval tval = { READABLE_UNIX_FD_DROP_DEAD_TIMEVAL };
1120
 
    fd_set read_fds;
1121
 
 
1122
 
    FD_ZERO(&read_fds);
1123
 
    FD_SET(fd, &read_fds);
1124
 
 
1125
 
    return select(fd + 1, &read_fds, NULL, NULL, &tval) >= 0 && FD_ISSET(fd, &read_fds);
 
1130
    struct pollfd pfd;
 
1131
    pfd.fd = fd;
 
1132
    pfd.events = POLLIN;
 
1133
 
 
1134
    return poll(&pfd, 1, libfcgiIsAfUnixKeeperPollTimeout) >= 0 && (pfd.revents & POLLIN);
1126
1135
}
1127
1136
 
1128
1137
/*