]> git.kaiwu.me - nginx.git/commitdiff
Copy regex unnamed captures to cloned subrequests.
authorRoman Arutyunyan <arut@nginx.com>
Tue, 11 Dec 2018 10:09:00 +0000 (13:09 +0300)
committerRoman Arutyunyan <arut@nginx.com>
Tue, 11 Dec 2018 10:09:00 +0000 (13:09 +0300)
Previously, unnamed regex captures matched in the parent request, were not
available in a cloned subrequest.  Now 3 fields related to unnamed captures
are copied to a cloned subrequest: r->ncaptures, r->captures and
r->captures_data.  Since r->captures cannot be changed by either request after
creating a clone, a new flag r->realloc_captures is introduced to force
reallocation of r->captures.

The issue was reported as a proxy_cache_background_update misbehavior in
http://mailman.nginx.org/pipermail/nginx/2018-December/057251.html.

src/http/ngx_http_core_module.c
src/http/ngx_http_request.h
src/http/ngx_http_variables.c

index c57ec00ce7ebc91f3d47071e640640cad078baac..5e7152f0f2de63f71c0dce0a86395be05a2e0cf0 100644 (file)
@@ -2386,6 +2386,14 @@ ngx_http_subrequest(ngx_http_request_t *r,
         sr->phase_handler = r->phase_handler;
         sr->write_event_handler = ngx_http_core_run_phases;
 
+#if (NGX_PCRE)
+        sr->ncaptures = r->ncaptures;
+        sr->captures = r->captures;
+        sr->captures_data = r->captures_data;
+        sr->realloc_captures = 1;
+        r->realloc_captures = 1;
+#endif
+
         ngx_http_update_location_config(sr);
     }
 
index 6bfff96ef8b444d8d0b16acf13164503470fb997..fce70efe619d2c8ed056a9f94df828fff60d8e70 100644 (file)
@@ -499,6 +499,10 @@ struct ngx_http_request_s {
     unsigned                          gzip_vary:1;
 #endif
 
+#if (NGX_PCRE)
+    unsigned                          realloc_captures:1;
+#endif
+
     unsigned                          proxy:1;
     unsigned                          bypass_cache:1;
     unsigned                          no_cache:1;
index 2deb9689ecbc79ef80b4a4e1fda2448a2c122c11..31321b290940ae17d98370bae2dd13efdcb3fa81 100644 (file)
@@ -2504,7 +2504,9 @@ ngx_http_regex_exec(ngx_http_request_t *r, ngx_http_regex_t *re, ngx_str_t *s)
     if (re->ncaptures) {
         len = cmcf->ncaptures;
 
-        if (r->captures == NULL) {
+        if (r->captures == NULL || r->realloc_captures) {
+            r->realloc_captures = 0;
+
             r->captures = ngx_palloc(r->pool, len * sizeof(int));
             if (r->captures == NULL) {
                 return NGX_ERROR;