BUG/MINOR: cli/payload: do not search for args inside payload
authorWilly Tarreau <w@1wt.eu>
Fri, 17 Sep 2021 09:07:45 +0000 (11:07 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 20 Sep 2021 15:04:17 +0000 (17:04 +0200)
commit219453eb4c24b0933e2c018268ef3e7a44dfba9b
tree8bdafc7e0e90c3229ae7fcc287a614bb50789853
parentad2c8298cc00fce0aac6864c1903eec4c114b4f0
BUG/MINOR: cli/payload: do not search for args inside payload

The CLI's payload parser is over-complicated and as such contains more
bugs than needed. One of them is that it uses strstr() to find the
ending tag, ignoring spaces before it, while the argument locator
creates a new arg on each space, without checking if the end of the
word appears past the previously found end. This results in "<<" being
considered as the start of a new argument if preceeded by more than
one space, and the payload being damaged with a \0 inserted at the
first space or tab.

Let's make an easily backportable fix for now. This fix makes sure that
the trailing zero from the first line is properly kept after '<<' and
that the end tag is looked for only as an isolated argument and nothing
else. This also gets rid of the unsuitable strstr() call and now makes
sure that strcspn() will not return elements that are found in the
payload.

For the long term the loop must be rewritten to get rid of those
unsuitable strcspn() and strstr() calls which work past each other, and
the cli_parse_request() function should be split into a tokenizer and
an executor that are used from the caller instead of letting the caller
play games with what it finds there.

This should be backported wherever CLI payload is supported, i.e. 2.0+.

(cherry picked from commit f2dda52e784f3eebc693a70b9491a428cbbf188e)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit c5c170a0e2b59f1580bfa7578bdc0410a7ccbf0e)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
src/cli.c