]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: cfgparse-listen: fix ebpt_next_dup pointer dereference on proxy "from...
authorAurelien DARRAGON <adarragon@haproxy.com>
Mon, 21 Nov 2022 16:01:11 +0000 (17:01 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 22 Nov 2022 15:27:52 +0000 (16:27 +0100)
ebpt_next_dup() was used 2 times in a row but only the first call was
checked against NULL, probably assuming that the 2 calls always yield the
same result here.

gcc is not OK with that, and it should be safer to store the result of
the first call in a temporary var to dereference it once checked against NULL.

This should fix GH #1869.
Thanks to Ilya for reporting this issue.

It may be backported up to 2.4.

src/cfgparse-listen.c

index 258a3581ca63f62b7c1550ca1a4feaeffeadf2e0..258564404a9e9bbf84ea9839fa892611f6959c25 100644 (file)
@@ -291,6 +291,8 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                        curr_defproxy = last_defproxy;
 
                if (strcmp(args[arg], "from") == 0) {
+                       struct ebpt_node *next_by_name;
+
                        curr_defproxy = proxy_find_by_name(args[arg+1], PR_CAP_DEF, 0);
 
                        if (!curr_defproxy) {
@@ -299,8 +301,8 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                                goto out;
                        }
 
-                       if (ebpt_next_dup(&curr_defproxy->conf.by_name)) {
-                               struct proxy *px2 = container_of(ebpt_next_dup(&curr_defproxy->conf.by_name), struct proxy, conf.by_name);
+                       if ((next_by_name = ebpt_next_dup(&curr_defproxy->conf.by_name))) {
+                               struct proxy *px2 = container_of(next_by_name, struct proxy, conf.by_name);
 
                                ha_alert("parsing [%s:%d] : ambiguous defaults section name '%s' referenced by %s '%s' exists at least at %s:%d and %s:%d.\n",
                                         file, linenum, args[arg+1], proxy_cap_str(rc), name,