From 137d5ba93f62ef6e36caedac229ae47f7ddef48b Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Mon, 10 Nov 2025 11:55:33 +0100 Subject: [PATCH] BUG/MEDIUM: config: for word expansion, empty or non-existing are the same 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 | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/tools.c b/src/tools.c index c4344d472..a4d2638da 100644 --- a/src/tools.c +++ b/src/tools.c @@ -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. */