[PATCH 3 of 5] Rewrite: fixed "if" with relative file names

Maxim Dounin mdounin at mdounin.ru
Mon May 25 01:09:42 UTC 2026


# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1779656347 -10800
#      Sun May 24 23:59:07 2026 +0300
# Node ID 81500b5d5a1bcc8c89b3f192577dfd65512fad2c
# Parent  ebb65cf91321c0c58a8468e540dfebfdb8500322
Rewrite: fixed "if" with relative file names.

Previously, relative file names in "if" were not specifically handled
and therefore resolved from the process current working directory,
leading to changes in behaviour depending on the current directory
during startup.  This also differs from the expected behaviour of paths
used in the configuration, which are expected to be resolved either from
prefix or from configuration prefix.

The fix is to use ngx_get_full_name() in ngx_http_script_file_code(),
so relative paths, if used, are resolved from prefix.

diff --git a/src/http/ngx_http_script.c b/src/http/ngx_http_script.c
--- a/src/http/ngx_http_script.c
+++ b/src/http/ngx_http_script.c
@@ -1606,6 +1606,14 @@ ngx_http_script_file_code(ngx_http_scrip
 
     r = e->request;
 
+    if (ngx_get_full_name(r->pool, (ngx_str_t *) &ngx_cycle->prefix, &path)
+        != NGX_OK)
+    {
+        e->ip = ngx_http_script_exit;
+        e->status = NGX_HTTP_INTERNAL_SERVER_ERROR;
+        return;
+    }
+
     ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
                    "http script file op %p \"%V\"", (void *) code->op, &path);
 



More information about the nginx-devel mailing list