]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: server: check strdup return value on server ID
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Fri, 31 Jul 2026 09:34:17 +0000 (11:34 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Mon, 3 Aug 2026 09:11:19 +0000 (11:11 +0200)
Add missing checks on strdup() return value in _srv_parse_init() when
generating server ID or server-template tmpl_info.prefix.

This must be backported to all stable releases.

src/server.c

index 0f586c24ddb85f1afdde1be29017c77fa8bc7db8..22c82d8ba75f1c5eef4052dfb59ec958002e75c5 100644 (file)
@@ -3740,10 +3740,22 @@ static int _srv_parse_init(struct server **srv, char **args, int *cur_arg,
                if (parse_flags & SRV_PARSE_DYNAMIC)
                        newsrv->flags |= SRV_F_DYNAMIC;
 
-               if (!(parse_flags & SRV_PARSE_TEMPLATE))
+               if (!(parse_flags & SRV_PARSE_TEMPLATE)) {
                        newsrv->id = strdup(args[1]);
-               else
+                       if (!newsrv->id) {
+                               ha_alert("out of memory.\n");
+                               err_code |= ERR_ALERT | ERR_ABORT;
+                               goto out;
+                       }
+               }
+               else {
                        newsrv->tmpl_info.prefix = strdup(args[1]);
+                       if (!newsrv->tmpl_info.prefix) {
+                               ha_alert("out of memory.\n");
+                               err_code |= ERR_ALERT | ERR_ABORT;
+                               goto out;
+                       }
+               }
 
                /* several ways to check the port component :
                 *  - IP    => port=+0, relative (IPv4 only)