From: William Lallemand Date: Wed, 6 Jul 2022 12:30:23 +0000 (+0200) Subject: BUG/MINOR: peers: fix possible NULL dereferences at config parsing X-Git-Tag: v2.7-dev2~91 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1d93217a057cb202a49b0fae2ebcffc32495fbe6;p=thirdparty%2Fhaproxy.git BUG/MINOR: peers: fix possible NULL dereferences at config parsing Patch 49f6f4b ("BUG/MEDIUM: peers: fix segfault using multiple bind on peers sections") introduced possible NULL dereferences when parsing the peers configuration. Fix the issue by checking the return value of bind_conf_uniq_alloc(). This patch should be backported as far as 2.0. --- diff --git a/src/cfgparse.c b/src/cfgparse.c index 0c12ec6e22..8fb866b782 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -704,6 +704,11 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm) bind_conf = bind_conf_uniq_alloc(curpeers->peers_fe, file, linenum, args[1], xprt_get(XPRT_RAW)); + if (!bind_conf) { + ha_alert("parsing [%s:%d] : '%s %s' : cannot allocate memory.\n", file, linenum, args[0], args[1]); + err_code |= ERR_FATAL; + goto out; + } if (*args[0] == 'b') { struct listener *l; @@ -923,6 +928,11 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm) goto out; bind_conf = bind_conf_uniq_alloc(curpeers->peers_fe, file, linenum, args[2], xprt_get(XPRT_RAW)); + if (!bind_conf) { + ha_alert("parsing [%s:%d] : '%s %s' : Cannot allocate memory.\n", file, linenum, args[0], args[1]); + err_code |= ERR_FATAL; + goto out; + } if (!LIST_ISEMPTY(&bind_conf->listeners)) { ha_alert("parsing [%s:%d] : One listener per \"peers\" section is authorized but another is already configured at [%s:%d].\n", file, linenum, bind_conf->file, bind_conf->line);