]> git.kaiwu.me - nginx.git/commitdiff
Fixed testing unset path bytes for an empty variable root
authorAaron Queen <bompus@users.noreply.github.com>
Mon, 12 Oct 2026 18:56:37 +0000 (12:56 -0600)
committerRoman Arutyunyan <arutyunyan.roman@gmail.com>
Wed, 25 Nov 2026 13:36:06 +0000 (17:36 +0400)
ngx_http_map_uri_to_path() runs the root script with the space for the
URI reserved after it, then passes the whole buffer to
ngx_get_full_name().  When root evaluated to an empty string, the first
byte tested by ngx_test_full_name() was in the reserved space, which
had not been written yet, so the same request could map to a path
relative to the prefix or to a path from the file system root.

A NUL byte is now written where the root ends, so an empty root is an
empty string and not unset bytes.

Closes: https://github.com/nginx/nginx/issues/1836
src/http/ngx_http_core_module.c

index 30ae6e0ec8e631fcbe5aee63e81f4917f585b77e..85cf3aea1e5f96d90a06375b2a14d600244af29e 100644 (file)
@@ -2029,6 +2029,8 @@ ngx_http_map_uri_to_path(ngx_http_request_t *r, ngx_str_t *path,
             return NULL;
         }
 
+        path->data[path->len - reserved] = '\0';
+
         if (ngx_get_full_name(r->pool, (ngx_str_t *) &ngx_cycle->prefix, path)
             != NGX_OK)
         {