From: Feng Wu Date: Tue, 23 Jun 2026 23:22:43 +0000 (+0800) Subject: Add missing bounds check in ngx_{http,stream}_compile_complex_value() X-Git-Tag: release-1.30.6~30 X-Git-Url: https://git.kaiwu.me/?a=commitdiff_plain;h=37362244dc0da7368b60e36f5b1acbb728f7471a;p=nginx.git Add missing bounds check in ngx_{http,stream}_compile_complex_value() Complex value compilation scans strings for $1..$9 capture references. Check that a byte after '$' is present before testing it, matching ngx_str_t length semantics and avoiding reliance on NUL termination. Apply the same check to both HTTP and stream implementations. --- diff --git a/src/http/ngx_http_script.c b/src/http/ngx_http_script.c index d7b8e6e30..4d0a67084 100644 --- a/src/http/ngx_http_script.c +++ b/src/http/ngx_http_script.c @@ -156,7 +156,9 @@ ngx_http_compile_complex_value(ngx_http_compile_complex_value_t *ccv) for (i = 0; i < v->len; i++) { if (v->data[i] == '$') { - if (v->data[i + 1] >= '1' && v->data[i + 1] <= '9') { + if (i + 1 < v->len + && v->data[i + 1] >= '1' && v->data[i + 1] <= '9') + { nc++; } else { diff --git a/src/stream/ngx_stream_script.c b/src/stream/ngx_stream_script.c index 559b8b9fb..54e5dd559 100644 --- a/src/stream/ngx_stream_script.c +++ b/src/stream/ngx_stream_script.c @@ -157,7 +157,9 @@ ngx_stream_compile_complex_value(ngx_stream_compile_complex_value_t *ccv) for (i = 0; i < v->len; i++) { if (v->data[i] == '$') { - if (v->data[i + 1] >= '1' && v->data[i + 1] <= '9') { + if (i + 1 < v->len + && v->data[i + 1] >= '1' && v->data[i + 1] <= '9') + { nc++; } else {