[patch libnl] link: check retval of strdup in rtnl_link_set_ifalias

Jiri Pirko jpirko at redhat.com
Fri Nov 11 09:07:47 EST 2011


retval of strdup needs to be checked. So check it in
rtnl_link_set_ifalias and propagate error.

Signed-off-by: Jiri Pirko <jpirko at redhat.com>
---
 doc/route.txt                |    2 +-
 include/netlink/route/link.h |    2 +-
 lib/route/link.c             |    7 ++++++-
 python/netlink/route/capi.i  |    2 +-
 python/netlink/route/link.py |    4 +++-
 5 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/doc/route.txt b/doc/route.txt
index 33f58d0..0cd10e1 100644
--- a/doc/route.txt
+++ b/doc/route.txt
@@ -533,7 +533,7 @@ Alternative name for the link, primarly used for SNMP IfAlias.
 #include <netlink/route/link.h>
 
 const char *rtnl_link_get_ifalias(struct rtnl_link *link);
-void rtnl_link_set_ifalias(struct rtnl_link *link, const char *alias);
+int rtnl_link_set_ifalias(struct rtnl_link *link, const char *alias);
 -----
 
 *Length limit:* 256
diff --git a/include/netlink/route/link.h b/include/netlink/route/link.h
index 42ef7c8..2052467 100644
--- a/include/netlink/route/link.h
+++ b/include/netlink/route/link.h
@@ -186,7 +186,7 @@ extern void	rtnl_link_set_linkmode(struct rtnl_link *, uint8_t);
 extern uint8_t	rtnl_link_get_linkmode(struct rtnl_link *);
 
 extern const char *	rtnl_link_get_ifalias(struct rtnl_link *);
-extern void		rtnl_link_set_ifalias(struct rtnl_link *, const char *);
+extern int		rtnl_link_set_ifalias(struct rtnl_link *, const char *);
 
 extern int		rtnl_link_get_num_vf(struct rtnl_link *, uint32_t *);
 
diff --git a/lib/route/link.c b/lib/route/link.c
index ad5fcbe..0ab30ed 100644
--- a/lib/route/link.c
+++ b/lib/route/link.c
@@ -1854,16 +1854,21 @@ const char *rtnl_link_get_ifalias(struct rtnl_link *link)
  *
  * @route_doc{link_attr_alias, Alias}
  * @see rtnl_link_get_ifalias()
+ *
+ * @return 0 on success or a negative error code.
  */
-void rtnl_link_set_ifalias(struct rtnl_link *link, const char *alias)
+int 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);
+		if (!link->l_ifalias)
+			return -NLE_NOMEM;
 		link->ce_mask |= LINK_ATTR_IFALIAS;
 	}
+	return 0;
 }
 
 /**
diff --git a/python/netlink/route/capi.i b/python/netlink/route/capi.i
index ae3592d..031823c 100644
--- a/python/netlink/route/capi.i
+++ b/python/netlink/route/capi.i
@@ -135,7 +135,7 @@ extern void rtnl_link_set_linkmode(struct rtnl_link *, uint8_t);
 extern uint8_t rtnl_link_get_linkmode(struct rtnl_link *);
 
 extern const char *rtnl_link_get_ifalias(struct rtnl_link *);
-extern void rtnl_link_set_ifalias(struct rtnl_link *, const char *);
+extern int rtnl_link_set_ifalias(struct rtnl_link *, const char *);
 
 extern int rtnl_link_get_num_vf(struct rtnl_link *, uint32_t *);
 
diff --git a/python/netlink/route/link.py b/python/netlink/route/link.py
index e613f2e..5925a3c 100644
--- a/python/netlink/route/link.py
+++ b/python/netlink/route/link.py
@@ -378,7 +378,9 @@ class Link(netlink.Object):
 
 	@alias.setter
         def alias(self, value):
-                capi.rtnl_link_set_ifalias(self._rtnl_link, value)
+                ret = capi.rtnl_link_set_ifalias(self._rtnl_link, value)
+                if ret < 0:
+                        raise netlink.KernelError(ret)
 
 	#####################################################################
 	# type
-- 
1.7.6




More information about the libnl mailing list