]> git.kaiwu.me - nginx.git/log
nginx.git
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.

6 years agorelease-1.17.1 tag
Maxim Dounin [Tue, 25 Jun 2019 12:19:45 +0000 (15:19 +0300)]
release-1.17.1 tag

6 years agonginx-1.17.1-RELEASE release-1.17.1
Maxim Dounin [Tue, 25 Jun 2019 12:19:45 +0000 (15:19 +0300)]
nginx-1.17.1-RELEASE

6 years agoUpdated OpenSSL used for win32 builds.
Maxim Dounin [Tue, 25 Jun 2019 01:47:43 +0000 (04:47 +0300)]
Updated OpenSSL used for win32 builds.

6 years agoPerl: disabled not_modified filter (ticket #1786).
Maxim Dounin [Mon, 17 Jun 2019 16:48:56 +0000 (19:48 +0300)]
Perl: disabled not_modified filter (ticket #1786).

Embedded perl does not set any request fields needed for conditional
requests processing.  Further, filter finalization in the not_modified
filter can cause segmentation faults due to cleared ctx as in
ticket #1786.

Before 5fb1e57c758a (1.7.3) the not_modified filter was implicitly disabled
for perl responses, as r->headers_out.last_modified_time was -1.  This
change restores this behaviour by using the explicit r->disable_not_modified
flag.

Note that this patch doesn't try to address perl module robustness against
filter finalization and other errors returned from filter chains.  It should
be eventually reworked to handle errors instead of ignoring them.

6 years agoLimit req: limit_req_dry_run directive.
Roman Arutyunyan [Wed, 5 Jun 2019 16:55:27 +0000 (19:55 +0300)]
Limit req: limit_req_dry_run directive.

A new directive limit_req_dry_run allows enabling the dry run mode.  In this
mode requests are neither rejected nor delayed, but reject/delay status is
logged as usual.

6 years agoUpstream: background cache update before cache send (ticket #1782).
Roman Arutyunyan [Mon, 3 Jun 2019 17:33:26 +0000 (20:33 +0300)]
Upstream: background cache update before cache send (ticket #1782).

In case of filter finalization, essential request fields like r->uri,
r->args etc could be changed, which affected the cache update subrequest.
Also, after filter finalization r->cache could be set to NULL, leading to
null pointer dereference in ngx_http_upstream_cache_background_update().
The fix is to create background cache update subrequest before sending the
cached response.

Since initial introduction in 1aeaae6e9446 (1.11.10) background cache update
subrequest was created after sending the cached response because otherwise it
blocked the parent request output.  In 9552758a786e (1.13.1) background
subrequests were introduced to eliminate the delay before sending the final
part of the cached response.  This also made it possible to create the
background cache update subrequest before sending the response.

Note that creating the subrequest earlier does not change the fact that in case
of filter finalization the background cache update subrequest will likely not
have enough time to successfully update the cache entry.  Filter finalization
leads to the main request termination as soon the current iteration of request
processing is complete.

6 years agoUpstream hash: fall back to round-robin if hash key is empty.
Niklas Keller [Thu, 23 May 2019 13:49:22 +0000 (16:49 +0300)]
Upstream hash: fall back to round-robin if hash key is empty.

6 years agoVersion bump.
Roman Arutyunyan [Mon, 27 May 2019 16:47:50 +0000 (19:47 +0300)]
Version bump.

6 years agorelease-1.17.0 tag
Maxim Dounin [Tue, 21 May 2019 14:23:57 +0000 (17:23 +0300)]
release-1.17.0 tag

6 years agonginx-1.17.0-RELEASE release-1.17.0
Maxim Dounin [Tue, 21 May 2019 14:23:57 +0000 (17:23 +0300)]
nginx-1.17.0-RELEASE

10 years agoSSL: removed OpenSSL 0.9.7 compatibility.
Sergey Kandaurov [Mon, 11 Apr 2016 12:46:36 +0000 (15:46 +0300)]
SSL: removed OpenSSL 0.9.7 compatibility.

7 years agoRange filter: fixed duplicate last buffers.
Maxim Dounin [Mon, 13 May 2019 19:44:49 +0000 (22:44 +0300)]
Range filter: fixed duplicate last buffers.

In ngx_http_range_singlepart_body() special buffers where passed
unmodified, including ones after the end of the range.  As such,
if the last buffer of a response was sent separately as a special
buffer, two buffers with b->last_buf set were present in the response.

In particular, this might result in a duplicate final chunk when using
chunked transfer encoding (normally range filter and chunked transfer
encoding are not used together, but this may happen if there are trailers
in the response).  This also likely to cause problems in HTTP/2.

Fix is to skip all special buffers after we've sent the last part of
the range requested.  These special buffers are not meaningful anyway,
since we set b->last_buf in the buffer with the last part of the range,
and everything is expected to be flushed due to it.

Additionally, ngx_http_next_body_filter() is now called even
if no buffers are to be passed to it.  This ensures that various
write events are properly propagated through the filter chain.  In
particular, this fixes test failures observed with the above change
and aio enabled.

7 years agoRange filter: fixed loss of incoming chain links.
Maxim Dounin [Mon, 13 May 2019 19:44:02 +0000 (22:44 +0300)]
Range filter: fixed loss of incoming chain links.

Filters are not allowed to change incoming chain links, and should allocate
their own links if any modifications are needed.  Nevertheless
ngx_http_range_singlepart_body() modified incoming chain links in some
cases, notably at the end of the requested range.

No problems caused by this are currently known, mostly because of
limited number of possible modifications and the position of the range
body filter in the filter chain.  Though this behaviour is clearly incorrect
and tests demonstrate that it can at least cause some proxy buffers being
lost when using proxy_force_ranges, leading to less effective handling
of responses.

Fix is to always allocate new chain links in ngx_http_range_singlepart_body().
Links are explicitly freed to ensure constant memory usage with long-lived
requests.

7 years agoUnconditional compilation of the postpone filter.
Roman Arutyunyan [Wed, 8 May 2019 16:22:13 +0000 (19:22 +0300)]
Unconditional compilation of the postpone filter.

Postpone filter is an essential part of subrequest functionality.  In absence
of it a subrequest response body is sent to the client out of order with
respect to the main request header and body, as well as other subrequests.
For in-memory subrequests the response is also sent to the client instead of
being stored in memory.

Currently the postpone filter is automatically enabled if one of the following
standard modules which are known to create subrequests is enabled: ssi, slice,
addition.  However a third-party module that creates subrequests can still be
built without the postpone filter or be dynamically loaded in nginx built
without it.

7 years agoVariables support in proxy_upload_rate and proxy_download_rate.
Ruslan Ermilov [Wed, 24 Apr 2019 13:38:56 +0000 (16:38 +0300)]
Variables support in proxy_upload_rate and proxy_download_rate.

7 years agoVariables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov [Wed, 24 Apr 2019 13:38:54 +0000 (16:38 +0300)]
Variables support in limit_rate and limit_rate_after (ticket #293).

7 years agoAdded ngx_http_set_complex_value_size_slot().
Ruslan Ermilov [Wed, 24 Apr 2019 13:38:51 +0000 (16:38 +0300)]
Added ngx_http_set_complex_value_size_slot().

If a complex value is expected to be of type size_t, and the compiled
value is constant, the constant size_t value is remembered at compile
time.

The value is accessed through ngx_http_complex_value_size() which
either returns the remembered constant or evaluates the expression
and parses it as size_t.

7 years agoCore: enabled "include" in any context (ticket #1615).
Vladimir Homutov [Tue, 9 Apr 2019 08:40:20 +0000 (11:40 +0300)]
Core: enabled "include" in any context (ticket #1615).

7 years agoVersion bump.
Vladimir Homutov [Wed, 24 Apr 2019 10:41:29 +0000 (13:41 +0300)]
Version bump.

7 years agorelease-1.15.12 tag
Maxim Dounin [Tue, 16 Apr 2019 14:54:59 +0000 (17:54 +0300)]
release-1.15.12 tag

7 years agonginx-1.15.12-RELEASE release-1.15.12
Maxim Dounin [Tue, 16 Apr 2019 14:54:58 +0000 (17:54 +0300)]
nginx-1.15.12-RELEASE

7 years agoUpdated PCRE used for win32 builds.
Maxim Dounin [Tue, 16 Apr 2019 13:32:44 +0000 (16:32 +0300)]
Updated PCRE used for win32 builds.

7 years agoFixed incorrect length handling in ngx_utf8_length().
Maxim Dounin [Mon, 15 Apr 2019 17:14:07 +0000 (20:14 +0300)]
Fixed incorrect length handling in ngx_utf8_length().

Previously, ngx_utf8_decode() was called from ngx_utf8_length() with
incorrect length, potentially resulting in out-of-bounds read when
handling invalid UTF-8 strings.

In practice out-of-bounds reads are not possible though, as autoindex, the
only user of ngx_utf8_length(), provides null-terminated strings, and
ngx_utf8_decode() anyway returns an errors when it sees a null in the
middle of an UTF-8 sequence.

Reported by Yunbin Liu.

7 years agoOCSP stapling: fixed segfault with dynamic certificate loading.
Maxim Dounin [Mon, 15 Apr 2019 16:13:09 +0000 (19:13 +0300)]
OCSP stapling: fixed segfault with dynamic certificate loading.

If OCSP stapling was enabled with dynamic certificate loading, with some
OpenSSL versions (1.0.2o and older, 1.1.0h and older; fixed in 1.0.2p,
1.1.0i, 1.1.1) a segmentation fault might happen.

The reason is that during an abbreviated handshake the certificate
callback is not called, but the certificate status callback was called
(https://github.com/openssl/openssl/issues/1662), leading to NULL being
returned from SSL_get_certificate().

Fix is to explicitly check SSL_get_certificate() result.

7 years agoVersion bump.
Maxim Dounin [Mon, 15 Apr 2019 16:13:06 +0000 (19:13 +0300)]
Version bump.

7 years agorelease-1.15.11 tag
Maxim Dounin [Tue, 9 Apr 2019 13:00:30 +0000 (16:00 +0300)]
release-1.15.11 tag

7 years agonginx-1.15.11-RELEASE release-1.15.11
Maxim Dounin [Tue, 9 Apr 2019 13:00:30 +0000 (16:00 +0300)]
nginx-1.15.11-RELEASE

7 years agoWin32: avoid using CFLAGS, just add define instead.
Maxim Dounin [Thu, 4 Apr 2019 19:56:41 +0000 (22:56 +0300)]
Win32: avoid using CFLAGS, just add define instead.

With CFLAGS set as in 7da71a7b141a, OpenSSL compilation drops various
non-important compiler options.  To avoid this, a define is added
instead - OpenSSL is smart enough to recognize -D... in Configure
arguments.

7 years agoWin32: defined pdb path.
Maxim Dounin [Thu, 4 Apr 2019 16:30:47 +0000 (19:30 +0300)]
Win32: defined pdb path.

By default, MSVC uses vc<version>.pdb in the current directory.
With the "-Fd" switch it is directed to be in the objs directory instead.

7 years agoWin32: preserving binary compatibility with Windows XP - Vista.
Sergey Kandaurov [Thu, 4 Apr 2019 13:26:56 +0000 (16:26 +0300)]
Win32: preserving binary compatibility with Windows XP - Vista.

OpenSSL 1.1.0 and above uses BCrypt if available (Windows 7 or higher).
This results in an unusable binary on older Windows versions, when building
with newer Windows SDK (such as 7.0A).  Using CFLAGS to define _WIN32_WINNT
allows to set a desired ABI and make sure the binary works with Windows XP.

To not mix with other potential CFLAGS uses, it is set in GNUmakefile.

7 years agoWin32: skip building OpenSSL tests to conserve time and space.
Sergey Kandaurov [Thu, 4 Apr 2019 13:22:03 +0000 (16:22 +0300)]
Win32: skip building OpenSSL tests to conserve time and space.

When building OpenSSL 1.1.1b, as used for win32 builds, with tests
it takes about twice as long and near ~1GB of additional disk space.
Using "no-tests" OpenSSL configuration option allows to skip them.
Since such an option is supported since OpenSSL 1.1.1 only, it is
residing here and not in configure.

7 years agoOCSP stapling: open ssl_stapling_file in binary-mode.
Sergey Kandaurov [Wed, 3 Apr 2019 12:35:39 +0000 (15:35 +0300)]
OCSP stapling: open ssl_stapling_file in binary-mode.

OCSP response uses the DER format and as such needs to be opened in binary-mode.
This only has any effect under Win32.

7 years agoSSL: missing free calls in $ssl_client_s_dn and $ssl_client_i_dn.
Nikolay Morozov [Tue, 26 Mar 2019 06:33:57 +0000 (09:33 +0300)]
SSL: missing free calls in $ssl_client_s_dn and $ssl_client_i_dn.

If X509_get_issuer_name() or X509_get_subject_name() returned NULL,
this could lead to a certificate reference leak.  It cannot happen
in practice though, since each function returns an internal pointer
to a mandatory subfield of the certificate successfully decoded by
d2i_X509() during certificate message processing (closes #1751).

7 years agoVersion bump.
Sergey Kandaurov [Tue, 26 Mar 2019 15:25:08 +0000 (18:25 +0300)]
Version bump.

7 years agorelease-1.15.10 tag
Maxim Dounin [Tue, 26 Mar 2019 14:06:55 +0000 (17:06 +0300)]
release-1.15.10 tag

7 years agonginx-1.15.10-RELEASE release-1.15.10
Maxim Dounin [Tue, 26 Mar 2019 14:06:54 +0000 (17:06 +0300)]
nginx-1.15.10-RELEASE

7 years agoListen port ranges.
Roman Arutyunyan [Wed, 6 Mar 2019 17:46:09 +0000 (20:46 +0300)]
Listen port ranges.

A range is specified with a dash.  For each port in a range a separate listen
socket is created.

Examples:

    listen 8080-9000;
    listen example.com:80-88;

7 years agoRemoved sorting of getaddrinfo() results.
Roman Arutyunyan [Wed, 20 Mar 2019 17:31:59 +0000 (20:31 +0300)]
Removed sorting of getaddrinfo() results.

Previously the ngx_inet_resolve_host() function sorted addresses in a way that
IPv4 addresses came before IPv6 addresses.  This was implemented in eaf95350d75c
(1.3.10) along with the introduction of getaddrinfo() which could resolve host
names to IPv6 addresses.  Since the "listen" directive only used the first
address, sorting allowed to preserve "listen" compatibility with the previous
behavior and with the behavior of nginx built without IPv6 support.  Now
"listen" uses all resolved addresses which makes sorting pointless.

7 years agoMultiple addresses in "listen".
Roman Arutyunyan [Fri, 15 Mar 2019 12:45:56 +0000 (15:45 +0300)]
Multiple addresses in "listen".

Previously only one address was used by the listen directive handler even if
host name resolved to multiple addresses.  Now a separate listening socket is
created for each address.

7 years agoSSL: support for parsing PEM certificates from memory.
Maxim Dounin [Sat, 9 Mar 2019 00:03:56 +0000 (03:03 +0300)]
SSL: support for parsing PEM certificates from memory.

This makes it possible to provide certificates directly via variables
in ssl_certificate / ssl_certificate_key directives, without using
intermediate files.

7 years agoSSL: removed redundant "pkey" variable.
Maxim Dounin [Fri, 8 Mar 2019 23:55:43 +0000 (02:55 +0300)]
SSL: removed redundant "pkey" variable.

It was accidentally introduced in 77436d9951a1 (1.15.9).  In MSVC 2015
and more recent MSVC versions it triggers warning C4456 (declaration of
'pkey' hides previous local declaration).  Previously, all such warnings
were resolved in 2a621245f4cf.

Reported by Steve Stevenson.

7 years agoSSL: moved c->ssl->handshaked check in server name callback.
Maxim Dounin [Tue, 5 Mar 2019 13:34:19 +0000 (16:34 +0300)]
SSL: moved c->ssl->handshaked check in server name callback.

Server name callback is always called by OpenSSL, even
if server_name extension is not present in ClientHello.  As such,
checking c->ssl->handshaked before the SSL_get_servername() result
should help to more effectively prevent renegotiation in
OpenSSL 1.1.0 - 1.1.0g, where neither SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS
nor SSL_OP_NO_RENEGOTIATION is available.

7 years agoSSL: use of the SSL_OP_NO_CLIENT_RENEGOTIATION option.
Maxim Dounin [Sun, 3 Mar 2019 13:49:02 +0000 (16:49 +0300)]
SSL: use of the SSL_OP_NO_CLIENT_RENEGOTIATION option.

The SSL_OP_NO_CLIENT_RENEGOTIATION option was introduced in LibreSSL 2.5.1.
Unlike OpenSSL's SSL_OP_NO_RENEGOTIATION, it only disables client-initiated
renegotiation, and hence can be safely used on all SSL contexts.

7 years agoSSL: fixed potential leak on memory allocation errors.
Maxim Dounin [Sun, 3 Mar 2019 13:48:39 +0000 (16:48 +0300)]
SSL: fixed potential leak on memory allocation errors.

If ngx_pool_cleanup_add() fails, we have to clean just created SSL context
manually, thus appropriate call added.

Additionally, ngx_pool_cleanup_add() moved closer to ngx_ssl_create() in
the ngx_http_ssl_module, to make sure there are no leaks due to intermediate
code.

7 years agoSSL: server name callback changed to return fatal errors.
Maxim Dounin [Sun, 3 Mar 2019 13:48:06 +0000 (16:48 +0300)]
SSL: server name callback changed to return fatal errors.

Notably this affects various allocation errors, and should generally
improve things if an allocation error actually happens during a callback.

Depending on the OpenSSL version, returning an error can result in
either SSL_R_CALLBACK_FAILED or SSL_R_CLIENTHELLO_TLSEXT error from
SSL_do_handshake(), so both errors were switched to the "info" level.

7 years agoSSL: server name callback changed to return SSL_TLSEXT_ERR_OK.
Maxim Dounin [Sun, 3 Mar 2019 13:47:44 +0000 (16:47 +0300)]
SSL: server name callback changed to return SSL_TLSEXT_ERR_OK.

OpenSSL 1.1.1 does not save server name to the session if server name
callback returns anything but SSL_TLSEXT_ERR_OK, thus breaking
the $ssl_server_name variable in resumed sessions.

Since $ssl_server_name can be used even if we've selected the default
server and there are no other servers, it looks like the only viable
solution is to always return SSL_TLSEXT_ERR_OK regardless of the actual
result.

To fix things in the stream module as well, added a dummy server name
callback which always returns SSL_TLSEXT_ERR_OK.

7 years agoVersion bump.
Maxim Dounin [Sun, 3 Mar 2019 13:47:41 +0000 (16:47 +0300)]
Version bump.

7 years agorelease-1.15.9 tag
Maxim Dounin [Tue, 26 Feb 2019 15:29:22 +0000 (18:29 +0300)]
release-1.15.9 tag

7 years agonginx-1.15.9-RELEASE release-1.15.9
Maxim Dounin [Tue, 26 Feb 2019 15:29:22 +0000 (18:29 +0300)]
nginx-1.15.9-RELEASE

7 years agoUpdated OpenSSL used for win32 builds.
Maxim Dounin [Tue, 26 Feb 2019 15:01:30 +0000 (18:01 +0300)]
Updated OpenSSL used for win32 builds.

7 years agoSSL: fixed possible segfault with dynamic certificates.
Maxim Dounin [Mon, 25 Feb 2019 18:16:26 +0000 (21:16 +0300)]
SSL: fixed possible segfault with dynamic certificates.

A virtual server may have no SSL context if it does not have certificates
defined, so we have to use config of the ngx_http_ssl_module from the
SSL context in the certificate callback.  To do so, it is now passed as
the argument of the callback.

The stream module doesn't really need any changes, but was modified as
well to match http code.

7 years agoSSL: adjusted session id context with dynamic certificates.
Maxim Dounin [Mon, 25 Feb 2019 13:42:54 +0000 (16:42 +0300)]
SSL: adjusted session id context with dynamic certificates.

Dynamic certificates re-introduce problem with incorrect session
reuse (AKA "virtual host confusion", CVE-2014-3616), since there are
no server certificates to generate session id context from.

To prevent this, session id context is now generated from ssl_certificate
directives as specified in the configuration.  This approach prevents
incorrect session reuse in most cases, while still allowing sharing
sessions across multiple machines with ssl_session_ticket_key set as
long as configurations are identical.

7 years agoSSL: dynamic certificate loading in the stream module.
Maxim Dounin [Mon, 25 Feb 2019 13:42:43 +0000 (16:42 +0300)]
SSL: dynamic certificate loading in the stream module.

7 years agoSSL: passwords support for dynamic certificate loading.
Maxim Dounin [Mon, 25 Feb 2019 13:42:23 +0000 (16:42 +0300)]
SSL: passwords support for dynamic certificate loading.

Passwords have to be copied to the configuration pool to be used
at runtime.  Also, to prevent blocking on stdin (with "daemon off;")
an empty password list is provided.

To make things simpler, password handling was modified to allow
an empty array (with 0 elements and elts set to NULL) as an equivalent
of an array with 1 empty password.

7 years agoSSL: variables support in ssl_certificate and ssl_certificate_key.
Maxim Dounin [Mon, 25 Feb 2019 13:42:05 +0000 (16:42 +0300)]
SSL: variables support in ssl_certificate and ssl_certificate_key.

To evaluate variables, a request is created in the certificate callback,
and then freed.  To do this without side effects on the stub_status
counters and connection state, an additional function was introduced,
ngx_http_alloc_request().

Only works with OpenSSL 1.0.2+, since there is no SSL_CTX_set_cert_cb()
in older versions.

7 years agoSSL: loading of connection-specific certificates.
Maxim Dounin [Mon, 25 Feb 2019 13:41:44 +0000 (16:41 +0300)]
SSL: loading of connection-specific certificates.

7 years agoSSL: reworked ngx_ssl_certificate().
Maxim Dounin [Mon, 25 Feb 2019 13:41:28 +0000 (16:41 +0300)]
SSL: reworked ngx_ssl_certificate().

This makes it possible to reuse certificate loading at runtime,
as introduced in the following patches.

Additionally, this improves error logging, so nginx will now log
human-friendly messages "cannot load certificate" instead of only
referring to sometimes cryptic names of OpenSSL functions.

7 years agoSSL: removed logging of empty "(SSL:)" in ngx_ssl_error().
Maxim Dounin [Mon, 25 Feb 2019 13:41:15 +0000 (16:41 +0300)]
SSL: removed logging of empty "(SSL:)" in ngx_ssl_error().

The "(SSL:)" snippet currently appears in logs when nginx code uses
ngx_ssl_error() to log an error, but OpenSSL's error queue is empty.
This can happen either because the error wasn't in fact from OpenSSL,
or because OpenSSL did not indicate the error in the error queue
for some reason.

In particular, currently "(SSL:)" can be seen in errors at least in
the following cases:

- When SSL_write() fails due to a syscall error,
  "[info] ... SSL_write() failed (SSL:) (32: Broken pipe)...".

- When loading a certificate with no data in it,
  "[emerg] PEM_read_bio_X509_AUX(...) failed (SSL:)".
  This can easily happen due to an additional empty line before
  the end line, so all lines of the certificate are interpreted
  as header lines.

- When trying to configure an unknown curve,
  "[emerg] SSL_CTX_set1_curves_list("foo") failed (SSL:)".

Likely there are other cases as well.

With this change, "(SSL:...)" will be only added to the error message
if there is something in the error queue.  This is expected to make
logs more readable in the above cases.  Additionally, with this change
it is now possible to use ngx_ssl_error() to log errors when some
of the possible errors are not from OpenSSL and not expected to have
anything in the error queue.

7 years agoStyle.
Maxim Dounin [Mon, 25 Feb 2019 13:41:08 +0000 (16:41 +0300)]
Style.

7 years agoSlab: removed redundant page calculation (ticket #1721).
Maxim Dounin [Tue, 12 Feb 2019 18:51:15 +0000 (21:51 +0300)]
Slab: removed redundant page calculation (ticket #1721).

7 years agoUpstream: fixed logging of required buffer size (ticket #1722).
Chanhun Jeong [Mon, 11 Feb 2019 04:36:53 +0000 (13:36 +0900)]
Upstream: fixed logging of required buffer size (ticket #1722).

7 years agoSSL: fixed EVP_DigestFinal_ex() error message.
Sergey Kandaurov [Thu, 7 Feb 2019 16:39:35 +0000 (19:39 +0300)]
SSL: fixed EVP_DigestFinal_ex() error message.

7 years agoSSL: separate checks for errors in ngx_ssl_read_password_file().
Maxim Dounin [Thu, 31 Jan 2019 16:36:51 +0000 (19:36 +0300)]
SSL: separate checks for errors in ngx_ssl_read_password_file().

Checking multiple errors at once is a bad practice, as in general
it is not guaranteed that an object can be used after the error.
In this particular case, checking errors after multiple allocations
can result in excessive errors being logged when there is no memory
available.

7 years agoSSL: explicitly zero out session ticket keys.
Ruslan Ermilov [Thu, 31 Jan 2019 16:28:07 +0000 (19:28 +0300)]
SSL: explicitly zero out session ticket keys.

7 years agoModules compatibility: down flag in ngx_peer_connection_t.
Roman Arutyunyan [Thu, 31 Jan 2019 14:25:03 +0000 (17:25 +0300)]
Modules compatibility: down flag in ngx_peer_connection_t.

7 years agoUse %s for errors returned from configuration parsing handlers.
Ruslan Ermilov [Tue, 25 Dec 2018 12:26:58 +0000 (15:26 +0300)]
Use %s for errors returned from configuration parsing handlers.

7 years agoConfigure: added explicit ngx_binext to the linker output argument.
Sergey Kandaurov [Wed, 30 Jan 2019 16:28:27 +0000 (19:28 +0300)]
Configure: added explicit ngx_binext to the linker output argument.

Unlike with GCC or MSVC, Clang linker doesn't auto-append ".exe" to the name
of the output binary when building on win32.

7 years agoRemoved --test-build-eventport workaround for old FreeBSD versions.
Sergey Kandaurov [Mon, 28 Jan 2019 14:34:02 +0000 (14:34 +0000)]
Removed --test-build-eventport workaround for old FreeBSD versions.

7 years agoFixed portability issues with union sigval.
Sergey Kandaurov [Mon, 28 Jan 2019 14:33:31 +0000 (14:33 +0000)]
Fixed portability issues with union sigval.

AIO support in nginx was originally developed against FreeBSD versions 4-6,
where the sival_ptr field was named as sigval_ptr (seemingly by mistake[1]),
which made nginx use the only name available then.  The standard-complaint
name was restored in 2005 (first appeared in FreeBSD 7.0, 2008), retaining
compatibility with previous versions[2][3].  In DragonFly, similar changes
were committed in 2009[4], with backward compatibility recently removed[5].

The change switches to the standard name, retaining compatibility with old
FreeBSD versions.

[1] https://svnweb.freebsd.org/changeset/base/48621
[2] https://svnweb.freebsd.org/changeset/base/152029
[3] https://svnweb.freebsd.org/changeset/base/174003
[4] https://gitweb.dragonflybsd.org/dragonfly.git/commit/3693401
[5] https://gitweb.dragonflybsd.org/dragonfly.git/commit/7875042

7 years agoYear 2019.
Maxim Konovalov [Mon, 28 Jan 2019 10:23:37 +0000 (13:23 +0300)]
Year 2019.

7 years agoWin32: detection of connect() errors in select().
Maxim Dounin [Thu, 24 Jan 2019 19:00:44 +0000 (22:00 +0300)]
Win32: detection of connect() errors in select().

On Windows, connect() errors are only reported via exceptfds descriptor set
from select().  Previously exceptfds was set to NULL, and connect() errors
were not detected at all, so connects to closed ports were waiting till
a timeout occurred.

Since ongoing connect() means that there will be a write event active,
except descriptor set is copied from the write one.  While it is possible
to construct except descriptor set as a concatenation of both read and write
descriptor sets, this looks unneeded.

With this change, connect() errors are properly detected now when using
select().  Note well that it is not possible to detect connect() errors with
WSAPoll() (see https://daniel.haxx.se/blog/2012/10/10/wsapoll-is-broken/).

7 years agoWin32: enabled both select and poll on Windows by default.
Maxim Dounin [Thu, 24 Jan 2019 19:00:13 +0000 (22:00 +0300)]
Win32: enabled both select and poll on Windows by default.

Since we now have both select and poll on Windows, it is enough to
do not set EVENT_FOUND, auto/modules will enable both automatically.

7 years agoWin32: added WSAPoll() support.
Maxim Dounin [Thu, 24 Jan 2019 18:51:21 +0000 (21:51 +0300)]
Win32: added WSAPoll() support.

WSAPoll() is only available with Windows Vista and newer (and only
available during compilation if _WIN32_WINNT >= 0x0600).  To make
sure the code works with Windows XP, we do not redefine _WIN32_WINNT,
but instead load WSAPoll() dynamically if it is not available during
compilation.

Also, sockets are not guaranteed to be small integers on Windows.
So an index array is used instead of NGX_USE_FD_EVENT to map
events to connections.

7 years agoWin32: properly enabled select on Windows.
Maxim Dounin [Thu, 24 Jan 2019 18:51:00 +0000 (21:51 +0300)]
Win32: properly enabled select on Windows.

Previously, select was compiled in by default, but the NGX_HAVE_SELECT
macro was not set, resulting in iocp being used by default unless
the "--with-select_module" configure option was explicitly specified.
Since the iocp module is not finished and does not work properly, this
effectively meant that the "--with-select_module" option was mandatory.

With the change NGX_HAVE_SELECT is properly set, making "--with-select_module"
optional.  Accordingly, it is removed from misc/GNUmakefile win32 target.

7 years agoEvents: fixed copying of old events in poll init.
Maxim Dounin [Thu, 24 Jan 2019 18:50:37 +0000 (21:50 +0300)]
Events: fixed copying of old events in poll init.

Previously, the code incorrectly assumed "ngx_event_t *" elements
instead of "struct pollfd".

This is mostly cosmetic change, as this code is never called now.

7 years agoStream: do not split datagrams when limiting proxy rate.
Roman Arutyunyan [Thu, 27 Dec 2018 16:37:34 +0000 (19:37 +0300)]
Stream: do not split datagrams when limiting proxy rate.

Previously, when using proxy_upload_rate and proxy_download_rate, the buffer
size for reading from a socket could be reduced as a result of rate limiting.
For connection-oriented protocols this behavior is normal since unread data will
normally be read at the next iteration.  But for datagram-oriented protocols
this is not the case, and unread part of the datagram is lost.

Now buffer size is not limited for datagrams.  Rate limiting still works in this
case by delaying the next reading event.

7 years agoPrevented scheduling events on a shared connection.
Roman Arutyunyan [Mon, 14 Jan 2019 17:36:23 +0000 (20:36 +0300)]
Prevented scheduling events on a shared connection.

A shared connection does not own its file descriptor, which means that
ngx_handle_read_event/ngx_handle_write_event calls should do nothing for it.
Currently the c->shared flag is checked in several places in the stream proxy
module prior to calling these functions.  However it was not done everywhere.
Missing checks could lead to calling
ngx_handle_read_event/ngx_handle_write_event on shared connections.

The problem manifested itself when using proxy_upload_rate and resulted in
either duplicate file descriptor error (e.g. with epoll) or incorrect further
udp packet processing (e.g. with kqueue).

The fix is to set and reset the event active flag in a way that prevents
ngx_handle_read_event/ngx_handle_write_event from scheduling socket events.

7 years agoAdded the ngx_http_test_required_predicates() function.
Vladimir Homutov [Thu, 17 Jan 2019 11:31:04 +0000 (14:31 +0300)]
Added the ngx_http_test_required_predicates() function.

In contrast to ngx_http_test_predicates(), it requires all values to be
non-empty and not equal to "0".

7 years agoVersion bump.
Vladimir Homutov [Thu, 17 Jan 2019 11:31:01 +0000 (14:31 +0300)]
Version bump.

7 years agorelease-1.15.8 tag
Maxim Dounin [Tue, 25 Dec 2018 14:53:03 +0000 (17:53 +0300)]
release-1.15.8 tag

7 years agonginx-1.15.8-RELEASE release-1.15.8
Maxim Dounin [Tue, 25 Dec 2018 14:53:03 +0000 (17:53 +0300)]
nginx-1.15.8-RELEASE

7 years agoAutoindex: fixed possible integer overflow on 32-bit systems.
Vladimir Homutov [Tue, 25 Dec 2018 09:59:24 +0000 (12:59 +0300)]
Autoindex: fixed possible integer overflow on 32-bit systems.

7 years agoContrib: vim syntax, update core and 3rd party module directives.
Gena Makhomed [Mon, 24 Dec 2018 14:30:10 +0000 (16:30 +0200)]
Contrib: vim syntax, update core and 3rd party module directives.

7 years agoWin32: removed NGX_DIR_MASK concept.
Maxim Dounin [Mon, 24 Dec 2018 18:07:05 +0000 (21:07 +0300)]
Win32: removed NGX_DIR_MASK concept.

Previous interface of ngx_open_dir() assumed that passed directory name
has a room for NGX_DIR_MASK at the end (NGX_DIR_MASK_LEN bytes).  While all
direct users of ngx_dir_open() followed this interface, this also implied
similar requirements for indirect uses - in particular, via ngx_walk_tree().

Currently none of ngx_walk_tree() uses provides appropriate space, and
fixing this does not look like a right way to go.  Instead, ngx_dir_open()
interface was changed to not require any additional space and use
appropriate allocations instead.

7 years agoUserid: using stub for AF_UNIX addresses.
Sergey Kandaurov [Mon, 24 Dec 2018 16:55:00 +0000 (19:55 +0300)]
Userid: using stub for AF_UNIX addresses.

Previously, AF_UNIX addresses misbehaved as AF_INET, which typically resulted
in $uid_set composed from the middle of sun_path.