]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: config: don't count trailing spaces as empty arg (v2)
authorErwan Le Goas <elegoas@haproxy.com>
Fri, 23 Sep 2022 13:06:34 +0000 (15:06 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 30 Sep 2022 13:21:20 +0000 (15:21 +0200)
In parse_line(), spaces increment the arg count and it is incremented
again on '#' or end of line, resulting in an extra empty arg at the
end of arg's list. The visible effect is that the reported arg count
is in excess of 1. It doesn't seem to affect regular function but
specialized ones like anonymisation depends on this count.

This is the second attempt for this problem, here the explanation :

When called for the first line, no <out> was allocated yet so it's NULL,
letting the caller realloc a larger line if needed. However the words are
parsed and their respective args[arg] are filled with out+position, which
means that while the first arg is NULL, the other ones are no and fail the
test that was meant to avoid dereferencing a NULL. Let's simply check <out>
instead of <args> since the latter is always derived from the former and
cannot be NULL without the former also being.

This may need to be backported to stable versions.

src/tools.c

index 33bc88e6d449e669b86cf83d4036a977f8779cba..3796c98b11b1f63bc3cc5619f4311da0342c4674 100644 (file)
@@ -5750,7 +5750,13 @@ uint32_t parse_line(char *in, char *out, size_t *outlen, char **args, int *nbarg
 
        /* end of output string */
        EMIT_CHAR(0);
-       arg++;
+
+       /* don't add empty arg after trailing spaces. Note that args[arg]
+        * may contain some distances relative to NULL if <out> was NULL,
+        * so we test <out> instead of args[arg].
+        */
+       if (arg < argsmax && out && *(args[arg]))
+               arg++;
 
        if (quote) {
                /* unmatched quote */