1
0
mirror of https://github.com/openbsd/src.git synced 2026-06-18 07:13:36 +02:00

Don't fail hard on version mismatch and ignore extra end-of-params messages.

Replace the lerrx on version mismatch with a lwarnx and error return.
Switch to ssize_t return for that so that slowcgi_request() can properly
fail when this happens.

Also do not execute multiple commands when extra end-of-params messages
are received. Once a command is executed fail to start a 2nd one.

Same diff as bgplgd rev. 1.9
Reported by Frank Denis
OK florian@ tb@
This commit is contained in:
claudio
2026-05-31 11:26:24 +00:00
parent e284402f0d
commit 4a8414cfbd
+14 -7
View File
@@ -1,4 +1,4 @@
/* $OpenBSD: slowcgi.c,v 1.64 2022/08/07 07:43:53 op Exp $ */
/* $OpenBSD: slowcgi.c,v 1.65 2026/05/31 11:26:24 claudio Exp $ */
/*
* Copyright (c) 2013 David Gwynne <dlg@openbsd.org>
* Copyright (c) 2013 Florian Obser <florian@openbsd.org>
@@ -170,7 +170,7 @@ void slowcgi_response(int, short, void *);
void slowcgi_add_response(struct request *, struct fcgi_response *);
void slowcgi_timeout(int, short, void *);
void slowcgi_sig_handler(int, short, void *);
size_t parse_record(uint8_t * , size_t, struct request *);
ssize_t parse_record(uint8_t * , size_t, struct request *);
void parse_begin_request(uint8_t *, uint16_t, struct request *,
uint16_t);
void parse_params(uint8_t *, uint16_t, struct request *, uint16_t);
@@ -624,8 +624,7 @@ void
slowcgi_request(int fd, short events, void *arg)
{
struct request *c;
ssize_t n;
size_t parsed;
ssize_t n, parsed;
c = arg;
@@ -660,6 +659,8 @@ slowcgi_request(int fd, short events, void *arg)
*/
do {
parsed = parse_record(c->buf + c->buf_pos, c->buf_len, c);
if (parsed == -1)
goto fail;
c->buf_pos += parsed;
c->buf_len -= parsed;
} while (parsed > 0 && c->buf_len > 0);
@@ -717,6 +718,10 @@ parse_params(uint8_t *buf, uint16_t n, struct request *c, uint16_t id)
* begin execution of the CGI script.
*/
if (n == 0) {
if (c->script_pid != 0) {
lwarnx("extra end-of-param, ignoring");
return;
}
exec_cgi(c);
return;
}
@@ -820,7 +825,7 @@ parse_stdin(uint8_t *buf, uint16_t n, struct request *c, uint16_t id)
event_add(&c->script_stdin_ev, NULL);
}
size_t
ssize_t
parse_record(uint8_t *buf, size_t n, struct request *c)
{
struct fcgi_record_header *h;
@@ -837,8 +842,10 @@ parse_record(uint8_t *buf, size_t n, struct request *c)
+ h->padding_len)
return (0);
if (h->version != 1)
lerrx(1, "wrong version");
if (h->version != 1) {
lwarnx("wrong version");
return (-1);
}
switch (h->type) {
case FCGI_BEGIN_REQUEST: