]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: peers: prevent unitialized multiple listeners on peers section
authorEmeric Brun <ebrun@haproxy.com>
Wed, 25 May 2022 08:25:45 +0000 (10:25 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 25 May 2022 13:10:08 +0000 (15:10 +0200)
The previous fix:
BUG/MEDIUM: peers: fix segfault using multiple bind on peers

Prevents to declare multiple listeners on a peers sections but if
peers protocol is extended to support this we could raise the bug
again.

Indeed, after allocating a new listener and adding it to a list the
code mistakenly re-configure the first element of the list instead
of the new added one, and the last one remains finally uninitialized.
The previous fix assure there is no more than one listener in this
list but this could be changed in futur.

This patch patch assures we configure and initialize the newly added
listener instead of the first one in the list.

This patch could be backported until version 2.0 to complete
BUG/MEDIUM: peers: fix segfault using multiple bind on peers

src/cfgparse.c

index 52bf2ffddba54c94997a1e17fc71f3a2d5e58dab..8b2bfc9a9a7cad8063c4119dc2b4588b0fbd398a 100644 (file)
@@ -729,7 +729,10 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
                                err_code |= ERR_FATAL;
                                goto out;
                        }
-                       l = LIST_ELEM(bind_conf->listeners.n, typeof(l), by_bind);
+                       /*
+                        * Newly allocated listener is at the end of the list
+                        */
+                       l = LIST_ELEM(bind_conf->listeners.p, typeof(l), by_bind);
                        l->maxaccept = 1;
                        l->accept = session_accept_fd;
                        l->analysers |=  curpeers->peers_fe->fe_req_ana;
@@ -933,7 +936,10 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
                        goto out;
                }
 
-               l = LIST_ELEM(bind_conf->listeners.n, typeof(l), by_bind);
+               /*
+                * Newly allocated listener is at the end of the list
+                */
+               l = LIST_ELEM(bind_conf->listeners.p, typeof(l), by_bind);
                l->maxaccept = 1;
                l->accept = session_accept_fd;
                l->analysers |=  curpeers->peers_fe->fe_req_ana;