aboutsummaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAge
* Proxy: escape explicit space in URI in default cache key.Roman Arutyunyan2017-11-20
| | | | | | | | | | | | If the flag space_in_uri is set, the URI in HTTP upstream request is escaped to convert space to %20. However this flag is not checked while creating the default cache key. This leads to different cache keys for requests '/foo bar' and '/foo%20bar', while the upstream requests are identical. Additionally, the change fixes background cache updates when the client URI contains unescaped space. Default cache key in a subrequest is always based on escaped URI, while the main request may not escape it. As a result, background cache update subrequest may update a different cache entry.
* Inherit valid_unparsed_uri in cloned subrequests (ticket #1430).Roman Arutyunyan2017-11-20
| | | | | | | | | | | | | Inheriting this flag will make the cloned subrequest behave consistently with the parent. Specifically, the upstream HTTP request and cache key created by the proxy module may depend directly on unparsed_uri if valid_unparsed_uri flag is set. Previously, the flag was zero for cloned requests, which could make background update proxy a request different than its parent and cache the result with a different key. For example, if client URI contained the escaped slash character %2F, it was used as is by the proxy module in the main request, but was unescaped in the subrequests. Similar problems exist in the slice module.
* Proxy: simplified conditions of using unparsed uri.Roman Arutyunyan2017-11-20
| | | | | | Previously, the unparsed uri was explicitly allowed to be used only by the main request. However the valid_unparsed_uri flag is nonzero only in the main request, which makes the main request check pointless.
* Upstream: flush low-level buffers on write retry.Patryk Lesiewicz2017-12-01
| | | | | | | | | | | | | If the data to write is bigger than what the socket can send, and the reminder is smaller than NGX_SSL_BUFSIZE, then SSL_write() fails with SSL_ERROR_WANT_WRITE. The reminder of payload however is successfully copied to the low-level buffer and all the output chain buffers are flushed. This means that retry logic doesn't work because ngx_http_upstream_process_non_buffered_request() checks only if there's anything in the output chain buffers and ignores the fact that something may be buffered in low-level parts of the stack. Signed-off-by: Patryk Lesiewicz <patryk@google.com>
* Upstream keepalive: clean read delayed flag in stored connections.Roman Arutyunyan2017-11-28
| | | | | | | | | | | | If a connection with the read delayed flag set was stored in the keepalive cache, and after picking it from the cache a read timer was set on that connection, this timer was considered a delay timer rather than a socket read event timer as expected. The latter timeout is usually much longer than the former, which caused a significant delay in request processing. The issue manifested itself with proxy_limit_rate and upstream keepalive enabled and exists since 973ee2276300 (1.7.7) when proxy_limit_rate was introduced.
* Autoindex: discard request body (ticket #1439).Maxim Dounin2017-12-04
|
* Removed unused FreeBSD-specific definitions in ngx_posix_config.h.Sergey Kandaurov2017-11-28
|
* Fixed "changing binary" when reaper is not init.Ruslan Ermilov2017-11-28
| | | | | | | | | On some systems, it's possible that reaper of orphaned processes is set to something other than "init" process. On such systems, the changing binary procedure did not work. The fix is to check if PPID has changed, instead of assuming it's always 1 for orphaned processes.
* Version bump.Maxim Dounin2017-11-23
|
* Fixed worker_shutdown_timeout in various cases.Maxim Dounin2017-11-20
| | | | | | | | | | | | | | | | | | The ngx_http_upstream_process_upgraded() did not handle c->close request, and upgraded connections do not use the write filter. As a result, worker_shutdown_timeout did not affect upgraded connections (ticket #1419). Fix is to handle c->close in the ngx_http_request_handler() function, thus covering most of the possible cases in http handling. Additionally, mail proxying did not handle neither c->close nor c->error, and thus worker_shutdown_timeout did not work for mail connections. Fix is to add c->close handling to ngx_mail_proxy_handler(). Also, added explicit handling of c->close to stream proxy, ngx_stream_proxy_process_connection(). This improves worker_shutdown_timeout handling in stream, it will no longer wait for some data being transferred in a connection before closing it, and will also provide appropriate logging at the "info" level.
* Gzip: support for a zlib variant from Intel.Maxim Dounin2017-11-18
| | | | | | | | | | | | | | | | | | | | | | A zlib variant from Intel as available from https://github.com/jtkukunas/zlib uses 64K hash instead of scaling it from the specified memory level, and also uses 16-byte padding in one of the window-sized memory buffers, and can force window bits to 13 if compression level is set to 1 and appropriate compile options are used. As a result, nginx complained with "gzip filter failed to use preallocated memory" alerts. This change improves deflate_state allocation detection by testing that items is 1 (deflate_state is the only allocation where items is 1). Additionally, on first failure to use preallocated memory we now assume that we are working with the Intel's modified zlib, and switch to using appropriate preallocations. If this does not help, we complain with the usual alerts. Previous version of this patch was published at http://mailman.nginx.org/pipermail/nginx/2014-July/044568.html. The zlib variant in question is used by default in ClearLinux from Intel, see http://mailman.nginx.org/pipermail/nginx-ru/2017-October/060421.html, http://mailman.nginx.org/pipermail/nginx-ru/2017-November/060544.html.
* Xslt: fixed parameters parsing (ticket #1416).Ruslan Ermilov2017-11-16
| | | | | If parameters were specified in xslt_stylesheet without variables, any request except the first would cause an internal server error.
* SSI: fixed type.hucongcong2017-10-27
|
* FastCGI: adjust buffer position when parsing incomplete records.Maxim Dounin2017-11-09
| | | | | | | | | | | | | | | | | | Previously, nginx failed to move buffer position when parsing an incomplete record header, and due to this wasn't be able to continue parsing once remaining bytes of the record header were received. This can affect response header parsing, potentially generating spurious errors like "upstream sent unexpected FastCGI request id high byte: 1 while reading response header from upstream". While this is very unlikely, since usually record headers are written in a single buffer, this still can happen in real life, for example, if a record header will be split across two TCP packets and the second packet will be delayed. This does not affect non-buffered response body proxying, due to "buf->pos = buf->last;" at the start of the ngx_http_fastcgi_non_buffered_filter() function. Also this does not affect buffered response body proxying, as each input buffer is only passed to the filter once.
* Core: free shared memory zones only after reconfiguration.Maxim Dounin2017-10-17
| | | | | | | | | | | This is what usually happens for zones no longer used in the new configuration, but zones where size or tag were changed were freed when creating new memory zones. If reconfiguration failed (for example, due to a conflicting listening socket), this resulted in a segmentation fault in the master process. Reported by Zhihua Cao, http://mailman.nginx.org/pipermail/nginx-devel/2017-October/010536.html.
* Postpone filter: handled ngx_http_postpone_filter_add() failures.Sergey Kandaurov2017-10-16
| | | | | In particular, if ngx_http_postpone_filter_add() fails in ngx_chain_add_copy(), the output chain of the postponed request was left in an invalid state.
* Fixed type of ngx_conf_t.handler_conf.Ruslan Ermilov2017-10-13
| | | | | The type should have been changed in c9b243802a17 along with changing ngx_conf_handler_pt.
* SSL: include <openssl/hmac.h>.Alessandro Ghedini2017-10-11
| | | | | | | | This header carries the definition of HMAC_Init_ex(). In OpenSSL this header is included by <openssl/ssl.h>, but it's not so in BoringSSL. It's probably a good idea to explicitly include this header anyway, regardless of whether it's included by other headers or not.
* Upstream: disabled upgrading in subrequests.Roman Arutyunyan2017-10-11
| | | | | | | Upgrading an upstream connection is usually followed by reading from the client which a subrequest is not allowed to do. Moreover, accessing the header_in request field while processing upgraded connection ends up with a null pointer dereference since the header_in buffer is only created for the the main request.
* Upstream: fixed $upstream_status when upstream returns 503/504.Ruslan Ermilov2017-10-11
| | | | | | If proxy_next_upstream includes http_503/http_504, and upstream returns 503/504, $upstream_status converted this to 502 for any values except the last one.
* Version bump.Ruslan Ermilov2017-10-11
|
* Upstream: fixed error handling of stale and revalidated cache send.Sergey Kandaurov2017-10-10
| | | | | | | | | | The NGX_DONE value returned from ngx_http_upstream_cache_send() indicates that upstream was already finalized in ngx_http_upstream_process_headers(). It was treated as a generic error which resulted in duplicate finalization. Handled NGX_HTTP_UPSTREAM_INVALID_HEADER from ngx_http_upstream_cache_send(). Previously, it could return within ngx_http_upstream_finalize_request(), and since it's below NGX_HTTP_SPECIAL_RESPONSE, a client connection could stuck.
* Upstream: even better handling of invalid headers in cache files.Maxim Dounin2017-10-09
| | | | | | | | | When parsing of headers in a cache file fails, already parsed headers need to be cleared, and protocol state needs to be reinitialized. To do so, u->request_sent is now set to ensure ngx_http_upstream_reinit() will be called. This change complements improvements in 46ddff109e72.
* Upstream hash: reordered peer checks.Maxim Dounin2017-10-05
| | | | | | This slightly reduces cost of selecting a peer if all or almost all peers failed, see ticket #1030. There should be no measureable difference with other workloads.
* Upstream hash: limited number of tries in consistent case.Maxim Dounin2017-10-05
| | | | | | | | 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.
* Fixed build without IPv6, broken by 874171c3c71a.Maxim Dounin2017-10-05
|
* Fixed handling of unix sockets in $binary_remote_addr.Maxim Dounin2017-10-04
| | | | | | | | | | | | | | 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.
* Fixed handling of non-null-terminated unix sockets.Maxim Dounin2017-10-04
| | | | | | | | | | | | | 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.
* Fixed buffer overread with unix sockets after accept().Maxim Dounin2017-10-04
| | | | | | | | | | | | | | | | | 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).
* HTTP/2: enforce writing the sync request body buffer to file.Valentin Bartenev2017-10-04
| | | | | | | | | | | | | | | | | 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.
* Cache: fixed caching of intercepted errors (ticket #1382).Maxim Dounin2017-10-03
| | | | | | | | 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.
* Upstream: better handling of invalid headers in cache files.Maxim Dounin2017-10-02
| | | | | | | | | | | | | | | | | | 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.
* Fixed the NGX_UNIX_ADDRSTRLEN macro.Ruslan Ermilov2017-09-25
|
* Modules compatibility: down flag promoted to a bitmask.Ruslan Ermilov2017-09-22
| | | | | | 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.
* Style.Ruslan Ermilov2017-09-22
|
* Do not use the obsolete NGX_SOCKADDRLEN macro.Ruslan Ermilov2017-09-22
| | | | | The change in ac120e797d28 re-used the macro which was made obsolete in adf25b8d0431.
* Removed more remnants of the old pthread implementation.Ruslan Ermilov2017-09-18
| | | | After e284f3ff6831, ngx_crypt() can no longer return NGX_AGAIN.
* HTTP/2: shortened some debug log messages.Maxim Dounin2017-09-14
| | | | | This ensures slightly more readable debug logs on 80-character-wide terminals.
* HTTP/2: fixed debug log about indexed headers.Maxim Dounin2017-09-14
| | | | | | | | 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.
* HTTP/2: added logging of 400 (Bad Request) reasons.Maxim Dounin2017-09-14
|
* Stream: fixed logging UDP upstream timeout.Roman Arutyunyan2017-09-12
| | | | | | | | | 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.
* Introduced time truncation to December 31, 9999 (ticket #1368).Maxim Dounin2017-09-13
| | | | | | | | | | | | 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.
* Fixed ngx_gmtime() on 32-bit platforms with 64-bit time_t.Maxim Dounin2017-09-13
| | | | | | | | | | | 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.
* Fixed reference to time parsing code after 8b6fa4842133.Maxim Dounin2017-09-13
|
* Style.Maxim Dounin2017-09-13
|
* HTTP/2: signal 0-byte HPACK's dynamic table size.Piotr Sikora2017-08-30
| | | | | | | | | | | | | | 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>
* Stream: relaxed next upstream condition (ticket #1317).Roman Arutyunyan2017-09-11
| | | | | | | | | | | | | | | | | 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.
* Version bump.Roman Arutyunyan2017-09-11
|
* Secure link: fixed stack buffer overflow.Roman Arutyunyan2017-08-22
| | | | | | | | | | | 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.
* Upstream: unconditional parsing of last_modified_time.Maxim Dounin2017-08-23
| | | | | | | | | 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.