# HG changeset patch # User Maxim Dounin <mdou...@mdounin.ru> # Date 1713574627 -10800 # Sat Apr 20 03:57:07 2024 +0300 # Node ID 3c408152180f04a54c44d482cf1c9c52b63480d9 # Parent ccd7e4022a2498a930c9e0927a9820f7ea17ae13 Reordered checks for Content-Length and Transfer-Encoding.
This ensures that r->headers_in.content_length_n is not set when both Content-Length and Transfer-Encoding headers are present, making it slightly safer to use complex processing for 400 (Bad Request) errors. diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c --- a/src/http/ngx_http_request.c +++ b/src/http/ngx_http_request.c @@ -1968,6 +1968,15 @@ ngx_http_process_request_header(ngx_http } if (r->headers_in.content_length) { + if (r->headers_in.transfer_encoding) { + ngx_log_error(NGX_LOG_INFO, r->connection->log, 0, + "client sent \"Content-Length\" and " + "\"Transfer-Encoding\" headers " + "at the same time"); + ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST); + return NGX_ERROR; + } + r->headers_in.content_length_n = ngx_atoof(r->headers_in.content_length->value.data, r->headers_in.content_length->value.len); @@ -1993,15 +2002,6 @@ ngx_http_process_request_header(ngx_http && ngx_strncasecmp(r->headers_in.transfer_encoding->value.data, (u_char *) "chunked", 7) == 0) { - if (r->headers_in.content_length) { - ngx_log_error(NGX_LOG_INFO, r->connection->log, 0, - "client sent \"Content-Length\" and " - "\"Transfer-Encoding\" headers " - "at the same time"); - ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST); - return NGX_ERROR; - } - r->headers_in.chunked = 1; } else { -- nginx-devel mailing list nginx-devel@freenginx.org https://freenginx.org/mailman/listinfo/nginx-devel