]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: cfgcond: report invalid trailing chars after expressions
authorWilly Tarreau <w@1wt.eu>
Fri, 16 Jul 2021 14:18:03 +0000 (16:18 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 16 Jul 2021 17:18:41 +0000 (19:18 +0200)
Random characters placed after a configuration predicate currently do
not report an error. This is a problem because extra parenthesis,
commas or even other random left-over chars may accidently appear there.
Let's now report an error when this happens.

This is marked MEDIUM because it may break otherwise working configs
which are faulty.

src/cfgcond.c

index df8e4d064287f244d5ebb334840193d15d66a174..ac83b30baa1347fb664d3848287241b4797e0917 100644 (file)
@@ -195,6 +195,16 @@ int cfg_eval_condition(char **args, char **err, const char **errptr)
        if (ret != 0) {
                if (ret == -1) // parse error, error already reported
                        goto done;
+               while (*text == ' ' || *text == '\t')
+                       text++;
+
+               if (*text) {
+                       ret = -1;
+                       memprintf(err, "unexpected character '%c' at the end of conditional expression '%s'",
+                                 *text, args[0]);
+                       goto fail;
+               }
+
                ret = cfg_eval_cond_term(&term, err);
                goto done;
        }
@@ -202,6 +212,7 @@ int cfg_eval_condition(char **args, char **err, const char **errptr)
        /* ret == 0, no other way to parse this */
        ret = -1;
        memprintf(err, "unparsable conditional expression '%s'", args[0]);
+ fail:
        if (errptr)
                *errptr = text;
  done: