]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: peers: fix possible NULL dereferences at config parsing
authorWilliam Lallemand <wlallemand@haproxy.org>
Wed, 6 Jul 2022 12:30:23 +0000 (14:30 +0200)
committerWilliam Lallemand <wlallemand@haproxy.org>
Wed, 6 Jul 2022 12:40:11 +0000 (14:40 +0200)
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.

src/cfgparse.c

index 0c12ec6e22732607a81e9e95608af39cf0dd3513..8fb866b7829ac1aefe5e4c04addf4c51c28a2b32 100644 (file)
@@ -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);