]> granicus.if.org Git - libnl/commitdiff
route/link: fix dangling pointer after rtnl_link_get_ifalias(link, NULL)
authorThomas Haller <thaller@redhat.com>
Tue, 10 Jun 2014 15:50:09 +0000 (17:50 +0200)
committerThomas Haller <thaller@redhat.com>
Tue, 10 Jun 2014 19:45:52 +0000 (21:45 +0200)
Fixed bug that left a dangling pointer after clearing the ifalias
property. This happened when calling 'rtnl_link_get_ifalias(link, NULL)'
on a link that has already an ifalias set.

This can cause a crash and/or a double-free.

Error found by coverity.

Acked-by: Thomas Graf <tgraf@suug.ch>
Signed-off-by: Thomas Haller <thaller@redhat.com>
lib/route/link.c

index 65e42ec9ec4cc79f153316c5a3f43d85ed2a3edb..3d31ffcbc55451f7d8f77a9d3cf5daee179f8902 100644 (file)
@@ -2102,11 +2102,13 @@ const char *rtnl_link_get_ifalias(struct rtnl_link *link)
 void rtnl_link_set_ifalias(struct rtnl_link *link, const char *alias)
 {
        free(link->l_ifalias);
-       link->ce_mask &= ~LINK_ATTR_IFALIAS;
 
        if (alias) {
                link->l_ifalias = strdup(alias);
                link->ce_mask |= LINK_ATTR_IFALIAS;
+       } else {
+               link->l_ifalias = NULL;
+               link->ce_mask &= ~LINK_ATTR_IFALIAS;
        }
 }