From: Aaron Queen Date: Mon, 12 Oct 2026 18:56:37 +0000 (-0600) Subject: Core: fixed reading past an empty string in ngx_test_full_name() X-Git-Url: https://git.kaiwu.me/%7Bsubstring-before(@doc,%20'.xml')%7D.html?a=commitdiff_plain;h=69b110d53ab9ee01c458fad83673b4272ab05e45;p=nginx.git Core: fixed reading past an empty string in ngx_test_full_name() 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 --- diff --git a/src/core/ngx_file.c b/src/core/ngx_file.c index 63ada8557..8e0d1cb21 100644 --- a/src/core/ngx_file.c +++ b/src/core/ngx_file.c @@ -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; }