Skip to content

Commit ff45244

Browse files
committed
Proper fix for bug #37205
1 parent 522ce80 commit ff45244

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

sapi/cgi/fastcgi.c

+13
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ static int fcgi_read_request(fcgi_request *req)
441441
unsigned char buf[FCGI_MAX_LENGTH+8];
442442

443443
req->keep = 0;
444+
req->has_in = 0;
444445
req->in_len = 0;
445446
req->out_hdr = NULL;
446447
req->out_pos = req->out_buf;
@@ -509,6 +510,15 @@ static int fcgi_read_request(fcgi_request *req)
509510
len = (hdr.contentLengthB1 << 8) | hdr.contentLengthB0;
510511
padding = hdr.paddingLength;
511512
}
513+
if (safe_read(req, &hdr, sizeof(fcgi_header)) != sizeof(fcgi_header) ||
514+
hdr.version < FCGI_VERSION_1 ||
515+
hdr.type != FCGI_STDIN) {
516+
req->keep = 0;
517+
return 0;
518+
}
519+
req->in_len = (hdr.contentLengthB1 << 8) | hdr.contentLengthB0;
520+
req->in_pad = hdr.paddingLength;
521+
req->has_in = (req->in_len != 0);
512522
} else if (hdr.type == FCGI_GET_VALUES) {
513523
int i, j;
514524
int name_len;
@@ -551,6 +561,9 @@ int fcgi_read(fcgi_request *req, char *str, int len)
551561
fcgi_header hdr;
552562
unsigned char buf[8];
553563

564+
if (!req->has_in) {
565+
return 0;
566+
}
554567
n = 0;
555568
rest = len;
556569
while (rest > 0) {

sapi/cgi/fastcgi.h

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ typedef struct _fcgi_request {
9797
int id;
9898
int keep;
9999

100+
int has_in;
100101
int in_len;
101102
int in_pad;
102103

0 commit comments

Comments
 (0)