summaryrefslogtreecommitdiffhomepage
path: root/src (follow)
AgeCommit message (Collapse)AuthorFilesLines
2017-10-05Upstream hash: limited number of tries in consistent case.Maxim Dounin2-6/+14
While this may result in non-ideal distribution of requests if nginx won't be able to select a server in a reasonable number of attempts, this still looks better than severe performance degradation observed if there is no limit and there are many points configured (ticket #1030). This is also in line with what we do for other hash balancing methods.
2017-10-05Fixed build without IPv6, broken by 874171c3c71a.Maxim Dounin1-1/+3
2017-10-04Fixed handling of unix sockets in $binary_remote_addr.Maxim Dounin2-0/+24
Previously, unix sockets were treated as AF_INET ones, and this may result in buffer overread on Linux, where unbound unix sockets have 2-byte addresses. Note that it is not correct to use just sun_path as a binary representation for unix sockets. This will result in an empty string for unbound unix sockets, and thus behaviour of limit_req and limit_conn will change when switching from $remote_addr to $binary_remote_addr. As such, normal text representation is used. Reported by Stephan Dollberg.
2017-10-04Fixed handling of non-null-terminated unix sockets.Maxim Dounin3-1/+21
At least FreeBSD, macOS, NetBSD, and OpenBSD can return unix sockets with non-null-terminated sun_path. Additionally, the address may become non-null-terminated if it does not fit into the buffer provided and was truncated (may happen on macOS, NetBSD, and Solaris, which allow unix socket addresess larger than struct sockaddr_un). As such, ngx_sock_ntop() might overread the sockaddr provided, as it used "%s" format and thus assumed null-terminated string. To fix this, the ngx_strnlen() function was introduced, and it is now used to calculate correct length of sun_path.
2017-10-04Fixed buffer overread with unix sockets after accept().Maxim Dounin2-0/+12
Some OSes (notably macOS, NetBSD, and Solaris) allow unix socket addresses larger than struct sockaddr_un. Moreover, some of them (macOS, Solaris) return socklen of the socket address before it was truncated to fit the buffer provided. As such, on these systems socklen must not be used without additional check that it is within the buffer provided. Appropriate checks added to ngx_event_accept() (after accept()), ngx_event_recvmsg() (after recvmsg()), and ngx_set_inherited_sockets() (after getsockname()). We also obtain socket addresses via getsockname() in ngx_connection_local_sockaddr(), but it does not need any checks as it is only used for INET and INET6 sockets (as there can be no wildcard unix sockets).
2017-10-04HTTP/2: enforce writing the sync request body buffer to file.Valentin Bartenev1-5/+2
The sync flag of HTTP/2 request body buffer is used when the size of request body is unknown or bigger than configured "client_body_buffer_size". In this case the buffer points to body data inside the global receive buffer that is used for reading all HTTP/2 connections in the worker process. Thus, when the sync flag is set, the buffer must be flushed to a temporary file, otherwise the request body data can be overwritten. Previously, the sync buffer wasn't flushed to a temporary file if the whole body was received in one DATA frame with the END_STREAM flag and wasn't copied into the HTTP/2 body preread buffer. As a result, the request body might be corrupted (ticket #1384). Now, setting r->request_body_in_file_only enforces writing the sync buffer to a temporary file in all cases.
2017-10-03Cache: fixed caching of intercepted errors (ticket #1382).Maxim Dounin1-5/+15
When caching intercepted errors, previous behaviour was to use proxy_cache_valid times specified, regardless of various cache control headers present in the response. Fix is to check u->cacheable and use u->cache->valid_sec as set by various cache control response headers, similar to how we do this in the normal caching code path.
2017-10-02Upstream: better handling of invalid headers in cache files.Maxim Dounin1-0/+10
If cache file is truncated, it is possible that u->process_header() will return NGX_AGAIN. Added appropriate handling of this case by changing the error to NGX_HTTP_UPSTREAM_INVALID_HEADER. Also, added appropriate logging of this and NGX_HTTP_UPSTREAM_INVALID_HEADER cases at the "crit" level. Note that this will result in duplicate logging in case of NGX_HTTP_UPSTREAM_INVALID_HEADER. While this is something better to avoid, it is considered to be an overkill to implement cache-specific error logging in u->process_header(). Additionally, u->buffer.start is now reset to be able to receive a new response, and u->cache_status set to MISS to provide the value in the $upstream_cache_status variable, much like it happens on other cache file errors detected by ngx_http_file_cache_read(), instead of HIT, which is believed to be misleading.
2017-09-25Fixed the NGX_UNIX_ADDRSTRLEN macro.Ruslan Ermilov1-2/+3
2017-09-22Modules compatibility: down flag promoted to a bitmask.Ruslan Ermilov2-2/+2
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.
2017-09-22Style.Ruslan Ermilov1-1/+1
2017-09-22Do not use the obsolete NGX_SOCKADDRLEN macro.Ruslan Ermilov2-2/+2
The change in ac120e797d28 re-used the macro which was made obsolete in adf25b8d0431.
2017-09-18Removed more remnants of the old pthread implementation.Ruslan Ermilov2-65/+15
After e284f3ff6831, ngx_crypt() can no longer return NGX_AGAIN.
2017-09-14HTTP/2: shortened some debug log messages.Maxim Dounin3-8/+8
This ensures slightly more readable debug logs on 80-character-wide terminals.
2017-09-14HTTP/2: fixed debug log about indexed headers.Maxim Dounin1-1/+1
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.
2017-09-14HTTP/2: added logging of 400 (Bad Request) reasons.Maxim Dounin1-0/+13
2017-09-12Stream: fixed logging UDP upstream timeout.Roman Arutyunyan1-1/+5
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.
2017-09-13Introduced time truncation to December 31, 9999 (ticket #1368).Maxim Dounin1-0/+10
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.
2017-09-13Fixed ngx_gmtime() on 32-bit platforms with 64-bit time_t.Maxim Dounin1-8/+10
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.
2017-09-13Fixed reference to time parsing code after 8b6fa4842133.Maxim Dounin1-1/+1
2017-09-13Style.Maxim Dounin1-2/+3
2017-08-30HTTP/2: signal 0-byte HPACK's dynamic table size.Piotr Sikora3-1/+16
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>
2017-09-11Stream: relaxed next upstream condition (ticket #1317).Roman Arutyunyan1-2/+6
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.
2017-09-11Version bump.Roman Arutyunyan1-2/+2
2017-08-22Secure link: fixed stack buffer overflow.Roman Arutyunyan1-2/+1
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.
2017-08-23Upstream: unconditional parsing of last_modified_time.Maxim Dounin1-17/+3
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.
2017-08-22SSL: fixed possible use-after-free in $ssl_server_name.Maxim Dounin1-6/+15
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.
2017-08-22SSL: the $ssl_client_escaped_cert variable (ticket #857).Maxim Dounin4-0/+40
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.
2017-08-10Range filter: changed type for total length to off_t.Maxim Dounin1-8/+9
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.
2017-08-10Restored ngx_event_aio_t layout for debug logging.Maxim Dounin1-2/+2
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.
2017-08-10Style.Maxim Dounin3-7/+7
2017-08-09Fixed calls to ngx_open_file() in certain places.Sergey Kandaurov3-3/+4
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.
2017-08-09Style.Sergey Kandaurov6-0/+7
2017-08-09Version bump.Sergey Kandaurov1-2/+2
2017-08-08Slab: fixed initialization on win32.Ruslan Ermilov3-10/+20
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.
2017-08-04Upstream: copy peer data in shared memory.Ruslan Ermilov2-16/+138
This, in addition to 1eb753aa8e5e, fixes "upstream zone" on Windows.
2017-08-04Referer: fixed $invalid_referer.Ruslan Ermilov1-14/+25
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.
2017-08-01Upstream zone: store peers->name and its data in shared memory.Ruslan Ermilov2-0/+36
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.
2017-08-01Variables: macros for null variables.Ruslan Ermilov19-17/+21
No functional changes.
2017-08-01Browser: style.Ruslan Ermilov1-24/+21
Removed custom variable type and renamed function that adds variables.
2017-07-26Cache: fixed max_size on win32.Ruslan Ermilov1-0/+1
2017-07-25SSL: fixed typo in the error message.Sergey Kandaurov1-1/+1
2017-07-21Mirror: "off" paramater of the "mirror" directive.Roman Arutyunyan1-2/+43
2017-07-20Mirror module.Roman Arutyunyan1-0/+223
2017-07-20Precontent phase.Roman Arutyunyan4-337/+414
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.
2017-07-19Upstream: keep request body file from removal if requested.Roman Arutyunyan5-1/+14
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.
2017-07-19Style.Alex Zhang1-1/+1
Signed-off-by: Alex Zhang <zchao1995@gmail.com>
2017-07-17Parenthesized ASCII-related calculations.Valentin Bartenev7-29/+29
This also fixes potential undefined behaviour in the range and slice filter modules, caused by local overflows of signed integers in expressions.
2017-07-12Style: aligned ngx_null_command.Ruslan Ermilov1-1/+1
2017-07-11Core: fixed error message on setsockopt(SO_REUSEPORT) failure.Maxim Dounin1-1/+1
The error is fatal when configuring a new socket, so the ", ignored" part is not appropriate and was removed.