]> git.kaiwu.me - nginx.git/commitdiff
Rewrite: fixed segfault with rewritten URI and "alias".
authorRuslan Ermilov <ru@nginx.com>
Mon, 16 Dec 2019 12:19:01 +0000 (15:19 +0300)
committerRuslan Ermilov <ru@nginx.com>
Mon, 16 Dec 2019 12:19:01 +0000 (15:19 +0300)
The "alias" directive cannot be used in the same location where URI
was rewritten.  This has been detected in the "rewrite ... break"
case, but not when the standalone "break" directive was used.

This change also fixes proxy_pass with URI component in a similar
case:

       location /aaa/ {
           rewrite ^ /xxx/yyy;
           break;
           proxy_pass http://localhost:8080/bbb/;
       }

Previously, the "/bbb/yyy" would be sent to a backend instead of
"/xxx/yyy".  And if location's prefix was longer than the rewritten
URI, a segmentation fault might occur.

src/http/ngx_http_script.c

index f2f5a1ca8986214e5df5c05ec8cfa0f2a62c39d6..13c57d6d94ea81b17aa3103620a47f135c63518d 100644 (file)
@@ -1470,7 +1470,14 @@ ngx_http_script_return_code(ngx_http_script_engine_t *e)
 void
 ngx_http_script_break_code(ngx_http_script_engine_t *e)
 {
-    e->request->uri_changed = 0;
+    ngx_http_request_t  *r;
+
+    r = e->request;
+
+    if (r->uri_changed) {
+        r->valid_location = 0;
+        r->uri_changed = 0;
+    }
 
     e->ip = ngx_http_script_exit;
 }