]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: cfgparse: detect another uncaught case of duplicate defaults
authorWilly Tarreau <w@1wt.eu>
Fri, 20 Sep 2024 12:28:15 +0000 (14:28 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 20 Sep 2024 13:58:10 +0000 (15:58 +0200)
The following sequence was not properly caught:

   defaults def
   backend back from def
   defaults def

But this one was:

   defaults def
   defaults def
   backend back from def

Let's check when defaults are declared that they're not already
referenced.

Better not backport this. While it will catch broken configs (possibly
some with backends pasted after the wrong defaults), these might still
work by accident. It may be reported as a diag warning though.

src/cfgparse-listen.c

index 72d08e887560253087bcd8ffd604dbc36a744006..e190e6e16f509a19e29cbd66791cbe36ea4714ad 100644 (file)
@@ -307,6 +307,26 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                        err_code |= ERR_ALERT | ERR_FATAL;
                }
 
+               if (*args[1] && rc & PR_CAP_DEF) {
+                       /* for default proxies, if another one has the same
+                        * name and was explicitly referenced, this is an error
+                        * that we must reject. E.g.
+                        *     defaults def
+                        *     backend bck from def
+                        *     defaults def
+                        */
+                       curproxy = proxy_find_by_name(args[1], PR_CAP_DEF, 0);
+                       if (curproxy && curproxy->flags & PR_FL_EXPLICIT_REF) {
+                               ha_alert("Parsing [%s:%d]: %s '%s' has the same name as another defaults section declared at"
+                                        " %s:%d which was explicitly referenced hence cannot be replaced. Please remove or"
+                                        " rename one of the offending defaults section.\n",
+                                        file, linenum, proxy_cap_str(rc), args[1],
+                                        curproxy->conf.file, curproxy->conf.line);
+                               err_code |= ERR_ALERT | ERR_ABORT;
+                               goto out;
+                       }
+               }
+
                curproxy = proxy_find_by_name(args[1], 0, 0);
                if (!curproxy && !(rc & PR_CAP_DEF))
                        curproxy = proxy_find_by_name(args[1], PR_CAP_DEF, 0);