From cb4c236facd3b859a946f3c1bbfed691b63e3463 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 20 Sep 2024 14:28:15 +0200 Subject: [PATCH] BUG/MINOR: cfgparse: detect another uncaught case of duplicate defaults 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 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/cfgparse-listen.c b/src/cfgparse-listen.c index 72d08e8875..e190e6e16f 100644 --- a/src/cfgparse-listen.c +++ b/src/cfgparse-listen.c @@ -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); -- 2.47.3