handle CGI scripts that replies with the maximum header length allowed

the 1024 bytes limits is for the META only, not for the whole
response.  That means that the maximum size for the header line is
1029!
This commit is contained in:
Omar Polo 2021-03-29 09:42:06 +00:00
parent 071dce449d
commit c836cdfadb
5 changed files with 15 additions and 1 deletions

View File

@ -1,3 +1,7 @@
2021-03-27 Omar Polo <op@omarpolo.com>
* gmid.h (struct client): correctly handle CGI scripts that replies with the maximum header length allowed
2021-03-20 Omar Polo <op@omarpolo.com> 2021-03-20 Omar Polo <op@omarpolo.com>
* 1.6 tagged * 1.6 tagged

5
gmid.h
View File

@ -180,8 +180,11 @@ struct client {
const char *meta; const char *meta;
int fd, pfd; int fd, pfd;
DIR *dir; DIR *dir;
char sbuf[1024];
/* big enough to store STATUS + SPACE + META + CRLF */
char sbuf[1029];
ssize_t len, off; ssize_t len, off;
struct sockaddr_storage addr; struct sockaddr_storage addr;
struct vhost *host; /* host they're talking to */ struct vhost *host; /* host they're talking to */
}; };

View File

@ -68,6 +68,7 @@ testdata: fill-file
printf "# hello world\n" > testdata/index.gmi printf "# hello world\n" > testdata/index.gmi
./sha testdata/index.gmi testdata/index.gmi.sha ./sha testdata/index.gmi testdata/index.gmi.sha
cp hello slow err invalid serve-bigfile env testdata/ cp hello slow err invalid serve-bigfile env testdata/
cp max-length-reply testdata
mkdir testdata/dir mkdir testdata/dir
cp hello testdata/dir cp hello testdata/dir
cp testdata/index.gmi testdata/dir/foo.gmi cp testdata/index.gmi testdata/dir/foo.gmi

3
regress/max-length-reply Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
printf '20 iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii\r\n'

View File

@ -183,6 +183,9 @@ echo OK GET /err with cgi
eq "$(raw /invalid | wc -c | xargs)" 2048 "Unexpected body for /invalid" eq "$(raw /invalid | wc -c | xargs)" 2048 "Unexpected body for /invalid"
echo OK GET /invalid with cgi echo OK GET /invalid with cgi
eq "$(raw /max-length-reply | wc -c | xargs)" 1029 "Unexpected header for /max-length-reply"
echo OK GET /max-length-reply with cgi
# try a big file # try a big file
eq "$(head /serve-bigfile)" "20 application/octet-stream" "Unexpected head for /serve-bigfile" eq "$(head /serve-bigfile)" "20 application/octet-stream" "Unexpected head for /serve-bigfile"
get /bigfile > bigfile get /bigfile > bigfile