Project

General

Profile

Bug #841 » lighttpd_fix_841.patch

fix #841: Segmentation fault using fastcgi / php5-cgi - stbuehler, 2008-01-15 23:10

View differences:

src/mod_fastcgi.c
* if host is one of the local IP adresses the
* whole connection is local
*
* if tcp/ip should be used host AND port have
* to be specified
* if port is not 0, and host is not specified,
* "localhost" (INADDR_LOOPBACK) is assumed.
*
*/
buffer *host;
......
fcgi_addr_in.sin_family = AF_INET;
if (buffer_is_empty(host->host)) {
fcgi_addr_in.sin_addr.s_addr = htonl(INADDR_ANY);
fcgi_addr_in.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
} else {
struct hostent *he;
/* set a useful default */
fcgi_addr_in.sin_addr.s_addr = htonl(INADDR_ANY);
fcgi_addr_in.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
if (NULL == (he = gethostbyname(host->host->ptr))) {
......
fcgi_addr = (struct sockaddr *) &fcgi_addr_in;
buffer_copy_string(proc->connection_name, "tcp:");
buffer_append_string_buffer(proc->connection_name, host->host);
if (!buffer_is_empty(host->host)) {
buffer_append_string_buffer(proc->connection_name, host->host);
} else {
buffer_append_string(proc->connection_name, "localhost");
}
buffer_append_string(proc->connection_name, ":");
buffer_append_long(proc->connection_name, proc->port);
}
......
#endif
} else {
fcgi_addr_in.sin_family = AF_INET;
if (0 == inet_aton(host->host->ptr, &(fcgi_addr_in.sin_addr))) {
log_error_write(srv, __FILE__, __LINE__, "sbs",
"converting IP address failed for", host->host,
"\nBe sure to specify an IP address here");
return -1;
if (!buffer_is_empty(host->host)) {
if (0 == inet_aton(host->host->ptr, &(fcgi_addr_in.sin_addr))) {
log_error_write(srv, __FILE__, __LINE__, "sbs",
"converting IP address failed for", host->host,
"\nBe sure to specify an IP address here");
return -1;
}
} else {
fcgi_addr_in.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
}
fcgi_addr_in.sin_port = htons(proc->port);
servlen = sizeof(fcgi_addr_in);
......
if (buffer_is_empty(proc->connection_name)) {
/* on remote spawing we have to set the connection-name now */
buffer_copy_string(proc->connection_name, "tcp:");
buffer_append_string_buffer(proc->connection_name, host->host);
if (!buffer_is_empty(host->host)) {
buffer_append_string_buffer(proc->connection_name, host->host);
} else {
buffer_append_string(proc->connection_name, "localhost");
}
buffer_append_string(proc->connection_name, ":");
buffer_append_long(proc->connection_name, proc->port);
}
......
int ret;
/* sanity check */
/* sanity check:
* - host != NULL
* - either:
* - tcp socket (do not check host->host->uses, as it may be not set which means INADDR_LOOPBACK)
* - unix socket
*/
if (!host ||
((!host->host->used || !host->port) && !host->unixsocket->used)) {
(!host->port && !host->unixsocket->used)) {
log_error_write(srv, __FILE__, __LINE__, "sxddd",
"write-req: error",
host,
(2-2/2)