]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cfgcond: remerge all arguments into a single line
authorWilly Tarreau <w@1wt.eu>
Fri, 16 Jul 2021 14:38:58 +0000 (16:38 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 16 Jul 2021 17:18:41 +0000 (19:18 +0200)
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.

src/cfgparse.c
src/haproxy.c

index 4cee8a7b6c4a9055ed9be4ba95fb8cb7e401164a..fed8f7e5916bfac77455c51d903dbb74b1a3187c 100644 (file)
@@ -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);
index c863e13ec70e53abb7a382b54b1d54f41051b4e1..a4cbce5e33f29f76de99c58e0ec00d36a4c55629 100644 (file)
@@ -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) {