From 2ca01afceeb224d3a5d6f6a1d0eff741337da05d Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Tue, 24 Jun 2014 23:13:36 +0200 Subject: u32: prevent memcpy from NULL Found by Clang static analyzer. Fixes: 6cdc32df831a273007af7d24a3f75cd06e0ae738 Signed-off-by: Peter Wu Signed-off-by: Thomas Haller --- lib/route/cls/u32.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/route/cls/u32.c b/lib/route/cls/u32.c index e91c39a..0a4e83c 100644 --- a/lib/route/cls/u32.c +++ b/lib/route/cls/u32.c @@ -170,9 +170,12 @@ static int u32_clone(void *_dst, void *_src) !(dst->cu_selector = nl_data_clone(src->cu_selector))) return -NLE_NOMEM; - if (src->cu_act && !(dst->cu_act = rtnl_act_alloc())) - return -NLE_NOMEM; - memcpy(dst->cu_act, src->cu_act, sizeof(struct rtnl_act)); + if (src->cu_act) { + if (!(dst->cu_act = rtnl_act_alloc())) + return -NLE_NOMEM; + + memcpy(dst->cu_act, src->cu_act, sizeof(struct rtnl_act)); + } if (src->cu_police && !(dst->cu_police = nl_data_clone(src->cu_police))) return -NLE_NOMEM; -- cgit v0.12 From 8e052f59f431844ff6576dcf7b47293ab4ef45aa Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Tue, 24 Jun 2014 23:13:37 +0200 Subject: attr: prevent garbage return value for NULL param If nla is not given, then tmp is not set. Explicitly initalize with 0 to prevent garbage values. Found by Clang static analyzer. Signed-off-by: Peter Wu Signed-off-by: Thomas Haller --- lib/attr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/attr.c b/lib/attr.c index 66c029c..d3de399 100644 --- a/lib/attr.c +++ b/lib/attr.c @@ -648,7 +648,7 @@ int nla_put_u64(struct nl_msg *msg, int attrtype, uint64_t value) */ uint64_t nla_get_u64(struct nlattr *nla) { - uint64_t tmp; + uint64_t tmp = 0; nla_memcpy(&tmp, nla, sizeof(tmp)); -- cgit v0.12 From a8b352a4c50b0e44d53c5a74388f942523224171 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Tue, 24 Jun 2014 23:13:38 +0200 Subject: attr: fix compile warning in headers strlen() returns a size_t type, but nla_put accepts an int only. This breaks a -Werror build of applications using libnl, so avoid this warning by explicitly casting the length to an int. Signed-off-by: Peter Wu Signed-off-by: Thomas Haller --- include/netlink/attr.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/netlink/attr.h b/include/netlink/attr.h index 0ed3da3..82e4c38 100644 --- a/include/netlink/attr.h +++ b/include/netlink/attr.h @@ -205,7 +205,7 @@ extern int nla_is_nested(struct nlattr *); * @arg value NUL terminated character string. */ #define NLA_PUT_STRING(msg, attrtype, value) \ - NLA_PUT(msg, attrtype, strlen(value) + 1, value) + NLA_PUT(msg, attrtype, (int) strlen(value) + 1, value) /** * Add flag attribute to netlink message. -- cgit v0.12