]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: config: now reject configs with empty arguments
authorWilly Tarreau <w@1wt.eu>
Tue, 24 Jun 2025 06:24:28 +0000 (08:24 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 6 Nov 2025 18:57:44 +0000 (19:57 +0100)
As prepared during 3.2, we must error on empty arguments because they
mark the end of the line and cause subsequent arguments to be silently
ignored. It was too late in 3.2 to turn that into an error so it's a
warning, but for 3.3 it needed to be an alert.

This patch does that. It doesn't instantly break, instead it counts
one fatal error per violating line. This allows to emit several errors
at once, which can often be caused by the same variable being missed,
or a group of variables sharing a same misspelled prefix for example.
Tests show that it helps locate them better. It also explains what to
look for in the config manual for help with variables expansion.

src/cfgparse.c

index bf1c4d1faf7974ab5428228b173c2f0d61d52322..e0e655ba20ad3785c70ee079fcb16d7f06a04fdf 100644 (file)
@@ -2072,6 +2072,7 @@ next_line:
                                /* Only print empty arg warning in normal mode to prevent double display. */
                                for (check_arg = 0; check_arg < arg; check_arg++) {
                                        if (!*args[check_arg]) {
+                                               static int warned_empty;
                                                size_t newpos;
 
                                                /* if an empty arg was found, its pointer should be in <errptr>, except
@@ -2088,10 +2089,16 @@ next_line:
 
                                                /* sanitize input line in-place */
                                                newpos = sanitize_for_printing(line, errptr - line, 80);
-                                               ha_warning("parsing [%s:%d]: argument number %d at position %d is empty and marks the end of the "
-                                                          "argument list; all subsequent arguments will be ignored:\n  %s\n  %*s\n",
-                                                          file, linenum, check_arg, (int)(errptr - thisline + 1), line, (int)(newpos + 1), "^");
-                                               break;
+                                               ha_alert("parsing [%s:%d]: argument number %d at position %d is empty and marks the end of the "
+                                                        "argument list:\n  %s\n  %*s\n%s",
+                                                        file, linenum, check_arg, (int)(errptr - thisline + 1), line, (int)(newpos + 1),
+                                                        "^", (warned_empty++) ? "" :
+                                                        ("Aborting to prevent all subsequent arguments from being silently ignored. "
+                                                         "If this is caused by an environment variable expansion, please have a look at section "
+                                                         "2.3 of the configuration manual to find solutions to address this.\n"));
+                                               err_code |= ERR_ALERT | ERR_FATAL;
+                                               fatal++;
+                                               goto next_line;
                                        }
                                }
                        }