If the slowcgi timeout fires before the command was actually started then
just abort the fastcgi request with error 408.

This can happen on POST requests where the client stops sending data.
Now bgplgd does not support POST but that is only checked once the full
fastcgi request from the webserver was received.

-- 
:wq Claudio

Index: slowcgi.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgplgd/slowcgi.c,v
retrieving revision 1.5
diff -u -p -r1.5 slowcgi.c
--- slowcgi.c   27 Oct 2022 13:24:22 -0000      1.5
+++ slowcgi.c   27 Oct 2022 14:12:40 -0000
@@ -159,6 +159,7 @@ void                parse_begin_request(uint8_t *, uin
 void           parse_params(uint8_t *, uint16_t, struct request *, uint16_t);
 void           parse_stdin(uint8_t *, uint16_t, struct request *, uint16_t);
 char           *env_get(struct request *, const char *);
+void           error_response(struct request *, int);
 void           exec_cgi(struct request *);
 void           script_std_in(int, short, void *);
 void           script_err_in(int, short, void *);
@@ -505,6 +506,12 @@ slowcgi_timeout(int fd, short events, vo
        if (c->script_flags & SCRIPT_DONE)
                return;
 
+       if (c->command_pid == 0) {
+               c->command_status = SIGALRM;
+               error_response(c, 408);
+               return;
+       }
+
        ldebug("timeout fired for pid %d", c->command_pid);
 
        if (c->timeout_fired)
@@ -887,7 +894,7 @@ http_error(int *res)
        return "Internal Server Error";
 }
 
-static void
+void
 error_response(struct request *c, int res)
 {
        const char *type = "text/html";

Reply via email to