]> git.ipfire.org Git - thirdparty/haproxy.git/commit
MINOR: cfgparse: sanitize the output a little bit
authorWilly Tarreau <w@1wt.eu>
Thu, 25 Jun 2020 07:15:40 +0000 (09:15 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 25 Jun 2020 07:43:27 +0000 (09:43 +0200)
commitc54e5ad9cc60bc81ffdcd31e7d4d007d4bd592e1
tree66963c8d203b5eb52d1da9c2025006c9d8cfdec5
parent07d47060e0d99d0884440c3fa55ef2a338987769
MINOR: cfgparse: sanitize the output a little bit

With the rework of the config line parser, we've started to emit a dump
of the initial line underlined by a caret character indicating the error
location. But with extremely large lines it starts to take time and can
even cause trouble to slow terminals (e.g. over ssh), and this becomes
useless. In addition, control characters could be dumped as-is which is
bad, especially when the input file is accidently wrong (an executable).

This patch adds a string sanitization function which isolates an area
around the error position in order to report only that area if the string
is too large. The limit was set to 80 characters, which will result in
roughly 40 chars around the error being reported only, prefixed and suffixed
with "..." as needed. In addition, non-printable characters in the line are
now replaced with '?' so as not to corrupt the terminal. This way invalid
variable names, unmatched quotes etc will be easier to spot.

A typical output is now:

  [ALERT] 176/092336 (23852) : parsing [bad.cfg:8]: forbidden first char in environment variable name at position 811957:
    ...c$PATH$PATH$d(xlc`%?$PATH$PATH$dgc?T$%$P?AH?$PATH$PATH$d(?$PATH$PATH$dgc?%...
                                            ^
include/haproxy/tools.h
src/cfgparse.c
src/tools.c