]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: namespace: handle a possible strdup() failure
authorIlia Shipitsin <chipitsine@gmail.com>
Tue, 3 Dec 2024 16:10:21 +0000 (17:10 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 10 Dec 2024 07:05:34 +0000 (08:05 +0100)
This defect was found by the coccinelle script "unchecked-strdup.cocci".
It can be backported to all supported branches.

src/namespace.c

index 9cc85a38477919d8a0f0c65a324b5719d6142075..38464bd4cfdd00d66ac4700f273224feecfe37f2 100644 (file)
@@ -89,13 +89,23 @@ struct netns_entry* netns_store_insert(const char *ns_name)
 
        entry = calloc(1, sizeof(*entry));
        if (!entry)
-               goto out;
+               goto err_close_fd;
        entry->fd = fd;
        entry->node.key = strdup(ns_name);
+       if (!entry->node.key)
+               goto err_free_entry;
+
        entry->name_len = strlen(ns_name);
        ebis_insert(&namespace_tree_root, &entry->node);
 out:
        return entry;
+
+/* free all allocated stuff and return entry */
+err_free_entry:
+       ha_free(&entry);
+err_close_fd:
+       close(fd);
+       return entry;
 }
 
 const struct netns_entry* netns_store_lookup(const char *ns_name, size_t ns_name_len)