summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn Strauss <gstrauss@gluelogic.com>2020-11-12 01:44:19 -0500
committerGlenn Strauss <gstrauss@gluelogic.com>2020-11-12 01:44:19 -0500
commit45aa1aa880f2aea4a6ef1a5f188d3b6480323b33 (patch)
tree446d1afe07de06155a14d09e06c6dfc69182a19f
parentfc19558f9675ffe433b525e95b37aa47033dd828 (diff)
downloadlighttpd-git-45aa1aa880f2aea4a6ef1a5f188d3b6480323b33.tar.gz
[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)
-rw-r--r--src/mod_cgi.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/mod_cgi.c b/src/mod_cgi.c
index 5a73ec2b..e6c15f54 100644
--- a/src/mod_cgi.c
+++ b/src/mod_cgi.c
@@ -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