]> git.kaiwu.me - nginx.git/commit
Script: avoid garbage at the end of the result string
authorRoman Arutyunyan <arut@nginx.com>
Fri, 3 Jul 2026 11:11:09 +0000 (15:11 +0400)
committerRoman Arutyunyan <arutyunyan.roman@gmail.com>
Wed, 15 Jul 2026 17:20:38 +0000 (21:20 +0400)
commit97e40e59b7b4ad6aa36f54ce4f1e64d1e98f24cb
tree48f80556fe494cd35085dc9bb94083e9b1a727c4
parent326b17b0038321c29252e79bf4c53d4773fcb8b5
Script: avoid garbage at the end of the result string

If the script result turned out to be shorter than its predicted
length, the result string contained uninitialized bytes at the end.
The fix is to cut the result string by its actual size.

The following locations returned trailing garbage to the client with
URI "/1234abcd".

    map $uri $foo {
        ~^/(?<bar>[0-9]).*$ $bar;
    }

    location ~(?<bar>[0-9]*)[a-z]*$ {
        return 200 $1:$foo;
    }

    location ~(?<bar>[0-9]*)[a-z]*$ {
        set $qux $1:$foo;
        return 200 $qux;
    }
src/http/modules/ngx_http_rewrite_module.c
src/http/ngx_http_script.c
src/http/ngx_http_script.h
src/stream/ngx_stream_script.c