]> git.kaiwu.me - nginx.git/commitdiff
Request body: explicit handling of NGX_AGAIN.
authorMaxim Dounin <mdounin@mdounin.ru>
Sat, 30 Mar 2024 02:06:59 +0000 (05:06 +0300)
committerRoman Arutyunyan <arutyunyan.roman@gmail.com>
Wed, 11 Nov 2026 12:15:24 +0000 (16:15 +0400)
Request body reading indirectly uses the "do { c->recv() } while
(c->read->ready)" form, which is not really correct, as for example with
SSL c->read->ready may be still set when c->recv() returns NGX_AGAIN due
to SSL_ERROR_WANT_WRITE (see 7351:2b5528023f6b), and therefore this form
might be an infinite loop.

Added explicit NGX_AGAIN handling for the sake of correctness.

Signed-off-by: Elijah Zupancic <e.zupancic@f5.com>
Origin: <https://freenginx.org/hg/nginx/rev/392e8e2fd22a8461e75a67d5d33d85c07974e1e3>

src/http/ngx_http_request_body.c

index d9d0c22e3961ff35eba5d59f3b353a9818570944..5bd965b2c1d0c6115cb4894e46a92857ad0a4b2d 100644 (file)
@@ -307,6 +307,7 @@ ngx_http_do_read_client_request_body(ngx_http_request_t *r)
     c = r->connection;
     rb = r->request_body;
     flush = 1;
+    n = NGX_AGAIN;
 
     ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
                    "http read client request body");
@@ -432,7 +433,7 @@ ngx_http_do_read_client_request_body(ngx_http_request_t *r)
             break;
         }
 
-        if (!c->read->ready || rb->rest == 0) {
+        if (n == NGX_AGAIN || !c->read->ready || rb->rest == 0) {
 
             clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
             ngx_add_timer(c->read, clcf->client_body_timeout);