]> git.kaiwu.me - nginx.git/commitdiff
Try files: fix uri formating in case of script underwrite
authorRoman Arutyunyan <arut@nginx.com>
Thu, 5 Nov 2026 14:50:48 +0000 (18:50 +0400)
committerRoman Arutyunyan <arutyunyan.roman@gmail.com>
Wed, 11 Nov 2026 12:18:05 +0000 (16:18 +0400)
Previously, if try_files was used with alias, and the script produced
a string smaller than the predicted size, then an integer underflow
could happen which resulted in buffer overrun.

Fix is to recalculate the length after running the script.

A similar length recalculation exists in ngx_http_index_module.
It was added by 25f920eca when fixing script overruns.

Reported by Marc Luchian & Liviu-Alexandru Bud.

src/http/modules/ngx_http_try_files_module.c

index bbdab859842e94895938f42c41aa6aa6f103824d..90926028572c58f06e2b1c16e60517ec64537b9f 100644 (file)
@@ -186,6 +186,7 @@ ngx_http_try_files_handler(ngx_http_request_t *r)
                 return NGX_ERROR;
             }
 
+            len = e.pos - name + 1;
             path.len = e.pos - path.data;
 
             *e.pos = '\0';