]> git.ipfire.org Git - thirdparty/haproxy.git/commit
BUG/MINOR: log: prevent double spaces emission in sess_build_logline()
authorAurelien DARRAGON <adarragon@haproxy.com>
Thu, 2 May 2024 07:30:28 +0000 (09:30 +0200)
committerAurelien DARRAGON <adarragon@haproxy.com>
Fri, 3 May 2024 14:48:21 +0000 (16:48 +0200)
commitcc2e94a9480557afb86ea8777bac49196d6f1715
tree0c5e91c7cb9ad63a038849d4b0d69fdde4840a69
parent48e0efb00bd5a81c6f093f7d7561888e7ef2c44d
BUG/MINOR: log: prevent double spaces emission in sess_build_logline()

Christian reported in GH #2556 that since 3.0-dev double spaces may be
found in log messages on some cases where it was not the case before.

As we were able to easily reproduce, a quick bisect led us to c6a7138
("MINOR: log: simplify last_isspace in sess_build_logline()"). While
it is true that all switch cases set the last_isspace variable to 0,
there was a subtelty for some fields such as '%hr', '%hrl', '%hs' or
'%hsl' and I overlooked it. Indeed, for '%hr', last_isspace was only set
to 0 if data was emitted, else the assignment didn't occur.

But with c6a7138, last_isspace is always set to 0 as long as the current
node type is not a separator. Because of that, if no data is emitted for
the current node value, and a space was already emitted prior to the
current node, then an extra space could be emitted after the node,
resulting in two spaces being emitted.

Note that while c6a7138 introduces a slight behavior regression regarding
last_isspace logic with the specific fields mentionned above, this
behavior could already be triggered with a failing or empty logformat
node sample expression. Consider this logformat expression:

  log-format "%{-M}o | %[str()] |"

str() will not print anything, and since we disabled mandatory option with
'-M', nothing gets printed for the node sample expression. As a result, we
have the following output:

  "|  |"

Instead of (when mandatory option is enabled):

  "| - |"

Thus in order to stick to the historical behavior, systematically set
last_isspace to 0 for EXPR nodes, and only set last_isspace to 0 when
data was written for TAG nodes. This way, '%hr', '%hrl', '%hs' or
'%hsl' should behave as before.

No backport needed.
src/log.c