[PATCH 4 of 4] Script: changed index and try_files to evaluate lengths twice

Maxim Dounin mdounin at mdounin.ru
Sun Jul 19 00:01:38 UTC 2026


# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1784411862 -10800
#      Sun Jul 19 00:57:42 2026 +0300
# Node ID d6fd0bcea8666d6e0bbd3383d7ab2d28a7f21ce1
# Parent  762271b9b20cbb03e7f78c0f4e483930cb1edebc
Script: changed index and try_files to evaluate lengths twice.

Similarly to changes introduced to ngx_http_script_run(), direct script
evaluation in index and try_files now uses a separate length calculation
loop without e.flushed to ensure that all relevant non-cacheable
variables are flushed, and also to look up all the values.  This resolves
issues observed with non-cacheable variables and variables with side
effects in the index and try_files directives.

diff --git a/src/http/modules/ngx_http_index_module.c b/src/http/modules/ngx_http_index_module.c
--- a/src/http/modules/ngx_http_index_module.c
+++ b/src/http/modules/ngx_http_index_module.c
@@ -150,6 +150,14 @@ ngx_http_index_handler(ngx_http_request_
             e.ip = index[i].lengths->elts;
             e.request = r;
 
+            while (*(uintptr_t *) e.ip) {
+                lcode = *(ngx_http_script_len_code_pt *) e.ip;
+                (void) lcode(&e);
+            }
+
+            e.ip = index[i].lengths->elts;
+            e.flushed = 1;
+
             /* 1 is for terminating '\0' as in static names */
             len = 1;
 
diff --git a/src/http/modules/ngx_http_try_files_module.c b/src/http/modules/ngx_http_try_files_module.c
--- a/src/http/modules/ngx_http_try_files_module.c
+++ b/src/http/modules/ngx_http_try_files_module.c
@@ -123,6 +123,14 @@ ngx_http_try_files_handler(ngx_http_requ
             e.ip = tf->lengths->elts;
             e.request = r;
 
+            while (*(uintptr_t *) e.ip) {
+                lcode = *(ngx_http_script_len_code_pt *) e.ip;
+                (void) lcode(&e);
+            }
+
+            e.ip = tf->lengths->elts;
+            e.flushed = 1;
+
             /* 1 is for terminating '\0' as in static names */
             len = 1;
 



More information about the nginx-devel mailing list