naccyde / rpms / iproute

Forked from rpms/iproute 7 months ago
Clone

Blame SOURCES/0119-Convert-harmful-calls-to-strncpy-to-strlcpy.patch

36cfb7
From 9556150792daf8f2fbea934bcb77b4b74a21b2e1 Mon Sep 17 00:00:00 2001
36cfb7
From: Andrea Claudi <aclaudi@redhat.com>
36cfb7
Date: Mon, 29 Apr 2019 20:09:12 +0200
36cfb7
Subject: [PATCH] Convert harmful calls to strncpy() to strlcpy()
36cfb7
36cfb7
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1465646
36cfb7
Upstream Status: iproute2.git commit 532b8874fe545
36cfb7
36cfb7
commit 532b8874fe545acaa8d45c4dd3b54b8f3bb41d9f
36cfb7
Author: Phil Sutter <phil@nwl.cc>
36cfb7
Date:   Fri Sep 1 18:52:53 2017 +0200
36cfb7
36cfb7
    Convert harmful calls to strncpy() to strlcpy()
36cfb7
36cfb7
    This patch converts spots where manual buffer termination was missing to
36cfb7
    strlcpy() since that does what is needed.
36cfb7
36cfb7
    Signed-off-by: Phil Sutter <phil@nwl.cc>
36cfb7
---
36cfb7
 genl/ctrl.c     | 2 +-
36cfb7
 ip/ipvrf.c      | 2 +-
36cfb7
 ip/xfrm_state.c | 2 +-
36cfb7
 3 files changed, 3 insertions(+), 3 deletions(-)
36cfb7
36cfb7
diff --git a/genl/ctrl.c b/genl/ctrl.c
36cfb7
index 21e857cfcfc25..a6d31b04e5679 100644
36cfb7
--- a/genl/ctrl.c
36cfb7
+++ b/genl/ctrl.c
36cfb7
@@ -317,7 +317,7 @@ static int ctrl_list(int cmd, int argc, char **argv)
36cfb7
 
36cfb7
 		if (matches(*argv, "name") == 0) {
36cfb7
 			NEXT_ARG();
36cfb7
-			strncpy(d, *argv, sizeof (d) - 1);
36cfb7
+			strlcpy(d, *argv, sizeof(d));
36cfb7
 			addattr_l(nlh, 128, CTRL_ATTR_FAMILY_NAME,
36cfb7
 				  d, strlen(d) + 1);
36cfb7
 		} else if (matches(*argv, "id") == 0) {
36cfb7
diff --git a/ip/ipvrf.c b/ip/ipvrf.c
36cfb7
index f58c8df728265..406cddbcd44ca 100644
36cfb7
--- a/ip/ipvrf.c
36cfb7
+++ b/ip/ipvrf.c
36cfb7
@@ -71,7 +71,7 @@ static int vrf_identify(pid_t pid, char *name, size_t len)
36cfb7
 			if (end)
36cfb7
 				*end = '\0';
36cfb7
 
36cfb7
-			strncpy(name, vrf, len - 1);
36cfb7
+			strlcpy(name, vrf, len);
36cfb7
 			break;
36cfb7
 		}
36cfb7
 	}
36cfb7
diff --git a/ip/xfrm_state.c b/ip/xfrm_state.c
36cfb7
index 04ed3492ad3b5..2222737cdd98d 100644
36cfb7
--- a/ip/xfrm_state.c
36cfb7
+++ b/ip/xfrm_state.c
36cfb7
@@ -123,7 +123,7 @@ static int xfrm_algo_parse(struct xfrm_algo *alg, enum xfrm_attr_type_t type,
36cfb7
 	fprintf(stderr, "warning: ALGO-NAME/ALGO-KEYMAT values will be sent to the kernel promiscuously! (verifying them isn't implemented yet)\n");
36cfb7
 #endif
36cfb7
 
36cfb7
-	strncpy(alg->alg_name, name, sizeof(alg->alg_name));
36cfb7
+	strlcpy(alg->alg_name, name, sizeof(alg->alg_name));
36cfb7
 
36cfb7
 	if (slen > 2 && strncmp(key, "0x", 2) == 0) {
36cfb7
 		/* split two chars "0x" from the top */
36cfb7
-- 
e138d9
2.21.0
36cfb7