summaryrefslogtreecommitdiffhomepage
AgeCommit message (Collapse)AuthorFilesLines
2017-10-17nginx-1.12.2-RELEASErelease-1.12.2Maxim Dounin1-0/+69
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-09-25Fixed the NGX_UNIX_ADDRSTRLEN macro.Ruslan Ermilov1-2/+3
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-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-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-08Updated PCRE used for win32 builds.Maxim Dounin1-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.
2017-07-11Core: disabled SO_REUSEPORT when testing config (ticket #1300).Maxim Dounin1-1/+1
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.
2017-05-24Fixed deferred accept with EPOLLRDHUP enabled (ticket #1278).Roman Arutyunyan1-1/+1
Previously, the read event of the accepted connection was marked ready, but not available. This made EPOLLRDHUP-related code (for example, in ngx_unix_recv()) expect more data from the socket, leading to unexpected behavior. For example, if SSL, PROXY protocol and deferred accept were enabled on a listen socket, the client connection was aborted due to unexpected return value of c->recv().
2017-04-27Added missing "fall through" comments (ticket #1259).Maxim Dounin3-0/+6
Found by gcc7 (-Wimplicit-fallthrough).
2017-10-13Version bump.Maxim Dounin1-2/+2
2017-07-11release-1.12.1 tagMaxim Dounin1-0/+1
2017-07-11nginx-1.12.1-RELEASErelease-1.12.1Maxim Dounin1-0/+20
2017-07-11Range filter: protect from total size overflows.Maxim Dounin1-0/+4
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.
2017-05-30Updated OpenSSL used for win32 builds.Maxim Dounin1-1/+1
2017-07-11Version bump.Maxim Dounin1-2/+2
2017-04-12release-1.12.0 tagMaxim Dounin1-0/+1
2017-04-12nginx-1.12.0-RELEASErelease-1.12.0Maxim Dounin1-0/+14
2017-04-12Stable branch.Maxim Dounin1-2/+2
2017-04-04release-1.11.13 tagMaxim Dounin1-0/+1
2017-04-04nginx-1.11.13-RELEASErelease-1.11.13Maxim Dounin1-0/+91
2017-03-24Upstream: allow recovery from "429 Too Many Requests" response.Piotr Sikora6-5/+16
This change adds "http_429" parameter to "proxy_next_upstream" for retrying rate-limited requests, and to "proxy_cache_use_stale" for serving stale cached responses after being rate-limited. Signed-off-by: Piotr Sikora <piotrsikora@google.com>
2017-03-24Added support for "429 Too Many Requests" response (RFC6585).Piotr Sikora3-8/+29
This change adds reason phrase in status line and pretty response body when "429" status code is used in "return", "limit_conn_status" and/or "limit_req_status" directives. Signed-off-by: Piotr Sikora <piotrsikora@google.com>
2017-04-03Fixed type.hucongcong1-2/+2
2017-03-31Slice filter: prevented slice redirection (ticket #1219).Roman Arutyunyan1-1/+11
When a slice subrequest was redirected to a new location, its context was lost. After its completion, a new slice subrequest for the same slice was created. This could lead to infinite loop. Now the slice module makes sure each slice subrequest starts output with the slice context available.
2017-03-28Slice filter: allowed at most one subrequest at a time.Roman Arutyunyan1-12/+16
Previously, if slice main request write handler was called while a slice subrequest was running, a new subrequest for the same slice was started.
2017-04-02Moved handling of wev->delayed to the connection event handler.Maxim Dounin4-78/+26
With post_action or subrequests, it is possible that the timer set for wev->delayed will expire while the active subrequest write event handler is not ready to handle this. This results in request hangs as observed with limit_rate / sendfile_max_chunk and post_action (ticket #776) or subrequests (ticket #1228). Moving the handling to the connection event handler fixes the hangs observed, and also slightly simplifies the code.
2017-04-02Perl: fixed delaying subrequests.Maxim Dounin2-6/+11
Much like in limit_req, use the wev->delayed flag to ensure proper handling and interoperability with limit_rate.
2017-04-02Limit req: fixed delaying subrequests.Maxim Dounin1-1/+4
Since limit_req uses connection's write event to delay request processing, it can conflict with timers in other subrequests. In particular, even if applied to an active subrequest, it can break things if wev->delayed is already set (due to limit_rate or sendfile_max_chunk), since after limit_req finishes the wev->delayed flag will be set and no timer will be active. Fix is to use the wev->delayed flag in limit_req as well. This ensures that wev->delayed won't be set after limit_req finishes, and also ensures that limit_req's timers will be properly handled by other subrequests if the one delayed by limit_req is not active.
2017-03-26HTTP/2: style and typos.Piotr Sikora2-7/+8
Signed-off-by: Piotr Sikora <piotrsikora@google.com>
2017-03-29HTTP/2: fixed connection finalization.Valentin Bartenev1-3/+8
All streams in connection must be finalized before the connection itself can be finalized and all related memory is freed. That's not always possible on the current event loop iteration. Thus when the last stream is finalized, it sets the special read event handler ngx_http_v2_handle_connection_handler() and posts the event. Previously, this handler didn't check the connection state and could call the regular event handler on a connection that was already in finalization stage. In the worst case that could lead to a segmentation fault, since some data structures aren't supposed to be used during connection finalization. Particularly, the waiting queue can contain already freed streams, so the WINDOW_UPDATE frame received by that moment could trigger accessing to these freed streams. Now, the connection error flag is explicitly checked in ngx_http_v2_handle_connection_handler().
2017-03-29HTTP/2: fixed stream finalization.Valentin Bartenev1-0/+3
In order to finalize stream the error flag is set on fake connection and either "write" or "read" event handler is called. The read events of fake connections are always ready, but it's not the case with the write events. When the ready flag isn't set, the error flag can be not checked in some cases and as a result stream isn't finalized. Now the ready flag is explicilty set on write events for proper finalization in all cases.
2017-03-26HTTP/2: emit PROTOCOL_ERROR on padding errors.Piotr Sikora1-2/+4
Signed-off-by: Piotr Sikora <piotrsikora@google.com>
2017-03-26HTTP/2: fix flow control with padded DATA frames.Piotr Sikora1-10/+12
Previously, flow control didn't account for padding in DATA frames, which meant that its view of the world could drift from peer's view by up to 256 bytes per received padded DATA frame, which could lead to a deadlock. Signed-off-by: Piotr Sikora <piotrsikora@google.com>
2017-03-26HTTP/2: fix $body_bytes_sent variable.Piotr Sikora1-0/+3
Previously, its value included payloads and frame headers of HEADERS and CONTINUATION frames. Signed-off-by: Piotr Sikora <piotrsikora@google.com>
2017-03-26HTTP/2: fix $bytes_sent variable.Piotr Sikora1-0/+2
Previously, its value accounted for payloads of HEADERS, CONTINUATION and DATA frames, as well as frame headers of HEADERS and DATA frames, but it didn't account for frame headers of CONTINUATION frames. Signed-off-by: Piotr Sikora <piotrsikora@google.com>
2017-03-28Copy filter: wake up subrequests after aio operations.Maxim Dounin1-2/+30
Previously, connection write handler was called, resulting in wake up of the active subrequest. This change makes it possible to read data in non-active subrequests as well. For example, this allows SSI to process instructions in non-active subrequests earlier and start additional subrequests if needed, reducing overall response time.
2017-03-28Threads: fixed request hang with aio_write and subrequests.Maxim Dounin1-2/+12
If the subrequest is already finalized, the handler set with aio_write may still be used by sendfile in threads when using range requests (see also e4c1f5b32868, and the original note in 9fd738b85fad). Calling already finalized subrequest's r->write_event_handler in practice results in request hang in some cases. Fix is to trigger connection event handler if the subrequest was already finalized.
2017-03-28Simplified and improved sendfile() code on Linux.Maxim Dounin1-67/+47
The ngx_linux_sendfile() function is now used for both normal sendfile() and sendfile in threads. The ngx_linux_sendfile_thread() function was modified to use the same interface as ngx_linux_sendfile(), and is simply called from ngx_linux_sendfile() when threads are enabled. Special return code NGX_DONE is used to indicate that a thread task was posted and no further actions are needed. If number of bytes sent is less that what we were sending, we now always retry sending. This is needed for sendfile() in threads as the number of bytes we are sending might have been changed since the thread task was posted. And this is also needed for Linux 4.3+, as sendfile() might be interrupted at any time and provides no indication if it was interrupted or not (ticket #1174).
2017-03-28Fixed ngx_open_cached_file() error handling.Sergey Kandaurov5-3/+24
If of.err is 0, it means that there was a memory allocation error and no further logging and/or processing is needed. The of.failed string can be only accessed if of.err is not 0.
2017-03-28Core: set nginx_shared_zone name via ngx_str_set().Ruslan Ermilov1-2/+1
2017-03-28Use ngx_array_init() to initialize arrays.Ruslan Ermilov1-19/+15
2017-03-28Version bump.Ruslan Ermilov1-2/+2
2017-03-24release-1.11.12 tagMaxim Dounin1-0/+1
2017-03-24nginx-1.11.12-RELEASErelease-1.11.12Maxim Dounin1-0/+16
2017-03-24Fixed CPU hog while freeing hc->busy after e662cbf1b932 (1.11.11).Maxim Dounin1-0/+1
Reported by Richard Stanway, http://mailman.nginx.org/pipermail/nginx/2017-March/053296.html.