]> git.kaiwu.me - nginx.git/commitdiff
Core: fixed reading past an empty string in ngx_test_full_name()
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_variable_document_root() can pass an empty string (len == 0,
data from ngx_pnalloc(pool, 0)) to ngx_get_full_name() when root
evaluates to an empty value.  ngx_test_full_name() read data[0]
unconditionally, so whether the empty root counted as absolute depended
on uninitialized pool memory.  Two evaluations of $document_root in one
script (for example in "if (-f $document_root/file)") could return
different lengths, which fails the script copy check with "no buffer
space in script copy" and a 500 response.

An empty name is now never absolute.

Closes: https://github.com/nginx/nginx/issues/1836
src/core/ngx_file.c

index 63ada85576a457eb1ac7e8469f1e38f3d677a109..8e0d1cb21e3b70d83c165ecf0ca62a63ca95c387 100644 (file)
@@ -61,6 +61,10 @@ ngx_test_full_name(ngx_str_t *name)
 #if (NGX_WIN32)
     u_char  c0, c1;
 
+    if (name->len == 0) {
+        return NGX_DECLINED;
+    }
+
     c0 = name->data[0];
 
     if (name->len < 2) {
@@ -95,7 +99,7 @@ ngx_test_full_name(ngx_str_t *name)
 
 #else
 
-    if (name->data[0] == '/') {
+    if (name->len > 0 && name->data[0] == '/') {
         return NGX_OK;
     }