Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nginx/nginx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Dounin <mdounin@mdounin.ru>2017-01-20 21:12:48 +0300
committerMaxim Dounin <mdounin@mdounin.ru>2017-01-20 21:12:48 +0300
commit7ca4b6743d3bcbce1d2a1f024af406afe3c26025 (patch)
treeccaa6c61cb5a946f3c256c51356a7e23a1f7da3b /src/core/ngx_buf.c
parentc3ad24da01c062eaa4eb096f85f9be2312316821 (diff)
Fixed trailer construction with limit on FreeBSD and macOS.
The ngx_chain_coalesce_file() function may produce more bytes to send then requested in the limit passed, as it aligns the last file position to send to memory page boundary. As a result, (limit - send) may become negative. This resulted in big positive number when converted to size_t while calling ngx_output_chain_to_iovec(). Another part of the problem is in ngx_chain_coalesce_file(): it changes cl to the next chain link even if the current buffer is only partially sent due to limit. Therefore, if a file buffer was not expected to be fully sent due to limit, and was followed by a memory buffer, nginx called sendfile() with a part of the file buffer, and the memory buffer in trailer. If there were enough room in the socket buffer, this resulted in a part of the file buffer being skipped, and corresponding part of the memory buffer sent instead. The bug was introduced in 8e903522c17a (1.7.8). Configurations affected are ones using limits, that is, limit_rate and/or sendfile_max_chunk, and memory buffers after file ones (may happen when using subrequests or with proxying with disk buffering). Fix is to explicitly check if (send < limit) before constructing trailer with ngx_output_chain_to_iovec(). Additionally, ngx_chain_coalesce_file() was modified to preserve unfinished file buffers in cl.
Diffstat (limited to 'src/core/ngx_buf.c')
-rw-r--r--src/core/ngx_buf.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/core/ngx_buf.c b/src/core/ngx_buf.c
index d30a0a4fc..1862a0606 100644
--- a/src/core/ngx_buf.c
+++ b/src/core/ngx_buf.c
@@ -246,6 +246,9 @@ ngx_chain_coalesce_file(ngx_chain_t **in, off_t limit)
if (aligned <= cl->buf->file_last) {
size = aligned - cl->buf->file_pos;
}
+
+ total += size;
+ break;
}
total += size;