summaryrefslogtreecommitdiffhomepage
path: root/src (follow)
AgeCommit message (Collapse)AuthorFilesLines
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.
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-07-11Version bump.Maxim Dounin1-2/+2
2017-07-11Range filter: avoid negative range start.Maxim Dounin1-1/+1
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.
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-07-07Variables: use ngx_http_variable_null_value where appropriate.Ruslan Ermilov1-11/+5
2017-07-04Resolver: cancelable resend timer event.Ruslan Ermilov2-0/+3
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.
2017-07-04Resolver: factored out setting a timer for resolver timeout.Sergey Kandaurov1-50/+33
No functional changes.
2017-07-04Slab: fixed small allocations on systems with large pagesize.Ruslan Ermilov1-4/+13
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.
2017-07-04Slab: style.Ruslan Ermilov1-10/+10
2017-07-04Resolver: fixed possible use-after-free while resolving SRV.Roman Arutyunyan1-19/+19
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.
2017-03-15Proxy: split configured header names and values.Piotr Sikora1-106/+59
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>
2017-07-03Version bump.Maxim Dounin1-2/+2
2017-06-27Range filter: allowed ranges on empty files (ticket #1031).Maxim Dounin1-0/+3
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.
2017-06-22Upstream: introduced ngx_http_upstream_ssl_handshake_handler().Maxim Dounin1-14/+24
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.
2017-06-14Upstream: fixed running posted requests (ticket #788).Roman Arutyunyan1-1/+6
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.
2017-06-14Resolver: added the "async" flag to resolver context.Roman Arutyunyan2-1/+7
The flag indicates that the resolve handler is called asynchronously after the resolve function ngx_resolve_name()/ngx_resolve_addr() exited.
2017-06-19Resolver: fixed allocation error handling while resolving SRV.Bart Warmerdam1-1/+3
2017-06-16Introduced ngx_rwlock_downgrade().Ruslan Ermilov2-0/+10
2017-06-16Added memory barrier semantics to ngx_rwlock_unlock().Ruslan Ermilov1-1/+1
2017-03-24Headers filter: added "add_trailer" directive.Piotr Sikora1-22/+142
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>
2017-03-24HTTP/2: added support for trailers in HTTP responses.Piotr Sikora1-14/+152
Signed-off-by: Piotr Sikora <piotrsikora@google.com>
2017-03-24Added support for trailers in HTTP responses.Piotr Sikora5-27/+157
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>
2017-06-14Gzip: fixed style in $gzip_ratio variable handler.Ruslan Ermilov1-4/+4
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.
2017-06-14Removed excessive casts for ngx_file_info().Ruslan Ermilov2-6/+2