From 379ceeaaebb2bfa9bae77cc1635ac6299b72791e Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 16 Jul 2021 16:18:03 +0200 Subject: [PATCH] MEDIUM: cfgcond: report invalid trailing chars after expressions 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 | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/cfgcond.c b/src/cfgcond.c index df8e4d064..ac83b30ba 100644 --- a/src/cfgcond.c +++ b/src/cfgcond.c @@ -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: