]> git.kaiwu.me - nginx.git/commitdiff
Add missing bounds check in ngx_{http,stream}_compile_complex_value()
authorFeng Wu <wufengwufengwufeng@gmail.com>
Tue, 23 Jun 2026 23:22:43 +0000 (07:22 +0800)
committerSergey Kandaurov <pluknet@nginx.com>
Fri, 2 Oct 2026 14:33:28 +0000 (18:33 +0400)
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.

src/http/ngx_http_script.c
src/stream/ngx_stream_script.c

index d7b8e6e302ffe1192809b2a4b185daf383344e93..4d0a6708432a999101212c4082eaaae7a852b4af 100644 (file)
@@ -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 {
index 559b8b9fb2b03d57f215a1d9799cae7f5068688b..54e5dd55918c9c63d3529e8dfba7d00f7511a030 100644 (file)
@@ -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 {