]> 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)
committerVadimZhestikov <108960056+VadimZhestikov@users.noreply.github.com>
Thu, 25 Jun 2026 16:15:44 +0000 (09:15 -0700)
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 8f7b548cc6686ea0b59aee141a8497ff912ff67d..ddae0c1cb6c8a2c528d03b96b11695dc952f0244 100644 (file)
@@ -150,7 +150,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 c447e152f8f453ecac8798d6443a4945cb6c125b..175e44194bb6ff0a52726fe14be73cce145ee5a9 100644 (file)
@@ -151,7 +151,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 {