Ticket #841: lighttpd_fix_841.patch

File lighttpd_fix_841.patch, 3.8 kB (added by stbuehler, 7 months ago)

fix #841: Segmentation fault using fastcgi / php5-cgi

  • src/mod_fastcgi.c

    From ee397b384495234a927cd8c2951324cc80f2b5b8 Mon Sep 17 00:00:00 2001
    From: =?utf-8?q?Stefan=20B=C3=BChler?= <stbuehler@web.de>
    Date: Tue, 15 Jan 2008 23:54:57 +0100
    Subject: [PATCH] fix #841: Segmentation fault using fastcgi / php5-cgi
    
    ---
     src/mod_fastcgi.c |   45 +++++++++++++++++++++++++++++++--------------
     1 files changed, 31 insertions(+), 14 deletions(-)
    
    diff --git a/src/mod_fastcgi.c b/src/mod_fastcgi.c
    index 75b52ad..7550350 100644
    a b  
    162162         * if host is one of the local IP adresses the 
    163163         * whole connection is local 
    164164         * 
    165          * if tcp/ip should be used host AND port have 
    166          * to be specified 
     165         * if port is not 0, and host is not specified, 
     166         * "localhost" (INADDR_LOOPBACK) is assumed. 
    167167         * 
    168168         */ 
    169169        buffer *host; 
     
    823823                fcgi_addr_in.sin_family = AF_INET; 
    824824 
    825825                if (buffer_is_empty(host->host)) { 
    826                         fcgi_addr_in.sin_addr.s_addr = htonl(INADDR_ANY); 
     826                        fcgi_addr_in.sin_addr.s_addr = htonl(INADDR_LOOPBACK); 
    827827                } else { 
    828828                        struct hostent *he; 
    829829 
    830830                        /* set a useful default */ 
    831                         fcgi_addr_in.sin_addr.s_addr = htonl(INADDR_ANY); 
     831                        fcgi_addr_in.sin_addr.s_addr = htonl(INADDR_LOOPBACK); 
    832832 
    833833 
    834834                        if (NULL == (he = gethostbyname(host->host->ptr))) { 
     
    858858                fcgi_addr = (struct sockaddr *) &fcgi_addr_in; 
    859859 
    860860                buffer_copy_string(proc->connection_name, "tcp:"); 
    861                 buffer_append_string_buffer(proc->connection_name, host->host); 
     861                if (!buffer_is_empty(host->host)) { 
     862                        buffer_append_string_buffer(proc->connection_name, host->host); 
     863                } else { 
     864                        buffer_append_string(proc->connection_name, "localhost"); 
     865                } 
    862866                buffer_append_string(proc->connection_name, ":"); 
    863867                buffer_append_long(proc->connection_name, proc->port); 
    864868        } 
     
    16871691#endif 
    16881692        } else { 
    16891693                fcgi_addr_in.sin_family = AF_INET; 
    1690                 if (0 == inet_aton(host->host->ptr, &(fcgi_addr_in.sin_addr))) { 
    1691                         log_error_write(srv, __FILE__, __LINE__, "sbs", 
    1692                                         "converting IP address failed for", host->host, 
    1693                                         "\nBe sure to specify an IP address here"); 
    1694  
    1695                         return -1; 
     1694                if (!buffer_is_empty(host->host)) { 
     1695                        if (0 == inet_aton(host->host->ptr, &(fcgi_addr_in.sin_addr))) { 
     1696                                log_error_write(srv, __FILE__, __LINE__, "sbs", 
     1697                                                "converting IP address failed for", host->host, 
     1698                                                "\nBe sure to specify an IP address here"); 
     1699         
     1700                                return -1; 
     1701                        } 
     1702                } else { 
     1703                        fcgi_addr_in.sin_addr.s_addr = htonl(INADDR_LOOPBACK); 
    16961704                } 
    16971705                fcgi_addr_in.sin_port = htons(proc->port); 
    16981706                servlen = sizeof(fcgi_addr_in); 
     
    17021710                if (buffer_is_empty(proc->connection_name)) { 
    17031711                        /* on remote spawing we have to set the connection-name now */ 
    17041712                        buffer_copy_string(proc->connection_name, "tcp:"); 
    1705                         buffer_append_string_buffer(proc->connection_name, host->host); 
     1713                        if (!buffer_is_empty(host->host)) { 
     1714                                buffer_append_string_buffer(proc->connection_name, host->host); 
     1715                        } else { 
     1716                                buffer_append_string(proc->connection_name, "localhost"); 
     1717                        } 
    17061718                        buffer_append_string(proc->connection_name, ":"); 
    17071719                        buffer_append_long(proc->connection_name, proc->port); 
    17081720                } 
     
    27192731 
    27202732        int ret; 
    27212733 
    2722         /* sanity check */ 
     2734        /* sanity check: 
     2735         *  - host != NULL 
     2736         *  - either: 
     2737         *     - tcp socket (do not check host->host->uses, as it may be not set which means INADDR_LOOPBACK) 
     2738         *     - unix socket 
     2739         */ 
    27232740        if (!host || 
    2724             ((!host->host->used || !host->port) && !host->unixsocket->used)) { 
     2741            (!host->port && !host->unixsocket->used)) { 
    27252742                log_error_write(srv, __FILE__, __LINE__, "sxddd", 
    27262743                                "write-req: error", 
    27272744                                host,