]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MINOR: cfgparse/peers: warn and prevent undefined behavior when peers is missing...
authorAurelien DARRAGON <adarragon@haproxy.com>
Thu, 8 Oct 2026 18:04:31 +0000 (20:04 +0200)
committerAurelien DARRAGON <adarragon@haproxy.com>
Tue, 20 Oct 2026 20:03:02 +0000 (22:03 +0200)
As described in GH #3516, declaring a peers section containing the local
peer server (with server syntax) without the matching 'bind' diretive
causes haproxy to crash since 879c78c. However, as Amaury demonstrated,
the config is invalid/incomplete: it makes no sense to declare the local
peer server without the matching bind parameters. Before this patch
haproxy would let the config pass and the result was that the peers
proxy was created without any listeners. While it somehow didn't crash
in the past (perhaps the low level code was robust enough), from a
peers logic point of view it results in the peers proxy doing nothing.

Instead of silently failing (and now risking crashes upon reload), let's
proactively report a fatal error to the user that such config is
incomplete.

Many thanks to @alexandret-ik for the detailed report.
It should be backported to 3.4, and may be relevant to olders versions
but in this case replace the ha_alert() which ha_notice() so existing
configs that used to start (despite not valid from peers point of view)
don't break.

src/cfgparse.c

index 05b225114baececf37008503be3b4debcf4289f7..2097f24aff11b48e781bb97b5f0f5fbfd38e28f5 100644 (file)
@@ -2699,6 +2699,14 @@ init_proxies_list_stage2:
                                        stop_proxy(curpeers->peers_fe);
                                curpeers->peers_fe = NULL;
                        }
+                       else if (LIST_ISEMPTY(&curpeers->peers_fe->conf.listeners)) {
+                               ha_alert("Incomplete section 'peers %s' (missing listen/bind information for local peer named '%s').\n",
+                                          curpeers->id, localpeer);
+                               cfgerr++;
+                               if (curpeers->peers_fe)
+                                       stop_proxy(curpeers->peers_fe);
+                               curpeers->peers_fe = NULL;
+                       }
                        else {
                                /* Initializes the transport layer of the server part of all the peers belonging to
                                 * <curpeers> section if required.