Commit Graph

4194 Commits

Author SHA1 Message Date
Maxim Dounin
07c3c53e00 Merge of r5083: fixed potential segfault in keepalive handler.
Fixed potential segfault in ngx_http_keepalive_handler().

In case of error in the read event handling we close a connection
by calling ngx_http_close_connection(), that also destroys connection
pool. Thereafter, an attempt to free a buffer (added in r4892) that
was allocated from the pool could cause SIGSEGV and is meaningless
as well (the buffer already freed with the pool).
2013-03-29 17:19:11 +00:00
Maxim Dounin
e4010d888f Merge of r5082: SSL: retry "sess_id" and "id" allocations.
SSL: retry "sess_id" and "id" allocations.

In case of fully populated SSL session cache with no memory left for
new allocations, ngx_ssl_new_session() will try to expire the oldest
non-expired session and retry, but only in case when slab allocation
fails for "cached_sess", not when slab allocation fails for either
"sess_id" or "id", which can happen for number of reasons and results
in new session not being cached.

Patch fixes this by adding retry logic to "sess_id" & "id" allocations.

Patch by Piotr Sikora.
2013-03-29 17:17:45 +00:00
Maxim Dounin
0e7eb773de Merge of r5078: removed zero termination of shm zone names.
It was added in r2717 and no longer needed since r2721,
where the termination was added to ngx_shm_alloc() and
ngx_init_zone_pool().  Since then it only corrupted error
messages about invalid zones.
2013-03-29 17:15:34 +00:00
Maxim Dounin
f3dcfd8c20 Merge of r5071: rebuild perl module on headers change.
Configure: rebuild perl module nginx.so if headers are changed.

Note: the "-p" argument of cp(1) dropped intentionally, to force nginx.so
rebuild.  It is considered too boring to properly list all dependencies
in Makefile.PL.
2013-03-29 17:13:45 +00:00
Maxim Dounin
b02568884a Merge of r5070: fixed false memset warning on Linux.
Fixed false memset warning on Linux with -O3 (ticket #275).

Prodded by John Leach.
2013-03-29 17:11:09 +00:00
Maxim Dounin
5c09eb1bd4 Version bump. 2013-03-29 15:29:29 +00:00
Maxim Dounin
abb71819fb release-1.2.7 tag 2013-02-12 13:40:46 +00:00
Maxim Dounin
006c286862 nginx-1.2.7-RELEASE 2013-02-12 13:40:16 +00:00
Maxim Dounin
07b961d76d Merge of r5005, r5031, r5066: PCRE and OpenSSL for win32 builds. 2013-02-11 23:57:13 +00:00
Maxim Dounin
7eafb7761e Merge of r5027, r5028, r5029: fastcgi_keep_conn fixes.
*) FastCGI: fixed wrong connection close with fastcgi_keep_conn.

   With fastcgi_keep_conn it was possible that connection was closed after
   FCGI_STDERR record with zero padding and without any further data read
   yet.  This happended as f->state was set to ngx_http_fastcgi_st_padding
   and then "break" happened, resulting in p->length being set to
   f->padding, i.e. 0 (which in turn resulted in connection close).

   Fix is to make sure we continue the loop after f->state is set.

*) FastCGI: unconditional state transitions.  Checks for f->padding
   before state transitions make code hard to follow, remove them and
   make sure we always do another loop iteration after f->state is
   set to ngx_http_fastcgi_st_padding.

*) FastCGI: proper handling of split fastcgi end request.  If fastcgi
   end request record was split between several network packets, with
   fastcgi_keep_conn it was possible that connection was saved in
   incorrect state (e.g. with padding bytes not yet read).
2013-02-11 16:11:14 +00:00
Maxim Dounin
61312182f5 Merge of r5018: secure link: fixed configuration inheritance.
The "secure_link_secret" directive was always inherited from the outer
configuration level even when "secure_link" and "secure_link_md5" were
specified on the inner level.
2013-02-11 16:09:35 +00:00
Maxim Dounin
c9e51955ea Merge of r5017: fixed null dereference with resolver and poll.
Events: fixed null pointer dereference with resolver and poll.

A POLLERR signalled by poll() without POLLIN/POLLOUT, as seen on
Linux, would generate both read and write events, but there's no
write event handler for resolver events.  A fix is to only call
event handler of an active event.
2013-02-11 16:06:39 +00:00
Maxim Dounin
431111e8d8 Merge of r5014, r5015, r5016, r5030: geoip ipv6 support.
*) Configure: fixed style of include directories.

*) Configure: fixed GeoIP library detection.

*) GeoIP: IPv6 support.  When using IPv6 databases, IPv4 addresses are
   looked up as IPv4-mapped IPv6 addresses.  Mostly based on a patch
   by Gregor Kališnik (ticket #250).

*) GeoIP: removed pseudo-support of "proxy" and "netspeed" databases.
2013-02-11 15:34:30 +00:00
Maxim Dounin
e8ef9ea62b Merge of r5013: proxy: fixed proxy_method to always add space.
Before the patch if proxy_method was specified at http{} level the code
to add trailing space wasn't executed, resulting in incorrect requests
to upstream.
2013-02-11 15:31:10 +00:00
Maxim Dounin
ad45350460 Merge of r5012: configure: removed redundant variable assignment. 2013-02-11 15:28:50 +00:00
Maxim Dounin
a901bd695d Merge of r5004, r5019-r5025: ssl fixes.
*) SSL: speedup loading of configs with many ssl servers.  The patch
   saves one EC_KEY_generate_key() call per server{} block by informing
   OpenSSL about SSL_OP_SINGLE_ECDH_USE we are going to use before
   the SSL_CTX_set_tmp_ecdh() call.

   For a configuration file with 10k simple server{} blocks with SSL
   enabled this change reduces startup time from 18s to 5s on a slow
   test box here.

*) SSL: removed conditions that always hold true.

*) SSL: resetting of flush flag after the data was written.  There is
   no need to flush next chunk of data if it does not contain a buffer
   with the flush or last_buf flags set.

*) SSL: preservation of flush flag for buffered data.  Previously,
   if SSL buffer was not sent we lost information that the data
   must be flushed.

*) SSL: calculation of buffer size moved closer to its usage.
   No functional changes.

*) SSL: avoid calling SSL_write() with zero data size.  According to
   documentation, calling SSL_write() with num=0 bytes to be sent
   results in undefined behavior.

   We don't currently call ngx_ssl_send_chain() with empty chain and
   buffer.  This check handles the case of a chain with total data size
   that is a multiple of NGX_SSL_BUFSIZE, and with the special buffer
   at the end.

   In practice such cases resulted in premature connection close and
   critical error "SSL_write() failed (SSL:)" in the error log.

*) SSL: take into account data in the buffer while limiting output.
   In some rare cases this can result in a more smooth sending rate.

*) SSL: fixed ngx_ssl_handshake() with level-triggered event methods.
   Missing calls to ngx_handle_write_event() and ngx_handle_read_event()
   resulted in a CPU hog during SSL handshake if an level-triggered event
   method (e.g. select) was used.
2013-02-11 15:12:06 +00:00
Maxim Dounin
7ce291435a Merge of r5001: year 2013. 2013-02-11 15:00:43 +00:00
Maxim Dounin
635dae7cad Merge of r4999, r5003: detect duplicate "events" and "keepalive".
*) Upstream keepalive: detect duplicate "keepalive" directive.  A
   failure to detect duplicate "keepalive" directive resulted in
   stack exhaustion.

*) Events: added check for duplicate "events" directive.
2013-02-11 14:58:25 +00:00
Maxim Dounin
ff145c0574 Merge of r4992: off-by-one with 32/64 upstream backup servers.
Fixed off-by-one during upstream state resetting when switching to
backup servers if there were exactly 32 (64 on 64-bit platforms)
backup servers configured.

Based on patch by Thomas Chen (ticket #257).
2013-02-11 14:56:14 +00:00
Maxim Dounin
6b070a4d21 Merge of r4991: fixed proxied HEAD requests with gzip enabled.
Fixed HEAD requests handling when proxying is used (ticket #261).
2013-02-11 14:39:49 +00:00
Maxim Dounin
eef05677eb Merge of r4985, r4986, r4987, r4988, r4989, r5002: access_log gzip.
*) Access log: fixed redundant buffer reallocation.  Previously a new
   buffer was allocated for every "access_log" directive with the same
   file path and "buffer=" parameters, while only one buffer per file
   is used.

*) Reopening log files code moved to a separate function.  The code
   refactored in a way to call custom handler that can do appropriate
   cleanup work (if any), like flushing buffers, finishing compress
   streams, finalizing connections to log daemon, etc..

*) Access log: the "flush" parameter of the "access_log" directive.

*) Configure: added the NGX_ZLIB define.  This was introduced for
   conditional compilation of the code that requires the zlib library.

*) Access log: the "gzip" parameter of the "access_log" directive.
   Note: this requires zlib version 1.2.0.4 or above to work.

*) The data pointer in ngx_open_file_t objects must be initialized.
   Uninitialized pointer may result in arbitrary segfaults if access_log
   is used without buffer and without variables in file path.
   Patch by Tatsuhiko Kubo (ticket #268).
2013-02-11 14:34:00 +00:00
Maxim Dounin
8fea197932 Merge of r4979, r4982: image filter configuration inheritance.
*) Image filter: configuration inheritance fixes.

   The image_filter_jpeg_quality, image_filter_sharpen and
   "image_filter rotate" were inherited incorrectly if a directive
   with variables was defined, and then redefined to a literal value,
   i.e. in configurations like

       image_filter_jpeg_quality $arg_q;

       location / {
           image_filter_jpeg_quality 50;
       }

   Patch by Ian Babrou, with minor changes.

*) Image filter: fixed image_filter rotate inheritance.

   Configurations like

       location /i/ {
           image_filter resize 200 200;
           image_filter rotate 180;

           location /i/foo/ {
               image_filter resize 200 200;
           }
      }

   resulted in rotation incorrectly applied in the location /i/foo,
   without any way to clear it.  Fix is to handle conf->angle/conf->acv
   consistently with other filter variables and do not try to inherit
   them if there are transformations defined for current location.
2013-02-11 13:59:08 +00:00
Maxim Dounin
fba705e4f5 Merge of r4976: let add_header affect 201 responses (ticket #125). 2013-02-11 13:52:13 +00:00
Maxim Dounin
5b59ed2e0a Merge of r4983: crypt_r() error handling fixed.
The crypt_r() function returns NULL on errors, check it explicitly instead
of assuming errno will remain 0 if there are no errors (per POSIX, the
setting of errno after a successful call to a function is unspecified
unless the description of that function specifies that errno shall not
be modified).

Additionally, dropped unneeded ngx_set_errno(0) and fixed error handling
of memory allocation after normal crypt(), which was inapropriate and
resulted in null pointer dereference on allocation failures.
2013-02-11 12:37:06 +00:00
Maxim Dounin
bbbadc2be2 Merge of r4974: avoid sending "100 Continue" on 413.
Avoid sending "100 Continue" on 413 Request Entity Too Large.

Patch by Igor Sysoev.
2013-02-11 12:35:49 +00:00
Maxim Dounin
5667debba4 Merge of r4993, r4994, r4997, r5000: geo ipv6 support.
*) Geo: IPv6 support.  The "ranges" mode is still limited to IPv4 only.

*) Geo: properly initialize ngx_cidr_t when dealing with "default".

*) Geo: made "default" affect both IPv4 and IPv6 when using prefixes.
   Previously, "default" was equivalent to specifying 0.0.0.0/0, now
   it's equivalent to specifying both 0.0.0.0/0 and ::/0 (if support
   for IPv6 is enabled) with the same value.

*) Geo: improved code readability.
2013-02-11 12:31:43 +00:00
Maxim Dounin
20951d0eae Merge of r4968, r4969, r4977, r4980, r4981, r4990: geo fixes.
*) Geo: improved ngx_http_geo_block() code readability.

*) Geo: fixed the "ranges" without ranges case.  The following
   configuration returned an empty value for $geo:

       geo $geo {
           ranges;
           default default;
       }

*) Fixed return type of internal function that allocates radix tree nodes.

*) There's no need to normalize address returned by ngx_ptocidr().

*) Geo: ensure that default entry is always present.  If 0.0.0.0/32 entry
   was present and there was no explicit "default", we failed to add an
   empty string as a default value.

*) Trailing whitespace fix.
2013-02-11 12:26:33 +00:00
Maxim Dounin
b217a2a467 Merge of r4967: ngx_write_fd() and ngx_read_fd() errors handling.
The ngx_write_fd() and ngx_read_fd() functions return -1 in case of error,
so the incorrect comparison with NGX_FILE_ERROR (which is 0 on windows
platforms) might result in inaccurate error message in the error log.

Also the ngx_errno global variable is being set only if the returned value
is -1.
2013-02-10 03:55:18 +00:00
Maxim Dounin
ad72db49c0 Merge of r4966: gzip: fixed zlib memLevel adjusting.
An incorrect memLevel (lower than 1) might be passed to deflateInit2() if the
"gzip_hash" directive is set to a value less than the value of "gzip_window"
directive. This resulted in "deflateInit2() failed: -2" alert and an empty
reply.
2013-02-10 03:52:26 +00:00
Maxim Dounin
244b6659ec Merge of r4965: upstream: fixed SIGSEGV with the "if" directive.
Configuration like

    location / {
        set $true 1;

        if ($true) {
            proxy_pass http://backend;
        }

        if ($true) {
            # nothing
        }
    }

resulted in segmentation fault due to NULL pointer dereference as the
upstream configuration wasn't initialized in an implicit location created
by the last if(), but the r->content_handler was set due to first if().

Instead of committing a suicide by dereferencing a NULL pointer, return
500 (Internal Server Error) in such cases, i.e. if uscf is NULL.  Better
fix would be to avoid such cases by fixing the "if" directive handling,
but it's out of scope of this patch.

Prodded by Piotr Sikora.
2013-02-10 03:27:15 +00:00
Maxim Dounin
1e0ed6da52 Merge of r4963: proxy: better error message about unexpected data.
Requested by Igor Sysoev.
2013-02-10 03:22:58 +00:00
Maxim Dounin
4b78ff952f Merge of r4962: limit_rate fix.
Limit rate: fixed integer overflow in limit calculation (ticket #256).

Patch by Alexey Antropov.
2013-02-10 03:20:00 +00:00
Maxim Dounin
a2107a6705 Merge of r4961: configure: better check for PCRE JIT.
On Mac OS X system toolchain by default prefers include files
from /usr/local/include, but libraries from /usr/lib.  This might result in
various problems, in particular the one outlined below.

If the PCRE library is installed into /usr/local/, this results in pcre.h
being used from /usr/local/include (with PCRE_CONFIG_JIT defined), but
libpcre from /usr/lib (as shipped with the OS, without pcre_free_study()
symbol).  As a result build fails as we use pcre_free_study() function
if we try to compile with PCRE JIT support.

Obvious workaround to the root cause is to ask compiler to prefer
library from /usr/local/lib via ./configure --with-ld-opt="-L/usr/local/lib".
On the other hand, in any case it would be good to check if the function
we are going to use is available, hence the change.

See thread here for details:
http://mailman.nginx.org/pipermail/nginx-devel/2012-December/003074.html

Prodded by Piotr Sikora.
2013-02-10 03:18:08 +00:00
Maxim Dounin
8967b7e032 Merge of r4948, r4949, r4964, r4973, r5011: variables.
*) Allow the complex value to be defined as an empty string.
   This makes conversion from strings to complex values possible
   without the loss of functionality.

*) The "auth_basic" directive gained support of variables.

*) Fixed variable syntax checking in "set", "geo", "limit_conn_zone",
   and "perl_set" directives.

*) Added checks that disallow adding a variable with an empty name.
   Added variable name syntax checks to "geo" and "map" directives.

*) Variables $pipe, $request_length, $time_iso8601, and $time_local.
   Log module counterparts are preserved for efficiency.
   Based on patch by Kiril Kalchev.
2013-02-10 03:08:42 +00:00
Maxim Dounin
374b73c43c Merge of r4947: xslt: prevented infinite loop.
If XSLT transformation failed and error 500 was handled in the same
location, an infinite loop occured that exhausted the stack.
2013-02-10 03:00:55 +00:00
Maxim Dounin
deee4cafa0 Merge of r4946, r4978: perl.
*) Fixed build with embedded perl in certain setups (ticket #48).

*) Brought the link to ngx_http_perl_module documentation up to date.
2013-02-10 02:58:03 +00:00
Maxim Dounin
dcec6574b8 Merge of r4945, r4984: ngx_inet.[ch] minor fixes.
*) Fixed the NGX_SOCKADDR_STRLEN macro definition.
   The ngx_sock_ntop() function, when told to print both address and port,
   prints IPv6 address in square brackets, followed by colon and port.

*) Properly initialize "struct in6_addr" with zeroes.
2013-02-10 02:56:03 +00:00
Maxim Dounin
4f535b103e Merge of r4944: removed GLOB_NOSORT glob option.
This will result in alphabetical sorting of included files if
the "include" directive with wildcards is used.

Note that the behaviour is now different from that on Windows, where
alphabetical sorting is not guaranteed for FindFirsFile()/FindNextFile()
(used to be alphabetical on NTFS, but not on FAT).

Approved by Igor Sysoev, prodded by many.
2013-02-09 21:27:37 +00:00
Maxim Dounin
5abb6ff1f0 Version bump. 2013-02-09 21:07:06 +00:00
Maxim Dounin
4dcc362967 release-1.2.6 tag 2012-12-11 14:26:07 +00:00
Maxim Dounin
33e5b473af nginx-1.2.6-RELEASE 2012-12-11 14:24:23 +00:00
Maxim Dounin
663e14e10d Merge of r4921, r4922, r4923, r4924, r4925: request body fixes.
*) Request body: fixed "501 Not Implemented" error handling.

   It is not about "Method" but a generic message, and is expected to be used
   e.g. if specified Transfer-Encoding is not supported.  Fixed message to
   match RFC 2616.

   Additionally, disable keepalive on such errors as we won't be able to read
   request body correctly if we don't understand Transfer-Encoding used.

*) Request body: $request_body variable generalization.

   The $request_body variable was assuming there can't be more than two
   buffers.  While this is currently true due to request body reading
   implementation details, this is not a good thing to depend on and may
   change in the future.

*) Request body: code duplication reduced, no functional changes.

   The r->request_body_in_file_only with empty body case is now handled in
   ngx_http_write_request_body().

*) Request body: fixed socket leak on errors.

   The r->main->count reference counter was always incremented in
   ngx_http_read_client_request_body(), while it is only needs to be
   incremented on positive returns.

*) Request body: properly handle events while discarding body.

   An attempt to call ngx_handle_read_event() before actually reading
   data from a socket might result in read event being disabled, which is
   wrong.  Catched by body.t test on Solaris.
2012-12-11 13:18:50 +00:00
Maxim Dounin
f45e938b89 Merge of r4933, r4933: shared memory fixes.
*) Fixed location of debug message in ngx_shmtx_lock().

*) Core: don't reuse shared memory zone that changed ownership (ticket #210).

   nginx doesn't allow the same shared memory zone to be used for different
   purposes, but failed to check this on reconfiguration.  If a shared memory
   zone was used for another purpose in the new configuration, nginx attempted
   to reuse it and crashed.
2012-12-10 18:17:32 +00:00
Maxim Dounin
59833d5450 Merge of r4920, r4939: ngx_write_chain_to_file() fixes.
*) Core: added debug logging of writev() in ngx_write_chain_to_file().

*) Core: fixed ngx_write_chain_to_file() with IOV_MAX reached.

   Catched by dav_chunked.t on Solaris.  In released versions this might
   potentially result in corruption of complex protocol responses if they
   were written to disk and there were more distinct buffers than IOV_MAX
   in a single write.
2012-12-10 18:04:54 +00:00
Maxim Dounin
c460629181 Merge of r4919: fixed segfault on PUT in dav module.
Dav: fixed segfault on PUT if body was already read (ticket #238).

If request body reading happens with different options it's possible
that there will be no r->request_body->temp_file available (or even
no r->request_body available if body was discarded).  Return internal
server error in this case instead of committing suicide by dereferencing
a null pointer.
2012-12-10 17:51:10 +00:00
Maxim Dounin
e3cf44789f Merge of r4918: cache manager startup with many listen sockets.
Fixed failure to start cache manager and cache loader processes
if there were more than 512 listening sockets in configuration.
2012-12-10 17:46:51 +00:00
Maxim Dounin
72bba4144b Merge of r4915, r4916, r4917: upstream minor fixes.
*) Upstream: honor the "down" flag for a single server.

   If an upstream block was defined with the only server marked as
   "down", e.g.

       upstream u {
           server 127.0.0.1:8080 down;
       }

   an attempt was made to contact the server despite the "down" flag.
   It is believed that immediate 502 response is better in such a
   case, and it's also consistent with what is currently done in case
   of multiple servers all marked as "down".

*) Upstream: better detection of connect() failures with kqueue.

   Pending EOF might be reported on both read and write events, whichever
   comes first, so check both of them.

   Patch by Yichun Zhang (agentzh), slightly modified.
2012-12-10 16:35:32 +00:00
Maxim Dounin
18590cd21e Merge of r4914: variables $request_time and $msec.
Log module counterparts are preserved for efficiency.
2012-12-10 16:03:56 +00:00
Maxim Dounin
50832b0177 Merge of r4913: fixed CPU affinity on respawn of dead workers.
Worker processes are now made aware of their sequential number needed
to select CPU affinity mask.  This replaces a workaround from r4865.
2012-12-10 16:00:55 +00:00
Maxim Dounin
2948d7cfc2 Version bump. 2012-12-10 15:43:41 +00:00