]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: tools: make parseline report the required space for the trailing 0
authorWilly Tarreau <w@1wt.eu>
Mon, 5 May 2025 15:58:04 +0000 (17:58 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 5 May 2025 15:58:04 +0000 (17:58 +0200)
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.

src/tools.c

index fbb4c4781b06bda19066541d5f9509a7b68c4079..73335d21e878a2f41596903e77ecfd7a4ff0f07a 100644 (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.
         */