]> git.ipfire.org Git - thirdparty/haproxy.git/commit
BUG/MEDIUM: logs: fix sess_build_logline_orig() recursion with options
authorAurelien DARRAGON <adarragon@haproxy.com>
Fri, 25 Jul 2025 14:03:21 +0000 (16:03 +0200)
committerAurelien DARRAGON <adarragon@haproxy.com>
Fri, 25 Jul 2025 14:46:03 +0000 (16:46 +0200)
commit31adfb6c15df075967bffe909509cb49583dd0d1
tree42aa109dda67bb7436ac26b61c48d880c38593f2
parentb8d5307bd9b34e0f13012ba4e656c01e1d273c27
BUG/MEDIUM: logs: fix sess_build_logline_orig() recursion with options

Since ccc43412 ("OPTIM: log: use thread local lf_buildctx to stop pushing
it on the stack"), recursively calling sess_build_logline_orig(), which
may for instance happen when leveraging %ID (or unique-id fetch) for the
first time, would lead to undefined behavior because the parent
sess_build_logline_orig() build context was shared between recursive calls
(only one build ctx per thread to avoid pushing it on the stack for each
call)

In short, the parent build ctx would be altered by the recursive calls,
which is obviously not expected and could result in log formatting errors.

To fix the issue but still avoid polluting the stack with large lf_buildctx
struct, let's move the static 256 bytes build buffer out of the buildctx
so that the buildctx is now stored in the stack again (each function
invokation has its own dedicated build ctx). On the other hand, it's
acceptable to have only 1 256 bytes build buffer per thread because the
build buffer is not involved in recursives calls (unlike the build ctx)

Thanks to Willy and Vincent Gramer for spotting the bug and providing
useful repro.

It should be backported in 3.0 with ccc43412.
src/log.c