naccyde / rpms / iproute

Forked from rpms/iproute 7 months ago
Clone

Blame SOURCES/0116-lib-libnetlink-Don-t-pass-NULL-parameter-to-memcpy.patch

36cfb7
From 8af39fdff4f966d00571bda2610eac8fae2f7482 Mon Sep 17 00:00:00 2001
36cfb7
From: Andrea Claudi <aclaudi@redhat.com>
36cfb7
Date: Mon, 29 Apr 2019 20:08:08 +0200
36cfb7
Subject: [PATCH] lib/libnetlink: Don't pass NULL parameter to memcpy()
36cfb7
36cfb7
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1465646
36cfb7
Upstream Status: iproute2.git commit 893deac4c43b5
36cfb7
36cfb7
commit 893deac4c43b57ae49f736ec050724b6de181062
36cfb7
Author: Phil Sutter <phil@nwl.cc>
36cfb7
Date:   Thu Aug 24 11:41:31 2017 +0200
36cfb7
36cfb7
    lib/libnetlink: Don't pass NULL parameter to memcpy()
36cfb7
36cfb7
    Both addattr_l() and rta_addattr_l() may be called with NULL data
36cfb7
    pointer and 0 alen parameters. Avoid calling memcpy() in that case.
36cfb7
36cfb7
    Signed-off-by: Phil Sutter <phil@nwl.cc>
36cfb7
---
36cfb7
 lib/libnetlink.c | 6 ++++--
36cfb7
 1 file changed, 4 insertions(+), 2 deletions(-)
36cfb7
36cfb7
diff --git a/lib/libnetlink.c b/lib/libnetlink.c
36cfb7
index 75e20abf0b97f..ff26ddf50552b 100644
36cfb7
--- a/lib/libnetlink.c
36cfb7
+++ b/lib/libnetlink.c
36cfb7
@@ -898,7 +898,8 @@ int addattr_l(struct nlmsghdr *n, int maxlen, int type, const void *data,
36cfb7
 	rta = NLMSG_TAIL(n);
36cfb7
 	rta->rta_type = type;
36cfb7
 	rta->rta_len = len;
36cfb7
-	memcpy(RTA_DATA(rta), data, alen);
36cfb7
+	if (alen)
36cfb7
+		memcpy(RTA_DATA(rta), data, alen);
36cfb7
 	n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + RTA_ALIGN(len);
36cfb7
 	return 0;
36cfb7
 }
36cfb7
@@ -985,7 +986,8 @@ int rta_addattr_l(struct rtattr *rta, int maxlen, int type,
36cfb7
 	subrta = (struct rtattr *)(((char *)rta) + RTA_ALIGN(rta->rta_len));
36cfb7
 	subrta->rta_type = type;
36cfb7
 	subrta->rta_len = len;
36cfb7
-	memcpy(RTA_DATA(subrta), data, alen);
36cfb7
+	if (alen)
36cfb7
+		memcpy(RTA_DATA(subrta), data, alen);
36cfb7
 	rta->rta_len = NLMSG_ALIGN(rta->rta_len) + RTA_ALIGN(len);
36cfb7
 	return 0;
36cfb7
 }
36cfb7
-- 
e138d9
2.21.0
36cfb7