Handle FastCGI null request IDs better

This commit is contained in:
Přemysl Eric Janouch 2018-10-15 03:04:39 +02:00
parent 14ded260a0
commit 441c89f654
Signed by: p
GPG Key ID: A0420B94F92B9493
1 changed files with 24 additions and 8 deletions

View File

@ -276,6 +276,13 @@ static void
fcgi_muxer_on_get_values fcgi_muxer_on_get_values
(struct fcgi_muxer *self, const struct fcgi_parser *parser) (struct fcgi_muxer *self, const struct fcgi_parser *parser)
{ {
if (parser->request_id != FCGI_NULL_REQUEST_ID)
{
print_debug ("FastCGI: ignoring invalid %s message",
STRINGIFY (FCGI_GET_VALUES));
return;
}
struct str_map values = str_map_make (free); struct str_map values = str_map_make (free);
struct str_map response = str_map_make (free); struct str_map response = str_map_make (free);
@ -330,6 +337,13 @@ fcgi_muxer_on_begin_request
return; return;
} }
struct fcgi_request *request = self->requests[parser->request_id];
if (parser->request_id == FCGI_NULL_REQUEST_ID || request)
{
// TODO: fail
return;
}
// We can only act as a responder, reject everything else up front // We can only act as a responder, reject everything else up front
if (role != FCGI_RESPONDER) if (role != FCGI_RESPONDER)
{ {
@ -338,10 +352,11 @@ fcgi_muxer_on_begin_request
return; return;
} }
struct fcgi_request *request = self->requests[parser->request_id]; // TODO: also send OVERLOADED when shutting down?
if (request) if (parser->request_id >= N_ELEMENTS (self->requests))
{ {
// TODO: fail fcgi_muxer_send_end_request (self,
parser->request_id, 0, FCGI_OVERLOADED);
return; return;
} }
@ -359,21 +374,22 @@ fcgi_muxer_on_abort_request
(struct fcgi_muxer *self, const struct fcgi_parser *parser) (struct fcgi_muxer *self, const struct fcgi_parser *parser)
{ {
struct fcgi_request *request = self->requests[parser->request_id]; struct fcgi_request *request = self->requests[parser->request_id];
if (!request) if (parser->request_id == FCGI_NULL_REQUEST_ID || !request)
{ {
print_debug ("FastCGI: received %s for an unknown request", print_debug ("FastCGI: received %s for an unknown request",
STRINGIFY (FCGI_ABORT_REQUEST)); STRINGIFY (FCGI_ABORT_REQUEST));
return; return;
} }
// TODO: abort the request: let it somehow produce FCGI_END_REQUEST // TODO: abort the request: let it somehow produce FCGI_END_REQUEST,
// make sure to send an stdout EOF record
} }
static void static void
fcgi_muxer_on_params (struct fcgi_muxer *self, const struct fcgi_parser *parser) fcgi_muxer_on_params (struct fcgi_muxer *self, const struct fcgi_parser *parser)
{ {
struct fcgi_request *request = self->requests[parser->request_id]; struct fcgi_request *request = self->requests[parser->request_id];
if (!request) if (parser->request_id == FCGI_NULL_REQUEST_ID || !request)
{ {
print_debug ("FastCGI: received %s for an unknown request", print_debug ("FastCGI: received %s for an unknown request",
STRINGIFY (FCGI_PARAMS)); STRINGIFY (FCGI_PARAMS));
@ -388,7 +404,7 @@ static void
fcgi_muxer_on_stdin (struct fcgi_muxer *self, const struct fcgi_parser *parser) fcgi_muxer_on_stdin (struct fcgi_muxer *self, const struct fcgi_parser *parser)
{ {
struct fcgi_request *request = self->requests[parser->request_id]; struct fcgi_request *request = self->requests[parser->request_id];
if (!request) if (parser->request_id == FCGI_NULL_REQUEST_ID || !request)
{ {
print_debug ("FastCGI: received %s for an unknown request", print_debug ("FastCGI: received %s for an unknown request",
STRINGIFY (FCGI_STDIN)); STRINGIFY (FCGI_STDIN));