From: Willy Tarreau Date: Fri, 16 Jul 2021 14:18:03 +0000 (+0200) Subject: MEDIUM: cfgcond: report invalid trailing chars after expressions X-Git-Tag: v2.5-dev2~9 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=379ceeaaebb2bfa9bae77cc1635ac6299b72791e;p=thirdparty%2Fhaproxy.git 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. --- diff --git a/src/cfgcond.c b/src/cfgcond.c index df8e4d0642..ac83b30baa 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: