[PATCH 1/3] u32: prevent memcpy from NULL

Peter Wu peter at lekensteyn.nl
Tue Jun 24 14:13:36 PDT 2014


Found by Clang static analyzer.

Fixes: 6cdc32df831a273007af7d24a3f75cd06e0ae738
Signed-off-by: Peter Wu <peter at lekensteyn.nl>
---
 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;
-- 
2.0.0




More information about the libnl mailing list