aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Dounin <mdounin@mdounin.ru>2021-01-12 16:59:31 +0300
committerMaxim Dounin <mdounin@mdounin.ru>2021-01-12 16:59:31 +0300
commite1ca9851220bb6d5f8e6b967635078f35a423c7c (patch)
tree0eedcbe3501e4ea2e4831b9f931fa57d10bec96d
parent7b6b8b62dd9a66e91da0a28b06941ddb5e312590 (diff)
downloadnginx-e1ca9851220bb6d5f8e6b967635078f35a423c7c.tar.gz
nginx-e1ca9851220bb6d5f8e6b967635078f35a423c7c.zip
Upstream: fixed zero size buf alerts on extra data (ticket #2117).
After 7675:9afa45068b8f and 7678:bffcc5af1d72 (1.19.1), during non-buffered simple proxying, responses with extra data might result in zero size buffers being generated and "zero size buf" alerts in writer. This bug is similar to the one with FastCGI proxying fixed in 7689:da8d758aabeb. In non-buffered mode, normally the filter function is not called if u->length is already 0, since u->length is checked after each call of the filter function. There is a case when this can happen though: if the response length is 0, and there are pre-read response body data left after reading response headers. As such, a check for u->length is needed at the start of non-buffered filter functions, similar to the one for p->length present in buffered filter functions. Appropriate checks added to the existing non-buffered copy filters in the upstream (used by scgi and uwsgi proxying) and proxy modules.
-rw-r--r--src/http/modules/ngx_http_proxy_module.c7
-rw-r--r--src/http/ngx_http_upstream.c7
2 files changed, 14 insertions, 0 deletions
diff --git a/src/http/modules/ngx_http_proxy_module.c b/src/http/modules/ngx_http_proxy_module.c
index 3d8768af6..77a1e0d7f 100644
--- a/src/http/modules/ngx_http_proxy_module.c
+++ b/src/http/modules/ngx_http_proxy_module.c
@@ -2334,6 +2334,13 @@ ngx_http_proxy_non_buffered_copy_filter(void *data, ssize_t bytes)
u = r->upstream;
+ if (u->length == 0) {
+ ngx_log_error(NGX_LOG_WARN, r->connection->log, 0,
+ "upstream sent more data than specified in "
+ "\"Content-Length\" header");
+ return NGX_OK;
+ }
+
for (cl = u->out_bufs, ll = &u->out_bufs; cl; cl = cl->next) {
ll = &cl->next;
}
diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c
index dda4046be..9cbb5a3b0 100644
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -3721,6 +3721,13 @@ ngx_http_upstream_non_buffered_filter(void *data, ssize_t bytes)
u = r->upstream;
+ if (u->length == 0) {
+ ngx_log_error(NGX_LOG_WARN, r->connection->log, 0,
+ "upstream sent more data than specified in "
+ "\"Content-Length\" header");
+ return NGX_OK;
+ }
+
for (cl = u->out_bufs, ll = &u->out_bufs; cl; cl = cl->next) {
ll = &cl->next;
}