]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: listener: handle a possible strdup() failure
authorIlia Shipitsin <chipitsine@gmail.com>
Mon, 23 Dec 2024 21:00:10 +0000 (22:00 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 25 Dec 2024 11:41:08 +0000 (12:41 +0100)
This defect was found by the coccinelle script "unchecked-strdup.cocci".
It can be backported to all supported branches.

src/listener.c

index 5f3a98b4a8b444ae04616c6e19da45901518b06d..5e423eb5735bf4d86edf8da910165d2347b5e143 100644 (file)
@@ -2369,8 +2369,13 @@ static int bind_parse_name(char **args, int cur_arg, struct proxy *px, struct bi
                return ERR_ALERT | ERR_FATAL;
        }
 
-       list_for_each_entry(l, &conf->listeners, by_bind)
+       list_for_each_entry(l, &conf->listeners, by_bind) {
                l->name = strdup(args[cur_arg + 1]);
+               if (!l->name) {
+                       memprintf(err, "'%s %s' : out of memory", args[cur_arg], args[cur_arg + 1]);
+                       return ERR_ALERT | ERR_FATAL;
+               }
+       }
 
        return 0;
 }