From: Thomas Haller Date: Tue, 10 Jun 2014 15:50:09 +0000 (+0200) Subject: route/link: fix dangling pointer after rtnl_link_get_ifalias(link, NULL) X-Git-Tag: libnl3_2_25rc1~11^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d7a9e74f82d136d1e3fa4e174e8b7ba9595ec9a9;p=libnl route/link: fix dangling pointer after rtnl_link_get_ifalias(link, NULL) 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 Signed-off-by: Thomas Haller --- diff --git a/lib/route/link.c b/lib/route/link.c index 65e42ec..3d31ffc 100644 --- a/lib/route/link.c +++ b/lib/route/link.c @@ -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; } }