[mod_cgi] ensure tmp file open() before splice()

(bug on master branch)

With lighttpd defaults, including fully buffering request body, and
if request body > 1 MB, then multiple temporary files are used and
might not have open fd in chunkqueue.  This would result in failure
to send request body to CGI. (bug commited to master branch 1 month ago)
This commit is contained in:
Glenn Strauss 2020-11-12 01:44:19 -05:00
parent fc19558f96
commit 45aa1aa880
1 changed files with 8 additions and 8 deletions

View File

@ -563,6 +563,14 @@ static ssize_t cgi_write_file_chunk_mmap(request_st * const r, int fd, chunkqueu
return 0;
}
/*(simplified from chunk.c:chunkqueue_open_file_chunk())*/
if (-1 == c->file.fd) {
if (-1 == (c->file.fd = fdevent_open_cloexec(c->mem->ptr, r->conf.follow_symlink, O_RDONLY, 0))) {
log_perror(r->conf.errh, __FILE__, __LINE__, "open failed: %s", c->mem->ptr);
return -1;
}
}
#ifdef SPLICE_F_NONBLOCK
loff_t abs_offset = offset;
wr = splice(c->file.fd, &abs_offset, fd, NULL,
@ -572,14 +580,6 @@ static ssize_t cgi_write_file_chunk_mmap(request_st * const r, int fd, chunkqueu
char *data = NULL;
off_t file_end = c->file.length; /* offset to file end in this chunk */
/*(simplified from chunk.c:chunkqueue_open_file_chunk())*/
if (-1 == c->file.fd) {
if (-1 == (c->file.fd = fdevent_open_cloexec(c->mem->ptr, r->conf.follow_symlink, O_RDONLY, 0))) {
log_perror(r->conf.errh, __FILE__, __LINE__, "open failed: %s", c->mem->ptr);
return -1;
}
}
/* (re)mmap the buffer if range is not covered completely */
if (MAP_FAILED == c->file.mmap.start
|| offset < c->file.mmap.offset