]> git.kaiwu.me - nginx.git/commit
Fixed uninitialized memory read caused by stale regex captures.
authorPavel Pautov <p.pautov@f5.com>
Fri, 15 May 2026 07:48:50 +0000 (00:48 -0700)
committerRoman Arutyunyan <arutyunyan.roman@gmail.com>
Wed, 15 Jul 2026 17:20:38 +0000 (21:20 +0400)
commitb99f804ad38a60ceb07bc429598d5b2c4e70e336
tree89c4d5eeb46fbb8f68c83eb6a6e685535b277163
parent97e40e59b7b4ad6aa36f54ce4f1e64d1e98f24cb
Fixed uninitialized memory read caused by stale regex captures.

When ngx_http_regex_exec() reallocates r->captures array, it doesn't update
r->ncaptures value, if regex didn't match. So the next use of unnamed regex
capture triggers uninitialized read and potential buffer overrun.

This config demonstrates the issue:
    map test $my_map {
        volatile;

        ~mismatch(.*) 1; # reallocates r->captures in subrequests

        default "";
    }

    server {
        location ~(.*) { # sets r->ncaptures
            slice 50;

            # $1 will read from uninitialized memory in slice subrequests
            proxy_set_header Test $my_map$1;

            proxy_set_header Range $slice_range;
            proxy_pass http://backend;
        }
    }

The issue was introduced by 746fba0d79c6.
src/http/ngx_http_variables.c