From: Aurelien DARRAGON Date: Wed, 3 Apr 2024 09:41:57 +0000 (+0200) Subject: BUG/MEDIUM: server/lbprm: fix crash in _srv_set_inetaddr_port() X-Git-Tag: v3.0-dev7~30 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=837a26ab05350413a63354a8dafc17ac5efc38ef;p=thirdparty%2Fhaproxy.git BUG/MEDIUM: server/lbprm: fix crash in _srv_set_inetaddr_port() 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. --- diff --git a/src/server.c b/src/server.c index 52b715bfa0..fc5a45820d 100644 --- a/src/server.c +++ b/src/server.c @@ -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 */