]> git.ipfire.org Git - thirdparty/haproxy.git/commit
MINOR: tools: make parse_line() always terminate the args list
authorWilly Tarreau <w@1wt.eu>
Thu, 25 Jun 2020 05:35:42 +0000 (07:35 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 25 Jun 2020 07:43:27 +0000 (09:43 +0200)
commit61dd44bbc1d7b98710ddd922b766170e55defe73
tree5f164d219b582c18f96bdebe364ff9186e69b5b9
parent40cb26f6ec8cf9d8ba54706d95df4cfed3a7b332
MINOR: tools: make parse_line() always terminate the args list

parse_line() as added in commit c8d167bcf ("MINOR: tools: add a new
configurable line parse, parse_line()") presents an difficult usage
because it's up to the caller to determine the last written argument
based on what was passed to it. In practice the only way to safely
use it is for the caller to always pass nbarg-1 and make that last
entry point to the last arg + its strlen. This is annoying because
it makes it as painful to use as the infamous strncpy() while it has
all the information the caller needs.

This patch changes its behavior so that it guarantees that at least
one argument will point to the trailing zero at the end of the output
string, as long as there is at least one argument. The caller just
has to pass +1 to the arg count to make sure at least a last one is
empty.
src/cfgparse.c
src/tools.c