Forum

FastCGI Unix domain socket problem

bkh1957
8 July 2013, 19:15
First of all, I would like to thank you Hugo for the fantastic HTTP server you've developed.

I've configured Hiawatha to connect to my FastCGI process using a Unix domain socket (e.g. /var/run/fastcgi/process1.socket) rather than a host. This used to work fine on Hiawatha 8.3 (and perhaps later versions too). But it's broken on 9.2. The following patch fixed the problem for me.
--- ../hiawatha-9.2/src/target.c	2013-06-23 03:28:07.000000000 -0700
+++ src/target.c 2013-07-08 09:43:32.797505768 -0700
@@ -481,7 +481,8 @@

if ((wrap_cgi == false) && (session->cgi_type != fastcgi)) {
check_file_exists = true;
- } else if ((session->cgi_type == fastcgi) && (session->fcgi_server != NULL)) {
+ } else if ((session->cgi_type == fastcgi) && (session->fcgi_server != NULL) &&
+ (session->fcgi_server->connect_to != NULL) && (session->fcgi_server->connect_to->unix_socket == NULL)) {
check_file_exists = session->fcgi_server->localhost;
} else {
check_file_exists = false;


Hiawatha version: 9.2
Operating System: FreeBSD 9.1
Hugo Leisink
8 July 2013, 19:35
The patch you supplied is not correct. It can lead to a crash because session->fcgi_server can be NULL. The code you changed has nothing to do with the working of FastCGI support. Can you tell me what you mean by 'broken'?
bkh1957
8 July 2013, 20:03
Hi Hugo

Thanks for the quick response.

Hiawatha 9.2 returns 404 when attempting to connect to a FastCGI process using a Unix domain socket (but it works fine when connecting to a host). The problem appears to be in target.c at lines 484 and 485 where "check_file_exists" is set to true. Then, at line 491, the call to "open(session->file_on_disk, O_RDONLY)" fails and 404 is returned since, on my FreeBSD server, "session->file_on_disk" is the requested FastCGI URL not the path to the domain socket. After applying the patch, I can again connect to my FastCGI process via a domain socket.

The "if" statement in the patch tests both "session->fcgi_server" and "session->fcgi_server->connect_to" before dereferencing them. Isn't that enough to prevent a crash?

Brad
Hugo Leisink
9 July 2013, 15:19
Try this code at that spot:
    if ((wrap_cgi == false) && (session->cgi_type != fastcgi)) {
check_file_exists = true;
} else {
check_file_exists = false;
}
bkh1957
9 July 2013, 22:57
Hi Hugo

That completely and simply solves the problem. Thanks.

Brad
This topic has been closed.