]> git.kaiwu.me - njs.git/commitdiff
CHB: avoid overflow when enforcing the chain limit
authorDmitry Volyntsev <xeioex@nginx.com>
Tue, 22 Sep 2026 03:28:29 +0000 (20:28 -0700)
committerDmitry Volyntsev <xeioexception@gmail.com>
Fri, 25 Sep 2026 23:00:29 +0000 (16:00 -0700)
Check the requested size against the remaining chain capacity instead of
adding it to the current total.  This prevents the size check from wrapping
and bypassing the configured chain limit.

src/njs_chb.c

index eace09fe7ef5baeb381467a2bb5ad73d67847f23..ece3aeb0ffea6b0e2bd4a774d0438aa4d3d3a563 100644 (file)
@@ -68,7 +68,8 @@ njs_chb_reserve(njs_chb_t *chain, size_t size)
     }
 
     if (njs_slow_path(chain->max_size != 0
-                      && chain->total_size + size > chain->max_size))
+                      && (chain->total_size > chain->max_size
+                          || size > chain->max_size - chain->total_size)))
     {
         chain->error = NJS_CHB_ERR_OVERFLOW;
         return NULL;