]> git.kaiwu.me - nginx.git/log
nginx.git
6 years agoRemoved "Transfer-Encoding: identity" support.
Maxim Dounin [Thu, 20 Feb 2020 13:19:34 +0000 (16:19 +0300)]
Removed "Transfer-Encoding: identity" support.

The "identity" transfer coding has been removed in RFC 7230.  It is
believed that it is not used in real life, and at the same time it
provides a potential attack vector.

6 years agoDisabled multiple Transfer-Encoding headers.
Maxim Dounin [Thu, 20 Feb 2020 13:19:29 +0000 (16:19 +0300)]
Disabled multiple Transfer-Encoding headers.

We anyway do not support more than one transfer encoding, so accepting
requests with multiple Transfer-Encoding headers doesn't make sense.
Further, we do not handle multiple headers, and ignore anything but
the first header.

Reported by Filippo Valsorda.

6 years agoMade ngx_http_get_forwarded_addr_internal() non-recursive.
Vladimir Homutov [Tue, 11 Feb 2020 10:22:44 +0000 (13:22 +0300)]
Made ngx_http_get_forwarded_addr_internal() non-recursive.

6 years agoHTTP/2: fixed socket leak with an incomplete HEADERS frame.
Sergey Kandaurov [Wed, 5 Feb 2020 13:29:23 +0000 (16:29 +0300)]
HTTP/2: fixed socket leak with an incomplete HEADERS frame.

A connection could get stuck without timers if a client has partially sent
the HEADERS frame such that it was split on the individual header boundary.
In this case, it cannot be processed without the rest of the HEADERS frame.

The fix is to call ngx_http_v2_state_headers_save() in this case.  Normally,
it would be called from the ngx_http_v2_state_header_block() handler on the
next iteration, when there is not enough data to continue processing.  This
isn't the case if recv_buffer became empty and there's no more data to read.

6 years agoVersion bump.
Sergey Kandaurov [Wed, 5 Feb 2020 13:29:14 +0000 (16:29 +0300)]
Version bump.

6 years agorelease-1.17.8 tag
Maxim Dounin [Tue, 21 Jan 2020 13:39:42 +0000 (16:39 +0300)]
release-1.17.8 tag

6 years agonginx-1.17.8-RELEASE release-1.17.8
Maxim Dounin [Tue, 21 Jan 2020 13:39:41 +0000 (16:39 +0300)]
nginx-1.17.8-RELEASE

6 years agogRPC: variables support in the "grpc_pass" directive.
Vladimir Homutov [Fri, 17 Jan 2020 09:13:02 +0000 (12:13 +0300)]
gRPC: variables support in the "grpc_pass" directive.

6 years agoHTTP/2: removed ngx_debug_point() call.
Daniil Bondarev [Tue, 14 Jan 2020 11:20:08 +0000 (14:20 +0300)]
HTTP/2: removed ngx_debug_point() call.
    
With the recent change to prevent frames flood in d4448892a294,
nginx will finalize the connection with NGX_HTTP_V2_INTERNAL_ERROR
whenever flood is detected, causing nginx aborting or stopping if
the debug_points directive is used in nginx config.

6 years agoSSL: reworked posted next events again.
Maxim Dounin [Fri, 27 Dec 2019 16:43:01 +0000 (19:43 +0300)]
SSL: reworked posted next events again.

Previous change 1ce3f01a4355 incorrectly introduced processing of the
ngx_posted_next_events queue at the end of operation, effectively making
posted next events a nop, since at the end of an event loop iteration
the queue is always empty.  Correct approach is to move events to the
ngx_posted_events queue at an iteration start, as it was done previously.

Further, in some cases the c->read event might be already in the
ngx_posted_events queue, and calling ngx_post_event() with the
ngx_posted_next_events queue won't do anything.  To make sure the event
will be correctly placed into the ngx_posted_next_events queue
we now check if it is already posted.

6 years agoTrailing space removed.
Maxim Dounin [Fri, 27 Dec 2019 14:20:25 +0000 (17:20 +0300)]
Trailing space removed.

6 years agoVersion bump.
Maxim Dounin [Fri, 27 Dec 2019 14:20:20 +0000 (17:20 +0300)]
Version bump.

6 years agorelease-1.17.7 tag
Maxim Dounin [Tue, 24 Dec 2019 15:00:09 +0000 (18:00 +0300)]
release-1.17.7 tag

6 years agonginx-1.17.7-RELEASE release-1.17.7
Maxim Dounin [Tue, 24 Dec 2019 15:00:09 +0000 (18:00 +0300)]
nginx-1.17.7-RELEASE

6 years agoSSL: reworked posted next events.
Maxim Dounin [Tue, 24 Dec 2019 14:24:59 +0000 (17:24 +0300)]
SSL: reworked posted next events.

Introduced in 9d2ad2fb4423 available bytes handling in SSL relied
on connection read handler being overwritten to set the ready flag
and the amount of available bytes.  This approach is, however, does
not work properly when connection read handler is changed, for example,
when switching to a next pipelined request, and can result in unexpected
connection timeouts, see here:

http://mailman.nginx.org/pipermail/nginx-devel/2019-December/012825.html

Fix is to introduce ngx_event_process_posted_next() instead, which
will set ready and available regardless of how event handler is set.

6 years agoHTTP/2: introduced separate handler to retry stream close.
Maxim Dounin [Mon, 23 Dec 2019 18:25:21 +0000 (21:25 +0300)]
HTTP/2: introduced separate handler to retry stream close.

When ngx_http_v2_close_stream_handler() is used to retry stream close
after queued frames are sent, client timeouts on the stream can be
logged multiple times and/or in addition to already happened errors.
To resolve this, separate ngx_http_v2_retry_close_stream_handler()
was introduced, which does not try to log timeouts.

6 years agoHTTP/2: fixed socket leak with queued frames (ticket #1689).
Maxim Dounin [Mon, 23 Dec 2019 18:25:17 +0000 (21:25 +0300)]
HTTP/2: fixed socket leak with queued frames (ticket #1689).

If a stream is closed with queued frames, it is possible that no further
write events will occur on the stream, leading to the socket leak.
To fix this, the stream's fake connection read handler is set to
ngx_http_v2_close_stream_handler(), to make sure that finalizing the
connection with ngx_http_v2_finalize_connection() will be able to
close the stream regardless of the current number of queued frames.

Additionally, the stream's fake connection fc->error flag is explicitly
set, so ngx_http_v2_handle_stream() will post a write event when queued
frames are finally sent even if stream flow control window is exhausted.

6 years agoDav: added checks for chunked to body presence conditions.
Maxim Dounin [Mon, 23 Dec 2019 17:39:27 +0000 (20:39 +0300)]
Dav: added checks for chunked to body presence conditions.

These checks were missed when chunked support was introduced.  And also
added an explicit error message to ngx_http_dav_copy_move_handler()
(it was missed for some reason, in contrast to DELETE and MKCOL handlers).

6 years agoUpdate manpage, sort command line options.
Sergey A. Osokin [Mon, 23 Dec 2019 15:56:21 +0000 (18:56 +0300)]
Update manpage, sort command line options.

6 years agoDiscard request body when redirecting to a URL via error_page.
Ruslan Ermilov [Mon, 23 Dec 2019 12:45:46 +0000 (15:45 +0300)]
Discard request body when redirecting to a URL via error_page.

Reported by Bert JW Regeer and Francisco Oca Gonzalez.

6 years agoRewrite: disallow empty replacements.
Ruslan Ermilov [Mon, 16 Dec 2019 12:19:01 +0000 (15:19 +0300)]
Rewrite: disallow empty replacements.

While empty replacements were caught at run-time, parsing code
of the "rewrite" directive expects that a minimum length of the
"replacement" argument is 1.

6 years agoTolerate '\0' in URI when mapping URI to path.
Ruslan Ermilov [Mon, 16 Dec 2019 12:19:01 +0000 (15:19 +0300)]
Tolerate '\0' in URI when mapping URI to path.

If a rewritten URI has the null character, only a part of URI was
copied to a memory buffer allocated for path.  In some setups this
could be exploited to expose uninitialized memory via the Location
header.

6 years agoRewrite: fixed segfault with rewritten URI and "alias".
Ruslan Ermilov [Mon, 16 Dec 2019 12:19:01 +0000 (15:19 +0300)]
Rewrite: fixed segfault with rewritten URI and "alias".

The "alias" directive cannot be used in the same location where URI
was rewritten.  This has been detected in the "rewrite ... break"
case, but not when the standalone "break" directive was used.

This change also fixes proxy_pass with URI component in a similar
case:

       location /aaa/ {
           rewrite ^ /xxx/yyy;
           break;
           proxy_pass http://localhost:8080/bbb/;
       }

Previously, the "/bbb/yyy" would be sent to a backend instead of
"/xxx/yyy".  And if location's prefix was longer than the rewritten
URI, a segmentation fault might occur.

6 years agoFixed request finalization in ngx_http_index_handler().
Ruslan Ermilov [Mon, 16 Dec 2019 12:19:01 +0000 (15:19 +0300)]
Fixed request finalization in ngx_http_index_handler().

Returning 500 instead of NGX_ERROR is preferable here because
header has not yet been sent to the client.

6 years agoSaved some memory allocations.
Ruslan Ermilov [Mon, 16 Dec 2019 12:19:01 +0000 (15:19 +0300)]
Saved some memory allocations.

In configurations when "root" has variables, some modules unnecessarily
allocated memory for the "Location" header value.

6 years agoDav: fixed Location in successful MKCOL response.
Ruslan Ermilov [Mon, 16 Dec 2019 12:19:01 +0000 (15:19 +0300)]
Dav: fixed Location in successful MKCOL response.

Instead of reducing URI length to not include the terminating '\0'
character in 6ddaac3e0bf7, restore the terminating '/' character.

6 years agoUpstream keepalive: clearing of c->data in cached connections.
Maxim Dounin [Thu, 5 Dec 2019 16:38:06 +0000 (19:38 +0300)]
Upstream keepalive: clearing of c->data in cached connections.

Previously, connections returned from keepalive cache had c->data
pointing to the keepalive cache item.  While this shouldn't be a problem
for correct code, as c->data is not expected to be used before it is set,
explicitly clearing it might help to avoid confusion.

6 years agoVersion bump.
Maxim Dounin [Thu, 5 Dec 2019 16:22:48 +0000 (19:22 +0300)]
Version bump.

6 years agorelease-1.17.6 tag
Maxim Dounin [Tue, 19 Nov 2019 14:18:58 +0000 (17:18 +0300)]
release-1.17.6 tag

6 years agonginx-1.17.6-RELEASE release-1.17.6
Maxim Dounin [Tue, 19 Nov 2019 14:18:58 +0000 (17:18 +0300)]
nginx-1.17.6-RELEASE

6 years agoLimit conn: added shared context.
Roman Arutyunyan [Mon, 18 Nov 2019 16:50:59 +0000 (19:50 +0300)]
Limit conn: added shared context.

Previously only an rbtree was associated with a limit_conn.  To make it
possible to associate more data with a limit_conn, shared context is introduced
similar to limit_req.  Also, shared pool pointer is kept in a way similar to
limit_req.

6 years agoLimit conn: $limit_conn_status variable.
Roman Arutyunyan [Mon, 18 Nov 2019 14:48:32 +0000 (17:48 +0300)]
Limit conn: $limit_conn_status variable.

The variable takes one of the values: PASSED, REJECTED or REJECTED_DRY_RUN.

6 years agoLimit conn: limit_conn_dry_run directive.
Roman Arutyunyan [Tue, 19 Nov 2019 08:30:41 +0000 (11:30 +0300)]
Limit conn: limit_conn_dry_run directive.

A new directive limit_conn_dry_run allows enabling the dry run mode.  In this
mode connections are not rejected, but reject status is logged as usual.

6 years agoUpdated comment after 776d1bebdca2.
Roman Arutyunyan [Mon, 18 Nov 2019 14:46:52 +0000 (17:46 +0300)]
Updated comment after 776d1bebdca2.

6 years agoLimit req: $limit_req_status variable.
Roman Arutyunyan [Wed, 6 Nov 2019 16:03:18 +0000 (19:03 +0300)]
Limit req: $limit_req_status variable.

The variable takes one of the values: PASSED, DELAYED, REJECTED,
DELAYED_DRY_RUN or REJECTED_DRY_RUN.

6 years agoParsing server PROXY protocol address and port (ticket #1206).
Roman Arutyunyan [Mon, 21 Oct 2019 17:22:30 +0000 (20:22 +0300)]
Parsing server PROXY protocol address and port (ticket #1206).

New variables $proxy_protocol_server_addr and $proxy_protocol_server_port are
added both to HTTP and Stream.

6 years agoCore: moved PROXY protocol fields out of ngx_connection_t.
Roman Arutyunyan [Mon, 21 Oct 2019 15:06:19 +0000 (18:06 +0300)]
Core: moved PROXY protocol fields out of ngx_connection_t.

Now a new structure ngx_proxy_protocol_t holds these fields.  This allows
to add more PROXY protocol fields in the future without modifying the
connection structure.

6 years agoVersion bump.
Roman Arutyunyan [Thu, 24 Oct 2019 10:47:28 +0000 (13:47 +0300)]
Version bump.

6 years agorelease-1.17.5 tag
Maxim Dounin [Tue, 22 Oct 2019 15:16:08 +0000 (18:16 +0300)]
release-1.17.5 tag

6 years agonginx-1.17.5-RELEASE release-1.17.5
Maxim Dounin [Tue, 22 Oct 2019 15:16:08 +0000 (18:16 +0300)]
nginx-1.17.5-RELEASE

6 years agoWin32: silenced -Wcast-function-type GCC warning (ticket #1865).
Maxim Dounin [Mon, 21 Oct 2019 16:07:03 +0000 (19:07 +0300)]
Win32: silenced -Wcast-function-type GCC warning (ticket #1865).

With MinGW-w64, building 64-bit nginx binary with GCC 8 and above
results in warning due to cast of GetProcAddress() result to ngx_wsapoll_pt,
which GCC thinks is incorrect.  Added intermediate cast to "void *" to
silence the warning.

6 years agoWin32: improved fallback on FormatMessage() errors.
Maxim Dounin [Mon, 21 Oct 2019 16:06:12 +0000 (19:06 +0300)]
Win32: improved fallback on FormatMessage() errors.

FormatMessage() seems to return many errors which essentially indicate that
the language in question is not available.  At least the following were
observed in the wild and during testing: ERROR_MUI_FILE_NOT_FOUND (15100)
(ticket #1868), ERROR_RESOURCE_TYPE_NOT_FOUND (1813).  While documentation
says it should be ERROR_RESOURCE_LANG_NOT_FOUND (1815), this doesn't seem
to be the case.

As such, checking error code was removed, and as long as FormatMessage()
returns an error, we now always try the default language.

6 years agoSSL: available bytes handling (ticket #1431).
Maxim Dounin [Thu, 17 Oct 2019 13:02:24 +0000 (16:02 +0300)]
SSL: available bytes handling (ticket #1431).

Added code to track number of bytes available in the socket.
This makes it possible to avoid looping for a long time while
working with fast enough peer when data are added to the socket buffer
faster than we are able to read and process data.

When kernel does not provide number of bytes available, it is
retrieved using ioctl(FIONREAD) as long as a buffer is filled by
SSL_read().

It is assumed that number of bytes returned by SSL_read() is close
to the number of bytes read from the socket, as we do not use
SSL compression.  But even if it is not true for some reason, this
is not important, as we post an additional reading event anyway.

Note that data can be buffered at SSL layer, and it is not possible
to simply stop reading at some point and wait till the event will
be reported by the kernel again.  This can be only done when there
are no data in SSL buffers, and there is no good way to find out if
it's the case.

Instead of trying to figure out if SSL buffers are empty, this patch
introduces events posted for the next event loop iteration - such
events will be processed only on the next event loop iteration,
after going into the kernel and retrieving additional events.  This
seems to be simple and reliable approach.

6 years agoEvents: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin [Thu, 17 Oct 2019 13:02:19 +0000 (16:02 +0300)]
Events: available bytes calculation via ioctl(FIONREAD).

This makes it possible to avoid looping for a long time while working
with a fast enough peer when data are added to the socket buffer faster
than we are able to read and process them (ticket #1431).  This is
basically what we already do on FreeBSD with kqueue, where information
about the number of bytes in the socket buffer is returned by
the kevent() call.

With other event methods rev->available is now set to -1 when the socket
is ready for reading.  Later in ngx_recv() and ngx_recv_chain(), if
full buffer is received, real number of bytes in the socket buffer is
retrieved using ioctl(FIONREAD).  Reading more than this number of bytes
ensures that even with edge-triggered event methods the event will be
triggered again, so it is safe to stop processing of the socket and
switch to other connections.

Using ioctl(FIONREAD) only after reading a full buffer is an optimization.
With this approach we only call ioctl(FIONREAD) when there are at least
two recv()/readv() calls.

6 years agoSSL: improved ngx_ssl_recv_chain() to stop if c->read->ready is 0.
Maxim Dounin [Thu, 17 Oct 2019 13:02:13 +0000 (16:02 +0300)]
SSL: improved ngx_ssl_recv_chain() to stop if c->read->ready is 0.

As long as there are data to read in the socket, yet the amount of data
is less than total size of the buffers in the chain, this saves one
unneeded read() syscall.  Before this change, reading only stopped if
ngx_ssl_recv() returned no data, that is, two read() syscalls in a row
returned EAGAIN.

6 years agoEvent pipe: disabled c->read->available checking for SSL.
Maxim Dounin [Thu, 17 Oct 2019 13:02:03 +0000 (16:02 +0300)]
Event pipe: disabled c->read->available checking for SSL.

In SSL connections, data can be buffered by the SSL layer, and it is
wrong to avoid doing c->recv_chain() if c->read->available is 0 and
c->read->pending_eof is set.  And tests show that the optimization in
question indeed can result in incorrect detection of premature connection
close if upstream closes the connection without sending a close notify
alert at the same time.  Fix is to disable c->read->available optimization
for SSL connections.

6 years agoFixed header parsing with ignore_invalid_headers switched off.
Ruslan Ermilov [Tue, 15 Oct 2019 11:46:10 +0000 (14:46 +0300)]
Fixed header parsing with ignore_invalid_headers switched off.

The parsing was broken when the first character of the header name was invalid.

Based on a patch by Alan Kemp.

6 years agoFixed URI normalization with merge_slashes switched off.
Maxim Dounin [Tue, 8 Oct 2019 18:56:14 +0000 (21:56 +0300)]
Fixed URI normalization with merge_slashes switched off.

Previously, "/foo///../bar" was normalized into "/foo/bar"
instead of "/foo//bar".

6 years agoThe "/." and "/.." at the end of URI should be normalized.
Ruslan Ermilov [Tue, 8 Oct 2019 18:56:14 +0000 (21:56 +0300)]
The "/." and "/.." at the end of URI should be normalized.

6 years agoImproved detection of broken percent encoding in URI.
Ruslan Ermilov [Tue, 8 Oct 2019 18:56:14 +0000 (21:56 +0300)]
Improved detection of broken percent encoding in URI.

6 years agoCore: removed dead code in ngx_rbtree_delete().
Vladimir Homutov [Mon, 30 Sep 2019 13:39:20 +0000 (16:39 +0300)]
Core: removed dead code in ngx_rbtree_delete().

The result of ngx_rbtree_min() is always a node with the left child equal to
sentinel, thus the check is unnecessary.

6 years agoVersion bump.
Vladimir Homutov [Mon, 30 Sep 2019 13:43:16 +0000 (16:43 +0300)]
Version bump.

6 years agorelease-1.17.4 tag
Maxim Dounin [Tue, 24 Sep 2019 15:08:48 +0000 (18:08 +0300)]
release-1.17.4 tag

6 years agonginx-1.17.4-RELEASE release-1.17.4
Maxim Dounin [Tue, 24 Sep 2019 15:08:48 +0000 (18:08 +0300)]
nginx-1.17.4-RELEASE

6 years agoUpdated OpenSSL used for win32 builds.
Maxim Dounin [Tue, 24 Sep 2019 13:30:03 +0000 (16:30 +0300)]
Updated OpenSSL used for win32 builds.

6 years agoHTTP/2: fixed worker_shutdown_timeout.
Ruslan Ermilov [Mon, 23 Sep 2019 12:45:36 +0000 (15:45 +0300)]
HTTP/2: fixed worker_shutdown_timeout.

6 years agoHTTP/2: fixed possible alert about left open socket on shutdown.
Ruslan Ermilov [Mon, 23 Sep 2019 12:45:32 +0000 (15:45 +0300)]
HTTP/2: fixed possible alert about left open socket on shutdown.

This could happen when graceful shutdown configured by worker_shutdown_timeout
times out and is then followed by another timeout such as proxy_read_timeout.
In this case, the HEADERS frame is added to the output queue, but attempt to
send it fails (due to c->error forcibly set during graceful shutdown timeout).
This triggers request finalization which attempts to close the stream.  But the
stream cannot be closed because there is a frame in the output queue, and the
connection cannot be finalized.  This leaves the connection open without any
timer events leading to alert.

The fix is to post write event when sending output queue fails on c->error.
That will finalize the connection.

6 years agoHTTP/2: traffic-based flood detection.
Maxim Dounin [Wed, 18 Sep 2019 17:28:12 +0000 (20:28 +0300)]
HTTP/2: traffic-based flood detection.

With this patch, all traffic over an HTTP/2 connection is counted in
the h2c->total_bytes field, and payload traffic is counted in
the h2c->payload_bytes field.  As long as total traffic is many times
larger than payload traffic, we consider this to be a flood.

6 years agoHTTP/2: switched back to RST_STREAM with NO_ERROR.
Maxim Dounin [Wed, 18 Sep 2019 17:28:09 +0000 (20:28 +0300)]
HTTP/2: switched back to RST_STREAM with NO_ERROR.

In 8df664ebe037, we've switched to maximizing stream window instead
of sending RST_STREAM.  Since then handling of RST_STREAM with NO_ERROR
was fixed at least in Chrome, hence we switch back to using RST_STREAM.

This allows more effective rejecting of large bodies, and also minimizes
non-payload traffic to be accounted in the next patch.

6 years agoSSL: fixed ssl_verify_client error message.
Sergey Kandaurov [Mon, 16 Sep 2019 16:26:42 +0000 (19:26 +0300)]
SSL: fixed ssl_verify_client error message.

6 years agoResolver: fixed possible use-after-free while resolving PTR.
Sergey Kandaurov [Tue, 10 Sep 2019 12:42:34 +0000 (15:42 +0300)]
Resolver: fixed possible use-after-free while resolving PTR.

Previously, if a response to the PTR request was cached, and ngx_resolver_dup()
failed to allocate memory for the resulting name, then the original node was
freed but left in expire_queue.  A subsequent address resolving would end up
in a use-after-free memory access of the node either in ngx_resolver_expire()
or ngx_resolver_process_ptr(), when accessing it through expire_queue.

The fix is to leave the resolver node intact.

6 years agoHTTP/2: close connection on zero WINDOW_UPDATE.
Ruslan Ermilov [Tue, 10 Sep 2019 12:33:38 +0000 (15:33 +0300)]
HTTP/2: close connection on zero WINDOW_UPDATE.

Don't waste server resources by sending RST_STREAM frames.  Instead,
reject WINDOW_UPDATE frames with invalid zero increment by closing
connection with PROTOCOL_ERROR.

6 years agoHTTP/2: close connection on frames with self-dependency.
Ruslan Ermilov [Tue, 10 Sep 2019 12:33:37 +0000 (15:33 +0300)]
HTTP/2: close connection on frames with self-dependency.

Don't waste server resources by sending RST_STREAM frames.  Instead,
reject HEADERS and PRIORITY frames with self-dependency by closing
connection with PROTOCOL_ERROR.

6 years agoFixed "return" with discarding invalid chunked body.
Sergey Kandaurov [Wed, 4 Sep 2019 10:33:51 +0000 (13:33 +0300)]
Fixed "return" with discarding invalid chunked body.

When ngx_http_discard_request_body() call was added to ngx_http_send_response(),
there were no return codes other than NGX_OK and NGX_HTTP_INTERNAL_SERVER_ERROR.
Now it can also return NGX_HTTP_BAD_REQUEST, but ngx_http_send_response() still
incorrectly transforms it to NGX_HTTP_INTERNAL_SERVER_ERROR.

The fix is to propagate ngx_http_discard_request_body() errors.

6 years agoDetect runaway chunks in ngx_http_parse_chunked().
Sergey Kandaurov [Tue, 3 Sep 2019 14:26:56 +0000 (17:26 +0300)]
Detect runaway chunks in ngx_http_parse_chunked().

As defined in HTTP/1.1, body chunks have the following ABNF:

   chunk = chunk-size [ chunk-ext ] CRLF chunk-data CRLF

where chunk-data is a sequence of chunk-size octets.

With this change, chunk-data that doesn't end up with CRLF at chunk-size
offset will be treated as invalid, such as in the example provided below:

4
SEE-THIS-AND-
4
THAT
0

6 years agoHTTP/2: discard remaining request body after redirect.
Sergey Kandaurov [Mon, 19 Aug 2019 12:16:06 +0000 (15:16 +0300)]
HTTP/2: discard remaining request body after redirect.

Previously, if unbuffered request body reading wasn't finished before
the request was redirected to a different location using error_page
or X-Accel-Redirect, and the request body is read again, this could
lead to disastrous effects, such as a duplicate post_handler call or
"http request count is zero" alert followed by a segmentation fault.

This happened in the following configuration (ticket #1819):

    location / {
        proxy_request_buffering off;
        proxy_pass http://bad;
        proxy_intercept_errors on;
        error_page 502 = /error;
    }

    location /error {
        proxy_pass http://backend;
    }

6 years agoSSL: lowered log level for WSAECONNABORTED errors on Windows.
Maxim Dounin [Fri, 16 Aug 2019 15:16:21 +0000 (18:16 +0300)]
SSL: lowered log level for WSAECONNABORTED errors on Windows.

Winsock uses ECONNABORTED instead of ECONNRESET in some cases.
For non-SSL connections this is already handled since baad3036086e.

Reported at
http://mailman.nginx.org/pipermail/nginx-ru/2019-August/062363.html.

6 years agoVersion bump.
Maxim Dounin [Fri, 16 Aug 2019 15:16:14 +0000 (18:16 +0300)]
Version bump.

6 years agorelease-1.17.3 tag
Maxim Dounin [Tue, 13 Aug 2019 12:45:57 +0000 (15:45 +0300)]
release-1.17.3 tag

6 years agonginx-1.17.3-RELEASE release-1.17.3
Maxim Dounin [Tue, 13 Aug 2019 12:45:56 +0000 (15:45 +0300)]
nginx-1.17.3-RELEASE

6 years agoHTTP/2: limited number of PRIORITY frames.
Ruslan Ermilov [Tue, 13 Aug 2019 12:43:40 +0000 (15:43 +0300)]
HTTP/2: limited number of PRIORITY frames.

Fixed excessive CPU usage caused by a peer that continuously shuffles
priority of streams.  Fix is to limit the number of PRIORITY frames.

6 years agoHTTP/2: limited number of DATA frames.
Ruslan Ermilov [Tue, 13 Aug 2019 12:43:36 +0000 (15:43 +0300)]
HTTP/2: limited number of DATA frames.

Fixed excessive memory growth and CPU usage if stream windows are
manipulated in a way that results in generating many small DATA frames.
Fix is to limit the number of simultaneously allocated DATA frames.

6 years agoHTTP/2: reject zero length headers with PROTOCOL_ERROR.
Sergey Kandaurov [Tue, 13 Aug 2019 12:43:32 +0000 (15:43 +0300)]
HTTP/2: reject zero length headers with PROTOCOL_ERROR.

Fixed uncontrolled memory growth if peer sends a stream of
headers with a 0-length header name and 0-length header value.
Fix is to reject headers with zero name length.

6 years agoMail: fixed duplicate resolving.
Maxim Dounin [Thu, 1 Aug 2019 10:50:07 +0000 (13:50 +0300)]
Mail: fixed duplicate resolving.

When using SMTP with SSL and resolver, read events might be enabled
during address resolving, leading to duplicate ngx_mail_ssl_handshake_handler()
calls if something arrives from the client, and duplicate session
initialization - including starting another resolving.  This can lead
to a segmentation fault if the session is closed after first resolving
finished.  Fix is to block read events while resolving.

Reported by Robert Norris,
http://mailman.nginx.org/pipermail/nginx/2019-July/058204.html.

6 years agoGzip: fixed "zero size buf" alerts after ac5a741d39cf.
Maxim Dounin [Wed, 31 Jul 2019 14:29:00 +0000 (17:29 +0300)]
Gzip: fixed "zero size buf" alerts after ac5a741d39cf.

After ac5a741d39cf it is now possible that after zstream.avail_out
reaches 0 and we allocate additional buffer, there will be no more data
to put into this buffer, triggering "zero size buf" alert.  Fix is to
reset b->temporary flag in this case.

Additionally, an optimization added to avoid allocating additional buffer
in this case, by checking if last deflate() call returned Z_STREAM_END.
Note that checking for Z_STREAM_END by itself is not enough to fix alerts,
as deflate() can return Z_STREAM_END without producing any output if the
buffer is smaller than gzip trailer.

Reported by Witold Filipczyk,
http://mailman.nginx.org/pipermail/nginx-devel/2019-July/012469.html.

6 years agoVersion bump.
Maxim Dounin [Wed, 31 Jul 2019 14:28:41 +0000 (17:28 +0300)]
Version bump.

6 years agorelease-1.17.2 tag
Maxim Dounin [Tue, 23 Jul 2019 12:01:47 +0000 (15:01 +0300)]
release-1.17.2 tag

6 years agonginx-1.17.2-RELEASE release-1.17.2
Maxim Dounin [Tue, 23 Jul 2019 12:01:47 +0000 (15:01 +0300)]
nginx-1.17.2-RELEASE

6 years agoCore: fixed memory leak on error, missed in c3f60d618c17.
Maxim Dounin [Fri, 19 Jul 2019 14:50:00 +0000 (17:50 +0300)]
Core: fixed memory leak on error, missed in c3f60d618c17.

Found by Coverity (CID 1451664).

6 years agoXslt: fixed potential buffer overflow with null character.
Maxim Dounin [Thu, 18 Jul 2019 15:27:54 +0000 (18:27 +0300)]
Xslt: fixed potential buffer overflow with null character.

Due to shortcomings of the ccv->zero flag implementation in complex value
interface, length of the resulting string from ngx_http_complex_value()
might either not include terminating null character or include it,
so the only safe way to work with the result is to use it as a
null-terminated string.

Reported by Patrick Wollgast.

6 years agoSSI: avoid potential buffer overflow.
Maxim Dounin [Thu, 18 Jul 2019 15:27:53 +0000 (18:27 +0300)]
SSI: avoid potential buffer overflow.

When "-" follows a parameter of maximum length, a single byte buffer
overflow happens, since the error branch does not check parameter length.
Fix is to avoid saving "-" to the parameter key, and instead use an error
message with "-" explicitly written.  The message is mostly identical to
one used in similar cases in the preequal state.

Reported by Patrick Wollgast.

6 years agoUpstream: fixed EOF handling in unbuffered and upgraded modes.
Maxim Dounin [Thu, 18 Jul 2019 15:27:52 +0000 (18:27 +0300)]
Upstream: fixed EOF handling in unbuffered and upgraded modes.

With level-triggered event methods it is important to specify
the NGX_CLOSE_EVENT flag to ngx_handle_read_event(), otherwise
the event won't be removed, resulting in CPU hog.

Reported by Patrick Wollgast.

6 years agoHTTP/2: return error on output on closed stream.
Maxim Dounin [Thu, 18 Jul 2019 15:27:50 +0000 (18:27 +0300)]
HTTP/2: return error on output on closed stream.

Without this, an (incorrect) output on a closed stream could result in
a socket leak.

6 years agoCore: fixed segfault with too large bucket sizes (ticket #1806).
Maxim Dounin [Thu, 18 Jul 2019 15:27:44 +0000 (18:27 +0300)]
Core: fixed segfault with too large bucket sizes (ticket #1806).

To save memory hash code uses u_short to store resulting bucket sizes,
so maximum bucket size is limited to 65536 minus ngx_cacheline_size (larger
values will be aligned to 65536 which will overflow u_short).  However,
there were no checks to enforce this, and using larger bucket sizes
resulted in overflows and segmentation faults.

Appropriate safety checks to enforce this added to ngx_hash_init().

6 years agoPerl: removed unused variable, forgotten in 975d7ab37b39.
Maxim Dounin [Wed, 17 Jul 2019 14:00:57 +0000 (17:00 +0300)]
Perl: removed unused variable, forgotten in 975d7ab37b39.

6 years agoGzip: use zlib to write header and trailer.
Ilya Leoshkevich [Fri, 12 Jul 2019 10:43:08 +0000 (12:43 +0200)]
Gzip: use zlib to write header and trailer.

When nginx is used with zlib patched with [1], which provides
integration with the future IBM Z hardware deflate acceleration, it ends
up computing CRC32 twice: one time in hardware, which always does this,
and one time in software by explicitly calling crc32().

crc32() calls were added in changesets 133:b27548f540ad ("nginx-0.0.1-
2003-09-24-23:51:12 import") and 134:d57c6835225c ("nginx-0.0.1-
2003-09-26-09:45:21 import") as part of gzip wrapping feature - back
then zlib did not support it.

However, since then gzip wrapping was implemented in zlib v1.2.0.4,
and it's already being used by nginx for log compression.

This patch replaces hand-written gzip wrapping with the one provided by
zlib. It simplifies the code, and makes it avoid computing CRC32 twice
when using hardware acceleration.

[1] https://github.com/madler/zlib/pull/410

6 years agoPerl: named locations in $r->internal_redirect().
Maxim Dounin [Fri, 12 Jul 2019 12:39:28 +0000 (15:39 +0300)]
Perl: named locations in $r->internal_redirect().

6 years agoPerl: expect escaped URIs in $r->internal_redirect().
Maxim Dounin [Fri, 12 Jul 2019 12:39:26 +0000 (15:39 +0300)]
Perl: expect escaped URIs in $r->internal_redirect().

Similarly to the change in 5491:74bfa803a5aa (1.5.9), we should accept
properly escaped URIs and unescape them as needed, else it is not possible
to handle URIs with question marks.

6 years agoPerl: additional ctx->header_sent checks.
Maxim Dounin [Fri, 12 Jul 2019 12:39:25 +0000 (15:39 +0300)]
Perl: additional ctx->header_sent checks.

As we now have ctx->header_sent flag, it is further used to prevent
duplicate $r->send_http_header() calls, prevent output before sending
header, and $r->internal_redirect() after sending header.

Further, $r->send_http_header() protected from calls after
$r->internal_redirect().

6 years agoPerl: avoid returning 500 if header was already sent.
Maxim Dounin [Fri, 12 Jul 2019 12:39:25 +0000 (15:39 +0300)]
Perl: avoid returning 500 if header was already sent.

Returning NGX_HTTP_INTERNAL_SERVER_ERROR if a perl code died after
sending header will lead to a "header already sent" alert.  To avoid
it, we now check if header was already sent, and return NGX_ERROR
instead if it was.

6 years agoPerl: avoid redirects on errors.
Maxim Dounin [Fri, 12 Jul 2019 12:38:27 +0000 (15:38 +0300)]
Perl: avoid redirects on errors.

Previously, redirects scheduled with $r->internal_redirect() were followed
even if the code then died.  Now these are ignored and nginx will return
an error instead.

6 years agoPerl: disabled unrelated calls from variable handlers.
Maxim Dounin [Fri, 12 Jul 2019 12:35:31 +0000 (15:35 +0300)]
Perl: disabled unrelated calls from variable handlers.

Variable handlers are not expected to send anything to the client, cannot
sleep or read body, and are not expected to modify the request.  Added
appropriate protection to prevent accidental foot shooting.

6 years agoPerl: protection against duplicate $r->sleep() calls.
Maxim Dounin [Fri, 12 Jul 2019 12:34:37 +0000 (15:34 +0300)]
Perl: protection against duplicate $r->sleep() calls.

Duplicate $r->sleep() and/or $r->has_request_body() calls result
in undefined behaviour (in practice, connection leaks were observed).
To prevent this, croak() added in appropriate places.

6 years agoPerl: handling of allocation errors.
Maxim Dounin [Fri, 12 Jul 2019 10:56:23 +0000 (13:56 +0300)]
Perl: handling of allocation errors.

Previously, allocation errors in nginx.xs were more or less ignored,
potentially resulting in incorrect code execution in specific low-memory
conditions.  This is changed to use ctx->error bit and croak(), similarly
to how output errors are now handled.

Note that this is mostly a cosmetic change, as Perl itself exits on memory
allocation errors, and hence nginx with Perl is hardly usable in low-memory
conditions.

6 years agoPerl: propagate errors.
Maxim Dounin [Fri, 12 Jul 2019 10:56:21 +0000 (13:56 +0300)]
Perl: propagate errors.

When an error happens, the ctx->error bit is now set, and croak()
is called to terminate further processing.  The ctx->error bit is
checked in ngx_http_perl_call_handler() to cancel further processing,
and is also checked in various output functions - to make sure these won't
be called if croak() was handled by an eval{} in perl code.

In particular, this ensures that output chain won't be called after
errors, as filters might not expect this to happen.  This fixes some
segmentation faults under low memory conditions.  Also this stops
request processing after filter finalization or request body reading
errors.

For cases where an HTTP error status can be additionally returned (for
example, 416 (Requested Range Not Satisfiable) from the range filter),
the ctx->status field is also added.

6 years agoPerl: reworked perl module to pass ctx instead of request.
Maxim Dounin [Fri, 12 Jul 2019 08:29:22 +0000 (11:29 +0300)]
Perl: reworked perl module to pass ctx instead of request.

This ensures that correct ctx is always available, including after
filter finalization.  In particular, this fixes a segmentation fault
with the following configuration:

    location / {
        image_filter test;

        perl 'sub {
            my $r = shift;
            $r->send_http_header();
            $r->print("foo\n");
            $r->print("bar\n");
        }';
    }

This also seems to be the only way to correctly handle filter finalization
in various complex cases, for example, when embedded perl is used both
in the original handler and in an error page called after filter
finalization.

6 years agoPerl: removed unneeded NGX_DONE test.
Maxim Dounin [Thu, 11 Jul 2019 20:20:08 +0000 (23:20 +0300)]
Perl: removed unneeded NGX_DONE test.

The NGX_DONE test in ngx_http_perl_handle_request() was introduced
in 1702:86bb52e28ce0, which also modified ngx_http_perl_call_handler()
to return NGX_DONE with c->destroyed.  The latter part was then
removed in 3050:f54b02dbb12b, so NGX_DONE test is no longer needed.

6 years agoContrib: vim syntax, update core and 3rd party module directives.
Gena Makhomed [Sun, 30 Jun 2019 07:39:01 +0000 (10:39 +0300)]
Contrib: vim syntax, update core and 3rd party module directives.

6 years agoTypo.
Maxim Dounin [Tue, 9 Jul 2019 13:03:25 +0000 (16:03 +0300)]
Typo.

6 years agoVersion bump.
Maxim Dounin [Tue, 9 Jul 2019 13:01:32 +0000 (16:01 +0300)]
Version bump.