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.
This commit is contained in:
Willy Tarreau 2025-05-05 17:58:04 +02:00
parent 09a325a4de
commit 1f51f1c816

View File

@ -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.
*/