From: Willy Tarreau Date: Fri, 16 Jul 2021 14:38:58 +0000 (+0200) Subject: MINOR: cfgcond: remerge all arguments into a single line X-Git-Tag: v2.5-dev2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c8194c30dff48a4f3bf3d0fc496dd9a219f77fee;p=thirdparty%2Fhaproxy.git MINOR: cfgcond: remerge all arguments into a single line Till now we were dealing with single-word expressions but in order to extend the configuration condition language a bit more, we'll need to support slightly more complex expressions involving operators, and we must absolutely support spaces around them to keep them readable. As all arguments are pointers to the same line with spaces replaced by zeroes, we can trivially rebuild the whole line before calling the condition evaluator, and remove the test for extraneous argument. This is what this patch does. --- diff --git a/src/cfgparse.c b/src/cfgparse.c index 4cee8a7b6c..fed8f7e591 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -1889,13 +1889,11 @@ next_line: const char *errptr = NULL; char *errmsg = NULL; int cond; + char *w; - if (*args[2]) { - ha_alert("parsing [%s:%d]: Unexpected argument '%s' for '%s'.\n", - file, linenum, args[2], args[0]); - err_code |= ERR_ALERT | ERR_FATAL | ERR_ABORT; - break; - } + /* remerge all words into a single expression */ + for (w = *args; (w += strlen(w)) < outline + outlen - 1; *w = ' ') + ; nested_cond_lvl++; if (nested_cond_lvl >= MAXNESTEDCONDS) { @@ -1938,13 +1936,11 @@ next_line: const char *errptr = NULL; char *errmsg = NULL; int cond; + char *w; - if (*args[2]) { - ha_alert("parsing [%s:%d]: Unexpected argument '%s' for '%s'.\n", - file, linenum, args[2], args[0]); - err_code |= ERR_ALERT | ERR_FATAL | ERR_ABORT; - break; - } + /* remerge all words into a single expression */ + for (w = *args; (w += strlen(w)) < outline + outlen - 1; *w = ' ') + ; if (!nested_cond_lvl) { ha_alert("parsing [%s:%d]: lone '.elif' with no matching '.if'.\n", file, linenum); diff --git a/src/haproxy.c b/src/haproxy.c index c863e13ec7..a4cbce5e33 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -1807,6 +1807,7 @@ static void init(int argc, char **argv) char *args[MAX_LINE_ARGS+1]; int arg = sizeof(args) / sizeof(*args); size_t outlen = strlen(check_condition) + 1; + char *w; err = parse_line(check_condition, check_condition, &outlen, args, &arg, PARSE_OPT_ENV | PARSE_OPT_WORD_EXPAND | PARSE_OPT_DQUOTE | PARSE_OPT_SQUOTE | PARSE_OPT_BKSLASH, @@ -1827,7 +1828,7 @@ static void init(int argc, char **argv) exit(2); } - if ((err & PARSE_ERR_TOOMANY) || *args[1]) { + if (err & PARSE_ERR_TOOMANY) { ha_alert("Error in condition: Too many words.\n"); exit(2); } @@ -1837,6 +1838,10 @@ static void init(int argc, char **argv) exit(2); } + /* remerge all words into a single expression */ + for (w = *args; (w += strlen(w)) < check_condition + outlen - 1; *w = ' ') + ; + result = cfg_eval_condition(args, &errmsg, &errptr); if (result < 0) {