From: Willy Tarreau Date: Mon, 5 May 2025 15:58:04 +0000 (+0200) Subject: BUG/MINOR: tools: make parseline report the required space for the trailing 0 X-Git-Tag: v3.2-dev15~31 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1f51f1c816b43cbfd6526bb17fe1bf9995fc083a;p=thirdparty%2Fhaproxy.git BUG/MINOR: tools: make parseline report the required space for the trailing 0 The fix in commit 09a325a4de ("BUG/MINOR: tools: always terminate empty lines") is insufficient. While it properly addresses the lack of trailing zero, it doesn't account for it in the returned outlen that is used to allocate a larger line. This happens at boot if the very first line of the test file is exactly a sharp with nothing else. In this case it will return a length 0 and the caller (parse_cfg()) will try to re-allocate an entry of size zero and will fail, bailing out a lack of memory. This time it should really be OK. It doesn't need to be backported, unless the patch above would be. --- diff --git a/src/tools.c b/src/tools.c index fbb4c4781..73335d21e 100644 --- a/src/tools.c +++ b/src/tools.c @@ -6504,13 +6504,13 @@ uint32_t parse_line(char *in, char *out, size_t *outlen, char **args, int *nbarg goto leave; } leave: - *nbargs = arg; - *outlen = outpos; - /* make sure empty lines are terminated */ if (!arg) EMIT_CHAR(0); + *nbargs = arg; + *outlen = outpos; + /* empty all trailing args by making them point to the trailing zero, * at least the last one in any case. */