[PATCH 7/9] route/link: fix dangling pointer after rtnl_link_get_ifalias(link, NULL)

Thomas Haller thaller at redhat.com
Tue Jun 10 09:59:43 PDT 2014


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.

Signed-off-by: Thomas Haller <thaller at redhat.com>
---
 lib/route/link.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

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;
 	}
 }
 
-- 
1.9.3




More information about the libnl mailing list