]> 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 15:51:22 +0000 (19:51 +0400)
commita8289aa69c74f7e664ad63b91c17aa2a554f190f
treea9fee3663b832651f34f89c2ecaadd190c8ca22b
parent25f920eca977139dc6fc7638b419169a602a0064
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