]> git.kaiwu.me - nginx.git/commitdiff
Rewrite: harden escape flags control
authorRoman Arutyunyan <arut@nginx.com>
Thu, 14 May 2026 13:47:42 +0000 (17:47 +0400)
committerSergey Kandaurov <pluknet@nginx.com>
Fri, 2 Oct 2026 14:33:28 +0000 (18:33 +0400)
Following 2046b45aa0c6, this change introduces better control of memory
allocation flags for escaped values.  Notably:

- The e->is_args flag is now explicitly reset on rewrite start.
  If the flag was set prior to rewrite start, then buffer overflow
  could happen before 2046b45aa0c6.

- The le->is_args flag value is now copied from e->is_args when
  calculating complex value length for "if" and "set" directives.
  If e->is_args was set, but le->is_args was not, then buffer overflow
  could happen before 2046b45aa0c6.

src/http/ngx_http_script.c

index 9c97a5b085112e1f673a6638ecd23ba5cd83d127..d7b8e6e302ffe1192809b2a4b185daf383344e93 100644 (file)
@@ -1234,6 +1234,7 @@ ngx_http_script_regex_start_code(ngx_http_script_engine_t *e)
         return;
     }
 
+    e->is_args = 0;
     e->quote = code->redirect;
 
     e->pos = e->buf.data;
@@ -1847,6 +1848,7 @@ ngx_http_script_complex_value_code(ngx_http_script_engine_t *e)
     le.ip = code->lengths->elts;
     le.line = e->line;
     le.request = e->request;
+    le.is_args = e->is_args;
     le.quote = e->quote;
 
     for (len = 0; *(uintptr_t *) le.ip; len += lcode(&le)) {