]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: server/lbprm: fix crash in _srv_set_inetaddr_port()
authorAurelien DARRAGON <adarragon@haproxy.com>
Wed, 3 Apr 2024 09:41:57 +0000 (11:41 +0200)
committerAurelien DARRAGON <adarragon@haproxy.com>
Wed, 3 Apr 2024 09:58:03 +0000 (11:58 +0200)
Since faa8c3e ("MEDIUM: lb-chash: Deterministic node hashes based on
server address") the following configuration will cause haproxy to crash:

  backend test1
       mode http
       balance hash int(1)
       server s1 haproxy.org:80

This is because lbprm.update_server_eweight() method is now systematically
called in _srv_set_inetaddr_port() upon srv addr/port change (and with the
above config it happens during startup after initial dns resolution).

However, depending on the chosen lbprm algo, update_server_eweight function
may not be set (it is not a mandatory method, some lb implementations don't
define it).

Thus, using 'balance hash' with map-based hashing or 'balance sticky' will
cause a crash due to a NULL de-reference in _srv_set_inetaddr_port(). To
fix the issue, we first check that the update_server_eweight() method is
set before using it.

No backport needed unless faa8c3e ("MEDIUM: lb-chash: Deterministic node
hashes based on server address") gets backported.

src/server.c

index 52b715bfa0a320580a70c0055bc7c1b3301b4491..fc5a45820db133bdec39fdfecea349b45cc32ce8 100644 (file)
@@ -184,8 +184,10 @@ static void _srv_set_inetaddr_port(struct server *srv,
        else
                srv->flags &= ~SRV_F_MAPPORTS;
 
-       /* balancers (chash in particular) may use the addr in their routing decisions */
-       srv->proxy->lbprm.update_server_eweight(srv);
+       if (srv->proxy->lbprm.update_server_eweight) {
+               /* some balancers (chash in particular) may use the addr in their routing decisions */
+               srv->proxy->lbprm.update_server_eweight(srv);
+       }
 
        if (srv->log_target && srv->log_target->type == LOG_TARGET_DGRAM) {
                /* server is used as a log target, manually update log target addr for DGRAM */