From: Aurelien DARRAGON Date: Thu, 6 Mar 2025 08:05:23 +0000 (+0100) Subject: BUG/MINOR: cfgparse/peers: fix inconsistent check for missing peer server X-Git-Tag: v3.2-dev7~21 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2560ab892f355e958007b287946f787b578d3131;p=thirdparty%2Fhaproxy.git BUG/MINOR: cfgparse/peers: fix inconsistent check for missing peer server In the "peers" section parser, right after parse_server() is called, we used to check whether the curpeers->peers_fe->srv pointer was set or not to know if parse_server() successfuly added a server to the peers proxy, server that we can then associate to the new peer. However the check is wrong, as curpeers->peers_fe->srv points to the last added server, if a server was successfully added before the failing one, we cannot detect that the last parse_server() didn't add a server. This is known to cause bug with bad "peer"/"server" statements. To fix the issue, we save a pointer on the last known curpeers->peers_fe->srv before parse_server() is called, and we then compare the save with the pointer after parse_server(), if the value didn't change, then parse_server() didn't add a server. This makes the check consistent in all situations. It should be backported to all stable versions. --- diff --git a/src/cfgparse.c b/src/cfgparse.c index c99a7339e..bf8d7a6c0 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -835,6 +835,7 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm) } else if (strcmp(args[0], "peer") == 0 || strcmp(args[0], "server") == 0) { /* peer or server definition */ + struct server *prev_srv; int local_peer, peer; int parse_addr = 0; @@ -885,10 +886,13 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm) * or if we are parsing a "server" line and the current peer is not the local one. */ parse_addr = (peer || !local_peer) ? SRV_PARSE_PARSE_ADDR : 0; + prev_srv = curpeers->peers_fe->srv; err_code |= parse_server(file, linenum, args, curpeers->peers_fe, NULL, SRV_PARSE_IN_PEER_SECTION|parse_addr|SRV_PARSE_INITIAL_RESOLVE); - if (!curpeers->peers_fe->srv) { - /* Remove the newly allocated peer. */ + if (curpeers->peers_fe->srv == prev_srv) { + /* parse_server didn't add a server: + * Remove the newly allocated peer. + */ if (newpeer != curpeers->local) { struct peer *p;