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.
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 {
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 {