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 <tgraf@suug.ch> Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
parent
dae0a2316e
commit
d7a9e74f82
1 changed files with 3 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue