]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: config: for word expansion, empty or non-existing are the same
authorWilly Tarreau <w@1wt.eu>
Mon, 10 Nov 2025 10:55:33 +0000 (11:55 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 10 Nov 2025 10:59:35 +0000 (11:59 +0100)
Amaury reported a case where "${FOO[*]}" still produces an empty field.
It happens if the variable is defined but does not contain any non-space
characters. The reason is that we special-case word expansion only on
non-existing vars. Let's change the ordering of operations so that word-
expanded vars always pretend the current arg is not an empty quote, so
that we don't make any difference between a non-existing var and an
empty one.

No backport is needed unless commit 1968731765 ("BUG/MEDIUM: config:
solve the empty argument problem again") is.

src/tools.c

index c4344d47210fd5ea390fe1bb74bd8c4693218a30..a4d2638daf08c93cd91e2d1001a4237cb85d965d 100644 (file)
@@ -6430,6 +6430,15 @@ uint32_t parse_line(char *in, char *out, size_t *outlen, char **args, int *nbarg
                                brace = NULL;
                        }
 
+                       if (word_expand) {
+                               /* If an empty or unknown env variable was passed as an array,
+                                * we pretend the quotes were not empty, which will be sufficient
+                                * to avoid creating a new arg. This is permitted and results
+                                * in not creating any arg and dropping the surrounding quotes.
+                                */
+                               empty_quote = 0;
+                       }
+
                        if (value) {
                                unknown_var_name = NULL;
                                while (*value) {
@@ -6461,16 +6470,7 @@ uint32_t parse_line(char *in, char *out, size_t *outlen, char **args, int *nbarg
                                        arg_start = outpos;
                                }
                        }
-                       else if (word_expand) {
-                               /* An empty or unknown env variable was passed as an array.
-                                * This is permitted and results in not creating any arg and
-                                * dropping the surrounding quotes. Here we pretend the quotes
-                                * were not empty, which will be sufficient to avoid creating
-                                * a new arg.
-                                */
-                               empty_quote = 0;
-                       }
-                       else {
+                       else if (!word_expand) {
                                /* An unmatched environment variable was parsed, it must
                                 * count as an argument.
                                 */