]> git.kaiwu.me - nginx.git/log
nginx.git
8 years agoModules compatibility: down flag promoted to a bitmask.
Ruslan Ermilov [Fri, 22 Sep 2017 19:49:42 +0000 (22:49 +0300)]
Modules compatibility: down flag promoted to a bitmask.

It is to be used as a bitmask with various bits set/reset when appropriate.
63b8b157b776 made a similar change to ngx_http_upstream_rr_peer_t.down and
ngx_stream_upstream_rr_peer_t.down.

8 years agoStyle.
Ruslan Ermilov [Fri, 22 Sep 2017 15:37:49 +0000 (18:37 +0300)]
Style.

8 years agoDo not use the obsolete NGX_SOCKADDRLEN macro.
Ruslan Ermilov [Fri, 22 Sep 2017 10:10:49 +0000 (13:10 +0300)]
Do not use the obsolete NGX_SOCKADDRLEN macro.

The change in ac120e797d28 re-used the macro which was made obsolete
in adf25b8d0431.

8 years agoRemoved more remnants of the old pthread implementation.
Ruslan Ermilov [Mon, 18 Sep 2017 08:09:41 +0000 (11:09 +0300)]
Removed more remnants of the old pthread implementation.

After e284f3ff6831, ngx_crypt() can no longer return NGX_AGAIN.

8 years agoHTTP/2: shortened some debug log messages.
Maxim Dounin [Thu, 14 Sep 2017 16:06:06 +0000 (19:06 +0300)]
HTTP/2: shortened some debug log messages.

This ensures slightly more readable debug logs on 80-character-wide
terminals.

8 years agoHTTP/2: fixed debug log about indexed headers.
Maxim Dounin [Thu, 14 Sep 2017 16:06:05 +0000 (19:06 +0300)]
HTTP/2: fixed debug log about indexed headers.

Previously, "get indexed header" message was logged when in fact only
header name was obtained using an index, and "get indexed header name"
was logged when full header representation (name and value) was obtained
using an index.  Fixed version logs "get indexed name" and "get indexed
header" respectively.

8 years agoHTTP/2: added logging of 400 (Bad Request) reasons.
Maxim Dounin [Thu, 14 Sep 2017 16:06:03 +0000 (19:06 +0300)]
HTTP/2: added logging of 400 (Bad Request) reasons.

8 years agoStream: fixed logging UDP upstream timeout.
Roman Arutyunyan [Tue, 12 Sep 2017 10:44:04 +0000 (13:44 +0300)]
Stream: fixed logging UDP upstream timeout.

Previously, when the first UDP response packet was not received from the
proxied server within proxy_timeout, no error message was logged before
switching to the next upstream.  Additionally, when one of succeeding response
packets was not received within the timeout, the timeout error had low severity
because it was logged as a client connection error as opposed to upstream
connection error.

8 years agoIntroduced time truncation to December 31, 9999 (ticket #1368).
Maxim Dounin [Wed, 13 Sep 2017 12:53:19 +0000 (15:53 +0300)]
Introduced time truncation to December 31, 9999 (ticket #1368).

Various buffers are allocated in an assumption that there would be
no more than 4 year digits.  This might not be true on platforms
with 64-bit time_t, as 64-bit time_t is able to represent more than that.
Such dates with more than 4 year digits hardly make sense though, as
various date formats in use do not allow them anyway.

As such, all dates are now truncated by ngx_gmtime() to December 31, 9999.
This should have no effect on valid dates, though will prevent potential
buffer overflows on invalid ones.

8 years agoFixed ngx_gmtime() on 32-bit platforms with 64-bit time_t.
Maxim Dounin [Wed, 13 Sep 2017 12:52:01 +0000 (15:52 +0300)]
Fixed ngx_gmtime() on 32-bit platforms with 64-bit time_t.

In ngx_gmtime(), instead of casting to ngx_uint_t we now work with
time_t directly.  This allows using dates after 2038 on 32-bit platforms
which use 64-bit time_t, notably NetBSD and OpenBSD.

As the code is not able to work with negative time_t values, argument
is now set to 0 for negative values.  As a positive side effect, this
results in Epoch being used for such values instead of a date in distant
future.

8 years agoFixed reference to time parsing code after 8b6fa4842133.
Maxim Dounin [Wed, 13 Sep 2017 12:51:58 +0000 (15:51 +0300)]
Fixed reference to time parsing code after 8b6fa4842133.

8 years agoStyle.
Maxim Dounin [Wed, 13 Sep 2017 12:51:52 +0000 (15:51 +0300)]
Style.

8 years agoHTTP/2: signal 0-byte HPACK's dynamic table size.
Piotr Sikora [Wed, 30 Aug 2017 21:52:11 +0000 (14:52 -0700)]
HTTP/2: signal 0-byte HPACK's dynamic table size.

This change lets NGINX talk to clients with SETTINGS_HEADER_TABLE_SIZE
smaller than the default 4KB. Previously, NGINX would ACK the SETTINGS
frame with a small dynamic table size, but it would never send dynamic
table size update, leading to a connection-level COMPRESSION_ERROR.

Also, it allows clients to release 4KB of memory per connection, since
NGINX doesn't use HPACK's dynamic table when encoding headers, however
clients had to maintain it, since NGINX never signaled that it doesn't
use it.

Signed-off-by: Piotr Sikora <piotrsikora@google.com>
8 years agoTrailing space removed.
Maxim Dounin [Mon, 11 Sep 2017 13:41:39 +0000 (16:41 +0300)]
Trailing space removed.

8 years agoStream: relaxed next upstream condition (ticket #1317).
Roman Arutyunyan [Mon, 11 Sep 2017 12:32:31 +0000 (15:32 +0300)]
Stream: relaxed next upstream condition (ticket #1317).

When switching to a next upstream, some buffers could be stuck in the middle
of the filter chain.  A condition existed that raised an error when this
happened.  As it turned out, this condition prevented switching to a next
upstream if ssl preread was used with the TCP protocol (see the ticket).

In fact, the condition does not make sense for TCP, since after successful
connection to an upstream switching to another upstream never happens.  As for
UDP, the issue with stuck buffers is unlikely to happen, but is still possible.
Specifically, if a filter delays sending data to upstream.

The condition can be relaxed to only check the "buffered" bitmask of the
upstream connection.  The new condition is simpler and fixes the ticket issue
as well.  Additionally, the upstream_out chain is now reset for UDP prior to
connecting to a new upstream to prevent repeating the client data twice.

8 years agoVersion bump.
Roman Arutyunyan [Mon, 11 Sep 2017 12:46:23 +0000 (15:46 +0300)]
Version bump.

8 years agorelease-1.13.5 tag
Maxim Dounin [Tue, 5 Sep 2017 14:59:31 +0000 (17:59 +0300)]
release-1.13.5 tag

8 years agonginx-1.13.5-RELEASE release-1.13.5
Maxim Dounin [Tue, 5 Sep 2017 14:59:31 +0000 (17:59 +0300)]
nginx-1.13.5-RELEASE

8 years agoSecure link: fixed stack buffer overflow.
Roman Arutyunyan [Tue, 22 Aug 2017 18:22:59 +0000 (21:22 +0300)]
Secure link: fixed stack buffer overflow.

When secure link checksum has length of 23 or 24 bytes, decoded base64 value
could occupy 17 or 18 bytes which is more than 16 bytes previously allocated
for it on stack.  The buffer overflow does not have any security implications
since only one local variable was corrupted and this variable was not used in
this case.

The fix is to increase buffer size up to 18 bytes.  Useless buffer size
initialization is removed as well.

8 years agoUpstream: unconditional parsing of last_modified_time.
Maxim Dounin [Wed, 23 Aug 2017 16:20:06 +0000 (19:20 +0300)]
Upstream: unconditional parsing of last_modified_time.

This fixes at least the following cases, where no last_modified_time
(assuming caching is not enabled) resulted in incorrect behaviour:

- slice filter and If-Range requests (ticket #1357);
- If-Range requests with proxy_force_ranges;
- expires modified.

8 years agoSSL: fixed possible use-after-free in $ssl_server_name.
Maxim Dounin [Tue, 22 Aug 2017 14:36:12 +0000 (17:36 +0300)]
SSL: fixed possible use-after-free in $ssl_server_name.

The $ssl_server_name variable used SSL_get_servername() result directly,
but this is not safe: it references a memory allocation in an SSL
session, and this memory might be freed at any time due to renegotiation.
Instead, copy the name to memory allocated from the pool.

8 years agoSSL: the $ssl_client_escaped_cert variable (ticket #857).
Maxim Dounin [Tue, 22 Aug 2017 12:18:10 +0000 (15:18 +0300)]
SSL: the $ssl_client_escaped_cert variable (ticket #857).

This variable contains URL-encoded client SSL certificate.  In contrast
to $ssl_client_cert, it doesn't depend on deprecated header continuation.
The NGX_ESCAPE_URI_COMPONENT variant of encoding is used, so the resulting
variable can be safely used not only in headers, but also as a request
argument.

The $ssl_client_cert variable should be considered deprecated now.
The $ssl_client_raw_cert variable will be eventually renambed back
to $ssl_client_cert.

8 years agoRange filter: changed type for total length to off_t.
Maxim Dounin [Thu, 10 Aug 2017 19:21:23 +0000 (22:21 +0300)]
Range filter: changed type for total length to off_t.

Total length of a response with multiple ranges can be larger than a size_t
variable can hold, so type changed to off_t.  Previously, an incorrect
Content-Length was returned when requesting more than 4G of ranges from
a large enough file on a 32-bit system.

An additional size_t variable introduced to calculate size of the boundary
header buffer, as off_t is not needed here and will require type casts on
win32.

Reported by Shuxin Yang,
http://mailman.nginx.org/pipermail/nginx/2017-July/054384.html.

8 years agoRestored ngx_event_aio_t layout for debug logging.
Maxim Dounin [Thu, 10 Aug 2017 19:21:22 +0000 (22:21 +0300)]
Restored ngx_event_aio_t layout for debug logging.

The "fd" field should be after 3 pointers for ngx_event_ident() to use it.
This was broken by ccad84a174e0.  While it does not seem to be currently used
for aio-related events, it should be a good idea to preserve the correct
layout nevertheless.

8 years agoStyle.
Maxim Dounin [Thu, 10 Aug 2017 19:21:20 +0000 (22:21 +0300)]
Style.

8 years agoFixed calls to ngx_open_file() in certain places.
Sergey Kandaurov [Wed, 9 Aug 2017 12:03:27 +0000 (15:03 +0300)]
Fixed calls to ngx_open_file() in certain places.

Pass NGX_FILE_OPEN to ngx_open_file() to fix "The parameter is incorrect"
error on win32 when using the ssl_session_ticket_key directive or loading
a binary geo base.  On UNIX, this change is a no-op.

8 years agoStyle.
Sergey Kandaurov [Wed, 9 Aug 2017 11:59:46 +0000 (14:59 +0300)]
Style.

8 years agoVersion bump.
Sergey Kandaurov [Wed, 9 Aug 2017 11:59:44 +0000 (14:59 +0300)]
Version bump.

8 years agorelease-1.13.4 tag
Maxim Dounin [Tue, 8 Aug 2017 15:00:11 +0000 (18:00 +0300)]
release-1.13.4 tag

8 years agonginx-1.13.4-RELEASE release-1.13.4
Maxim Dounin [Tue, 8 Aug 2017 15:00:11 +0000 (18:00 +0300)]
nginx-1.13.4-RELEASE

8 years agoUpdated PCRE used for win32 builds.
Maxim Dounin [Tue, 8 Aug 2017 12:21:10 +0000 (15:21 +0300)]
Updated PCRE used for win32 builds.

8 years agoSlab: fixed initialization on win32.
Ruslan Ermilov [Tue, 8 Aug 2017 12:16:01 +0000 (15:16 +0300)]
Slab: fixed initialization on win32.

On Windows, a worker process does not call ngx_slab_init() from
ngx_init_zone_pool(), so ngx_slab_max_size, ngx_slab_exact_size,
and ngx_slab_exact_shift were left uninitialized.

8 years agoUpstream: copy peer data in shared memory.
Ruslan Ermilov [Fri, 4 Aug 2017 14:03:10 +0000 (17:03 +0300)]
Upstream: copy peer data in shared memory.

This, in addition to 1eb753aa8e5e, fixes "upstream zone" on Windows.

8 years agoReferer: fixed $invalid_referer.
Ruslan Ermilov [Fri, 4 Aug 2017 05:01:55 +0000 (08:01 +0300)]
Referer: fixed $invalid_referer.

The variable was considered non-existent in the absence of any
valid_referers directives.

Given the following config snippet,

    location / {
        return 200 $invalid_referer;
    }

    location /referer {
        valid_referers server_names;
    }

"location /" should work identically and independently on other
"location /referer".

The fix is to always add the $invalid_referer variable as long
as the module is compiled in, as is done by other modules.

8 years agoUpstream zone: store peers->name and its data in shared memory.
Ruslan Ermilov [Tue, 1 Aug 2017 16:12:10 +0000 (19:12 +0300)]
Upstream zone: store peers->name and its data in shared memory.

The shared objects should generally be allocated from shared memory.
While peers->name and the data it points to allocated from cf->pool
happened to work on UNIX, it broke on Windows.  On UNIX this worked
only because the shared memory zone for upstreams is re-created for
every new configuration.

But on Windows, a worker process does not inherit the address space
of the master process, so the peers->name pointed to data allocated
from cf->pool by the master process, and was invalid.

8 years agoVariables: macros for null variables.
Ruslan Ermilov [Tue, 1 Aug 2017 11:28:33 +0000 (14:28 +0300)]
Variables: macros for null variables.

No functional changes.

8 years agoBrowser: style.
Ruslan Ermilov [Tue, 1 Aug 2017 11:27:23 +0000 (14:27 +0300)]
Browser: style.

Removed custom variable type and renamed function that adds variables.

8 years agoCache: fixed max_size on win32.
Ruslan Ermilov [Wed, 26 Jul 2017 10:13:51 +0000 (13:13 +0300)]
Cache: fixed max_size on win32.

8 years agoSSL: fixed typo in the error message.
Sergey Kandaurov [Tue, 25 Jul 2017 14:21:59 +0000 (17:21 +0300)]
SSL: fixed typo in the error message.

8 years agoMirror: "off" paramater of the "mirror" directive.
Roman Arutyunyan [Fri, 21 Jul 2017 16:47:56 +0000 (19:47 +0300)]
Mirror: "off" paramater of the "mirror" directive.

8 years agoMirror module.
Roman Arutyunyan [Thu, 20 Jul 2017 05:50:49 +0000 (08:50 +0300)]
Mirror module.

8 years agoPrecontent phase.
Roman Arutyunyan [Thu, 20 Jul 2017 12:51:11 +0000 (15:51 +0300)]
Precontent phase.

The phase is added instead of the try_files phase.  Unlike the old phase, the
new one supports registering multiple handlers.  The try_files implementation is
moved to a separate ngx_http_try_files_module, which now registers a precontent
phase handler.

8 years agoUpstream: keep request body file from removal if requested.
Roman Arutyunyan [Wed, 19 Jul 2017 17:38:17 +0000 (20:38 +0300)]
Upstream: keep request body file from removal if requested.

The new request flag "preserve_body" indicates that the request body file should
not be removed by the upstream module because it may be used later by a
subrequest.  The flag is set by the SSI (ticket #585), addition and slice
modules.  Additionally, it is also set by the upstream module when a background
cache update subrequest is started to prevent the request body file removal
after an internal redirect.  Only the main request is now allowed to remove the
file.

8 years agoStyle.
Alex Zhang [Wed, 19 Jul 2017 13:39:40 +0000 (21:39 +0800)]
Style.

Signed-off-by: Alex Zhang <zchao1995@gmail.com>
8 years agoConfigure: fixed PCRE requirement check by ngx_http_rewrite_module.
Samuel Martin [Wed, 19 Jul 2017 09:05:50 +0000 (12:05 +0300)]
Configure: fixed PCRE requirement check by ngx_http_rewrite_module.

The http_rewrite module cannot be selected when http is disabled.
Fixed the PCRE check condition to avoid irrelevant check failure.
This is a regression from 4d874b4d82ed.

Signed-off-by: Samuel Martin <s.martin49@gmail.com>
8 years agoParenthesized ASCII-related calculations.
Valentin Bartenev [Mon, 17 Jul 2017 14:23:51 +0000 (17:23 +0300)]
Parenthesized ASCII-related calculations.

This also fixes potential undefined behaviour in the range and slice filter
modules, caused by local overflows of signed integers in expressions.

8 years agoStyle: aligned ngx_null_command.
Ruslan Ermilov [Wed, 12 Jul 2017 08:34:04 +0000 (11:34 +0300)]
Style: aligned ngx_null_command.

8 years agoCore: fixed error message on setsockopt(SO_REUSEPORT) failure.
Maxim Dounin [Tue, 11 Jul 2017 17:06:52 +0000 (20:06 +0300)]
Core: fixed error message on setsockopt(SO_REUSEPORT) failure.

The error is fatal when configuring a new socket, so the ", ignored" part
is not appropriate and was removed.

8 years agoCore: disabled SO_REUSEPORT when testing config (ticket #1300).
Maxim Dounin [Tue, 11 Jul 2017 16:59:56 +0000 (19:59 +0300)]
Core: disabled SO_REUSEPORT when testing config (ticket #1300).

When closing a socket with SO_REUSEPORT, Linux drops all connections waiting
in this socket's listen queue.  Previously, it was believed to only result
in connection resets when reconfiguring nginx to use smaller number of worker
processes.  It also results in connection resets during configuration
testing though.

Workaround is to avoid using SO_REUSEPORT when testing configuration.  It
should prevent listening sockets from being created if a conflicting socket
already exists, while still preserving detection of other possible errors.
It should also cover UDP sockets.

The only downside of this approach seems to be that a configuration testing
won't be able to properly report the case when nginx was compiled with
SO_REUSEPORT, but the kernel is not able to set it.  Such errors will be
reported on a real start instead.

8 years agoVersion bump.
Maxim Dounin [Tue, 11 Jul 2017 16:59:16 +0000 (19:59 +0300)]
Version bump.

8 years agorelease-1.13.3 tag
Maxim Dounin [Tue, 11 Jul 2017 13:18:31 +0000 (16:18 +0300)]
release-1.13.3 tag

8 years agonginx-1.13.3-RELEASE release-1.13.3
Maxim Dounin [Tue, 11 Jul 2017 13:18:30 +0000 (16:18 +0300)]
nginx-1.13.3-RELEASE

8 years agoRange filter: avoid negative range start.
Maxim Dounin [Tue, 11 Jul 2017 13:06:26 +0000 (16:06 +0300)]
Range filter: avoid negative range start.

Suffix ranges no longer allowed to set negative start values, to prevent
ranges with negative start from appearing even if total size protection
will be removed.

8 years agoRange filter: protect from total size overflows.
Maxim Dounin [Tue, 11 Jul 2017 13:06:23 +0000 (16:06 +0300)]
Range filter: protect from total size overflows.

The overflow can be used to circumvent the restriction on total size of
ranges introduced in c2a91088b0c0 (1.1.2).  Additionally, overflow
allows producing ranges with negative start (such ranges can be created
by using a suffix, "bytes=-100"; normally this results in 200 due to
the total size check).  These can result in the following errors in logs:

[crit] ... pread() ... failed (22: Invalid argument)
[alert] ... sendfile() failed (22: Invalid argument)

When using cache, it can be also used to reveal cache file header.
It is believed that there are no other negative effects, at least with
standard nginx modules.

In theory, this can also result in memory disclosure and/or segmentation
faults if multiple ranges are allowed, and the response is returned in a
single in-memory buffer.  This never happens with standard nginx modules
though, as well as known 3rd party modules.

Fix is to properly protect from possible overflow when incrementing size.

8 years agoVariables: use ngx_http_variable_null_value where appropriate.
Ruslan Ermilov [Fri, 7 Jul 2017 11:34:21 +0000 (14:34 +0300)]
Variables: use ngx_http_variable_null_value where appropriate.

8 years agoResolver: cancelable resend timer event.
Ruslan Ermilov [Tue, 4 Jul 2017 15:50:41 +0000 (18:50 +0300)]
Resolver: cancelable resend timer event.

It is safe because re-sending still works during graceful shutdown as
long as resolving takes place (and resolve tasks set their own timeouts
that are not cancelable).

Also, the new ctx->cancelable flag can be set to make resolve task's
timeout event cancelable.

8 years agoResolver: factored out setting a timer for resolver timeout.
Sergey Kandaurov [Tue, 4 Jul 2017 15:46:30 +0000 (18:46 +0300)]
Resolver: factored out setting a timer for resolver timeout.

No functional changes.

8 years agoSlab: fixed small allocations on systems with large pagesize.
Ruslan Ermilov [Tue, 4 Jul 2017 15:32:30 +0000 (18:32 +0300)]
Slab: fixed small allocations on systems with large pagesize.

Notably, on ppc64 with 64k pagesize, slab 0 (of size 8) requires
128 64-bit elements for bitmasks.  The code bogusly assumed that
one uintptr_t is enough for bitmasks plus at least one free slot.

8 years agoSlab: style.
Ruslan Ermilov [Tue, 4 Jul 2017 15:32:28 +0000 (18:32 +0300)]
Slab: style.

8 years agoResolver: fixed possible use-after-free while resolving SRV.
Roman Arutyunyan [Tue, 4 Jul 2017 15:07:29 +0000 (18:07 +0300)]
Resolver: fixed possible use-after-free while resolving SRV.

Resolving an SRV record includes resolving its host names in subrequests.
Previously, if memory allocation failed while reporting a subrequest result
after receiving a response from a DNS server, the SRV resolve handler was
called immediately with the NGX_ERROR state.  However, if the SRV record
included another copy of the resolved name, it was reported once again.
This could trigger the use-after-free memory access after SRV resolve
handler freed the resolve context by calling ngx_resolve_name_done().

Now the SRV resolve handler is called only when all its subrequests are
completed.

9 years agoProxy: split configured header names and values.
Piotr Sikora [Wed, 15 Mar 2017 22:55:35 +0000 (15:55 -0700)]
Proxy: split configured header names and values.

Previously, each configured header was represented in one of two ways,
depending on whether or not its value included any variables.

If the value didn't include any variables, then it would be represented
as as a single script that contained complete header line with HTTP/1.1
delimiters, i.e.:

     "Header: value\r\n"

But if the value included any variables, then it would be represented
as a series of three scripts: first contained header name and the ": "
delimiter, second evaluated to header value, and third contained only
"\r\n", i.e.:

     "Header: "
     "$value"
     "\r\n"

This commit changes that, so that each configured header is represented
as a series of two scripts: first contains only header name, and second
contains (or evaluates to) only header value, i.e.:

    "Header"
    "$value"

or

    "Header"
    "value"

This not only makes things more consistent, but also allows header name
and value to be accessed separately.

Signed-off-by: Piotr Sikora <piotrsikora@google.com>
8 years agoVersion bump.
Maxim Dounin [Mon, 3 Jul 2017 13:58:08 +0000 (16:58 +0300)]
Version bump.

8 years agorelease-1.13.2 tag
Maxim Dounin [Tue, 27 Jun 2017 14:44:18 +0000 (17:44 +0300)]
release-1.13.2 tag

8 years agonginx-1.13.2-RELEASE release-1.13.2
Maxim Dounin [Tue, 27 Jun 2017 14:44:17 +0000 (17:44 +0300)]
nginx-1.13.2-RELEASE

8 years agoRange filter: allowed ranges on empty files (ticket #1031).
Maxim Dounin [Mon, 26 Jun 2017 21:53:46 +0000 (00:53 +0300)]
Range filter: allowed ranges on empty files (ticket #1031).

As per RFC 2616 / RFC 7233, any range request to an empty file
is expected to result in 416 Range Not Satisfiable response, as
there cannot be a "byte-range-spec whose first-byte-pos is less
than the current length of the entity-body".  On the other hand,
this makes use of byte-range requests inconvenient in some cases,
as reported for the slice module here:

http://mailman.nginx.org/pipermail/nginx-devel/2017-June/010177.html

This commit changes range filter to instead return 200 if the file
is empty and the range requested starts at 0.

8 years agoUpstream: introduced ngx_http_upstream_ssl_handshake_handler().
Maxim Dounin [Thu, 22 Jun 2017 18:09:06 +0000 (21:09 +0300)]
Upstream: introduced ngx_http_upstream_ssl_handshake_handler().

This change reworks 13a5f4765887 to only run posted requests once,
with nothing on stack.  Running posted requests with other request
functions on stack may result in use-after-free in case of errors,
similar to the one reported in #788.

To only run posted request once, a separate function was introduced
to be used as ssl handshake handler in c->ssl->handler,
ngx_http_upstream_ssl_handshake_handler().  The ngx_http_run_posted_requests()
is only called in this function, and not in ngx_http_upstream_ssl_handshake()
which may be called directly on stack.

Additionaly, ngx_http_upstream_ssl_handshake_handler() now does appropriate
debug logging of the current subrequest, similar to what is done in other
event handlers.

8 years agoUpstream: fixed running posted requests (ticket #788).
Roman Arutyunyan [Wed, 14 Jun 2017 17:13:41 +0000 (20:13 +0300)]
Upstream: fixed running posted requests (ticket #788).

Previously, the upstream resolve handler always called
ngx_http_run_posted_requests() to run posted requests after processing the
resolver response.  However, if the handler was called directly from the
ngx_resolve_name() function (for example, if the resolver response was cached),
running posted requests from the handler could lead to the following errors:

- If the request was scheduled for termination, it could actually be terminated
in the resolve handler.  Upper stack frames could reference the freed request
object in this case.

- If a significant number of requests were posted, and for each of them the
resolve handler was called directly from the ngx_resolve_name() function,
posted requests could be run recursively and lead to stack overflow.

Now ngx_http_run_posted_requests() is only called from asynchronously invoked
resolve handlers.

8 years agoResolver: added the "async" flag to resolver context.
Roman Arutyunyan [Wed, 14 Jun 2017 15:13:31 +0000 (18:13 +0300)]
Resolver: added the "async" flag to resolver context.

The flag indicates that the resolve handler is called asynchronously after the
resolve function ngx_resolve_name()/ngx_resolve_addr() exited.

8 years agoResolver: fixed allocation error handling while resolving SRV.
Bart Warmerdam [Mon, 19 Jun 2017 11:25:42 +0000 (14:25 +0300)]
Resolver: fixed allocation error handling while resolving SRV.

8 years agoIntroduced ngx_rwlock_downgrade().
Ruslan Ermilov [Fri, 16 Jun 2017 15:15:58 +0000 (18:15 +0300)]
Introduced ngx_rwlock_downgrade().

8 years agoAdded memory barrier semantics to ngx_rwlock_unlock().
Ruslan Ermilov [Fri, 16 Jun 2017 15:15:53 +0000 (18:15 +0300)]
Added memory barrier semantics to ngx_rwlock_unlock().

9 years agoHeaders filter: added "add_trailer" directive.
Piotr Sikora [Fri, 24 Mar 2017 10:37:34 +0000 (03:37 -0700)]
Headers filter: added "add_trailer" directive.

Trailers added using this directive are evaluated after response body
is processed by output filters (but before it's written to the wire),
so it's possible to use variables calculated from the response body
as the trailer value.

Signed-off-by: Piotr Sikora <piotrsikora@google.com>
9 years agoHTTP/2: added support for trailers in HTTP responses.
Piotr Sikora [Fri, 24 Mar 2017 10:37:34 +0000 (03:37 -0700)]
HTTP/2: added support for trailers in HTTP responses.

Signed-off-by: Piotr Sikora <piotrsikora@google.com>
9 years agoAdded support for trailers in HTTP responses.
Piotr Sikora [Fri, 24 Mar 2017 10:37:34 +0000 (03:37 -0700)]
Added support for trailers in HTTP responses.

Example:

   ngx_table_elt_t  *h;

   h = ngx_list_push(&r->headers_out.trailers);
   if (h == NULL) {
       return NGX_ERROR;
   }

   ngx_str_set(&h->key, "Fun");
   ngx_str_set(&h->value, "with trailers");
   h->hash = ngx_hash_key_lc(h->key.data, h->key.len);

The code above adds "Fun: with trailers" trailer to the response.

Modules that want to emit trailers must set r->expect_trailers = 1
in header filter, otherwise they might not be emitted for HTTP/1.1
responses that aren't already chunked.

This change also adds $sent_trailer_* variables.

Signed-off-by: Piotr Sikora <piotrsikora@google.com>
8 years agoGzip: fixed style in $gzip_ratio variable handler.
Ruslan Ermilov [Wed, 14 Jun 2017 09:49:20 +0000 (12:49 +0300)]
Gzip: fixed style in $gzip_ratio variable handler.

The current style in variable handlers returning NGX_OK is to either set
v->not_found to 1, or to initialize the entire ngx_http_variable_value_t
structure.

In theory, always setting v->valid = 1 for NGX_OK would be useful, which
would mean that the value was computed and is thus valid, including the
special case of v->not_found = 1.  But currently that's not the case and
causes the (v->valid || v->not_found) check to access an uninitialized
v->valid value, which is safe only because its value doesn't matter when
v->not_found is set.

8 years agoRemoved excessive casts for ngx_file_info().
Ruslan Ermilov [Wed, 14 Jun 2017 09:29:52 +0000 (12:29 +0300)]
Removed excessive casts for ngx_file_info().

8 years agoConfigure: use .exe for binaries for all win32 compilers.
Orgad Shaneh [Tue, 6 Jun 2017 16:37:34 +0000 (19:37 +0300)]
Configure: use .exe for binaries for all win32 compilers.

8 years agoConfigure: fix compilation on MSYS2 / MinGW64.
Orgad Shaneh [Tue, 6 Jun 2017 15:13:39 +0000 (18:13 +0300)]
Configure: fix compilation on MSYS2 / MinGW64.

8 years agoHTTP/2: reject HTTP/2 requests without ":scheme" pseudo-header.
Piotr Sikora [Tue, 13 Jun 2017 14:01:08 +0000 (17:01 +0300)]
HTTP/2: reject HTTP/2 requests without ":scheme" pseudo-header.

Signed-off-by: Piotr Sikora <piotrsikora@google.com>
8 years agoUserid: ngx_http_get_indexed_variable() error handling.
Sergey Kandaurov [Wed, 7 Jun 2017 15:46:36 +0000 (18:46 +0300)]
Userid: ngx_http_get_indexed_variable() error handling.

When evaluating a mapped $reset_uid variable in the userid filter,
if get_handler set to ngx_http_map_variable() returned an error,
this previously resulted in a NULL pointer dereference.

8 years agoFixed segfault in try_files with nested location.
Sergey Kandaurov [Wed, 7 Jun 2017 15:46:35 +0000 (18:46 +0300)]
Fixed segfault in try_files with nested location.

If memory allocation of a new r->uri.data storage failed, reset its length as
well.  Request URI is used in ngx_http_finalize_request() for debug logging.

8 years agoSSI: return NGX_ERROR when timefmt memory allocation failed.
Sergey Kandaurov [Wed, 7 Jun 2017 12:21:42 +0000 (15:21 +0300)]
SSI: return NGX_ERROR when timefmt memory allocation failed.

Previously, when using NGX_HTTP_SSI_ERROR, error was ignored in ssi processing,
thus timefmt could be accessed later in ngx_http_ssi_date_gmt_local_variable()
as part of "set" handler, or NULL format pointer could be passed to strftime().

8 years agoHTTP/2: don't send SETTINGS ACK before already queued DATA frames.
Piotr Sikora [Fri, 2 Jun 2017 12:05:32 +0000 (15:05 +0300)]
HTTP/2: don't send SETTINGS ACK before already queued DATA frames.

Previously, SETTINGS ACK was sent immediately upon receipt of SETTINGS
frame, before already queued DATA frames created using old SETTINGS.

This incorrect behavior was source of interoperability issues, because
peers rely on the fact that new SETTINGS are in effect after receiving
SETTINGS ACK.

Reported by Feng Li.

Signed-off-by: Piotr Sikora <piotrsikora@google.com>
8 years agoHTTP/2: make SETTINGS ACK frame reusable.
Piotr Sikora [Fri, 2 Jun 2017 12:05:28 +0000 (15:05 +0300)]
HTTP/2: make SETTINGS ACK frame reusable.

Signed-off-by: Piotr Sikora <piotrsikora@google.com>
8 years agoHTTP/2: send SETTINGS ACK after applying all SETTINGS params.
Piotr Sikora [Fri, 2 Jun 2017 12:05:24 +0000 (15:05 +0300)]
HTTP/2: send SETTINGS ACK after applying all SETTINGS params.

This avoids sending unnecessary SETTINGS ACK in case of PROTOCOL_ERROR.

Signed-off-by: Piotr Sikora <piotrsikora@google.com>
8 years agoHTTP/2: emit new frames only after applying all SETTINGS params.
Piotr Sikora [Fri, 2 Jun 2017 12:05:20 +0000 (15:05 +0300)]
HTTP/2: emit new frames only after applying all SETTINGS params.

Previously, new frames could be emitted in the middle of applying
new (and already acknowledged) SETTINGS params, which is illegal.

Signed-off-by: Piotr Sikora <piotrsikora@google.com>
8 years agoConfigure: enabled rpath for NetBSD.
Sergey Kandaurov [Fri, 2 Jun 2017 09:55:31 +0000 (12:55 +0300)]
Configure: enabled rpath for NetBSD.

8 years agoConfigure: disabled IP_PKTINFO feature on certain platforms.
Roman Arutyunyan [Thu, 1 Jun 2017 12:44:23 +0000 (15:44 +0300)]
Configure: disabled IP_PKTINFO feature on certain platforms.

On Cygwin and NetBSD 7.0+ struct in_pktinfo has no ipi_spec_dst field, which
caused nginx compilation error.  Now presence of this field is ensured by the
IP_PKTINFO feature test.

The problem was introduced by dbb0c854e308 (1.13.0).

8 years agoStyle.
Maxim Dounin [Thu, 1 Jun 2017 13:49:14 +0000 (16:49 +0300)]
Style.

8 years agoUpstream: style.
Piotr Sikora [Wed, 31 May 2017 20:51:36 +0000 (13:51 -0700)]
Upstream: style.

Signed-off-by: Piotr Sikora <piotrsikora@google.com>
8 years agoHeaders filter: style.
Piotr Sikora [Wed, 31 May 2017 20:51:35 +0000 (13:51 -0700)]
Headers filter: style.

Signed-off-by: Piotr Sikora <piotrsikora@google.com>
8 years agoHTTP/2: add debug logging of pseudo-headers and cookies.
Piotr Sikora [Tue, 30 May 2017 14:42:27 +0000 (17:42 +0300)]
HTTP/2: add debug logging of pseudo-headers and cookies.

Signed-off-by: Piotr Sikora <piotrsikora@google.com>
8 years agoVersion bump.
Valentin Bartenev [Tue, 30 May 2017 16:29:45 +0000 (19:29 +0300)]
Version bump.

8 years agorelease-1.13.1 tag
Maxim Dounin [Tue, 30 May 2017 14:55:23 +0000 (17:55 +0300)]
release-1.13.1 tag

8 years agonginx-1.13.1-RELEASE release-1.13.1
Maxim Dounin [Tue, 30 May 2017 14:55:22 +0000 (17:55 +0300)]
nginx-1.13.1-RELEASE

8 years agoUpdated OpenSSL used for win32 builds.
Maxim Dounin [Tue, 30 May 2017 14:14:00 +0000 (17:14 +0300)]
Updated OpenSSL used for win32 builds.

8 years agoFixed background requests with asynchronous operations.
Roman Arutyunyan [Mon, 29 May 2017 20:33:38 +0000 (23:33 +0300)]
Fixed background requests with asynchronous operations.

If the main request was finalized while a background request performed an
asynchronous operation, the main request ended up in ngx_http_writer() and was
not finalized until a network event or a timeout.  For example, cache
background update with aio enabled made nginx unable to process further client
requests or close the connection, keeping it open until client closes it.

Now regular finalization of the main request is not suspended because of an
asynchronous operation in another request.

If a background request was terminated while an asynchronous operation was in
progress, background request's write event handler was changed to
ngx_http_request_finalizer() and never called again.

Now, whenever a request is terminated while an asynchronous operation is in
progress, connection error flag is set to make further finalizations of any
request with this connection lead to termination.

These issues appeared in 1aeaae6e9446 (not yet released).

8 years agoConfigure: sched_setaffinity() test moved to auto/unix.
Maxim Dounin [Mon, 29 May 2017 13:48:30 +0000 (16:48 +0300)]
Configure: sched_setaffinity() test moved to auto/unix.

The sched_setaffinity() function was introduced in DragonFly BSD 4.7,
so it is no longer Linux-specific.

Prodded by Sepherosa Ziehau.

8 years agoStyle: changed checks of ngx_ssl_create_connection() to != NGX_OK.
Maxim Dounin [Mon, 29 May 2017 13:34:35 +0000 (16:34 +0300)]
Style: changed checks of ngx_ssl_create_connection() to != NGX_OK.

In http these checks were changed in a6d6d762c554, though mail module
was missed at that time.  Since then, the stream module was introduced
based on mail, using "== NGX_ERROR" check.

8 years agoSSL: set TCP_NODELAY on SSL connections before handshake.
Maxim Dounin [Mon, 29 May 2017 13:34:29 +0000 (16:34 +0300)]
SSL: set TCP_NODELAY on SSL connections before handshake.

With OpenSSL 1.1.0+, the workaround for handshake buffer size as introduced
in a720f0b0e083 (ticket #413) no longer works, as OpenSSL no longer exposes
handshake buffers, see https://github.com/openssl/openssl/commit/2e7dc7cd688.
Moreover, it is no longer possible to adjust handshake buffers at all now.

To avoid additional RTT if handshake uses more than 4k we now set TCP_NODELAY
on SSL connections before handshake.  While this still results in sub-optimal
network utilization due to incomplete packets being sent, it seems to be
better than nothing.