]> git.ipfire.org Git - thirdparty/haproxy.git/commit
MINOR: log: always consider "+M" option in lf_text_len()
authorAurelien DARRAGON <adarragon@haproxy.com>
Thu, 28 Nov 2024 11:58:37 +0000 (12:58 +0100)
committerAurelien DARRAGON <adarragon@haproxy.com>
Thu, 28 Nov 2024 12:11:11 +0000 (13:11 +0100)
commite37976166b66205c4ff2530e8a2b85ae3c50524c
tree8b241790fce5f3ae0a016cbf5551a6b39e0c3ae9
parent3e470471b7e0ec113807f6981699fda9538e7ffc
MINOR: log: always consider "+M" option in lf_text_len()

Historically, when lf_text_len() or lf_text() were called with a NULL
string and "+M" option was set, "-" would be printed.

However, if the input string was simply an empty one with len > 0, then
nothing would be printed. This can happen if lf_text() is called with
an empty string because in this case len is set to size (indeed, for
performance reasons we don't pre-compute the length, we stop as soon
as we encounter a NULL-byte)

In practise, a lot of call places making use of lf_text() or lf_text_len()
try their best to avoid calling lf_text() with an empty string, and
instead explicitly call lf_text_len() with NULL as parameter to consider
the "+M" option.

But this is not enough, as shown in GH #2797, there could still be places
where lf_text() is called with an empty string. In such case, instead of
ignoring the "+M" option, let's check after _lf_text_len() if the returned
pointer differs from the original one. If both are equal, then it means
that nothing was printed (ie: result of empty string): in that case we
check the "+M" option to print "-" when possible.

While this commit seems harmless, it's probably better to avoid
backporting it since it could break existing applications relying on the
historical behavior.
src/log.c