naccyde / rpms / iproute

Forked from rpms/iproute 9 months ago
Clone

Blame SOURCES/0118-Convert-the-obvious-cases-to-strlcpy.patch

36cfb7
From e557cf7984d2f06aff158a9089e714e5f445d3ac 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] Convert the obvious cases to strlcpy()
36cfb7
36cfb7
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1465646
36cfb7
Upstream Status: iproute2.git commit 18f156bfecda2
36cfb7
Conflicts:
36cfb7
* on iproute_lwtunnel.c, due to missing commit
36cfb7
  e8493916a8ede ("iproute: add support for SR-IPv6 lwtunnel encapsulation")
36cfb7
* on lib/bpf.c, due to missing commit
36cfb7
  95ae9a4870e7d ("bpf: fix mnt path when from env")
36cfb7
  fix bpf_find_mntpt() in this case, instead.
36cfb7
36cfb7
commit 18f156bfecda20166c2fb543ba8c9c6559edef9c
36cfb7
Author: Phil Sutter <phil@nwl.cc>
36cfb7
Date:   Fri Sep 1 18:52:52 2017 +0200
36cfb7
36cfb7
    Convert the obvious cases to strlcpy()
36cfb7
36cfb7
    This converts the typical idiom of manually terminating the buffer after
36cfb7
    a call to strncpy().
36cfb7
36cfb7
    Signed-off-by: Phil Sutter <phil@nwl.cc>
36cfb7
---
36cfb7
 ip/ipnetns.c     | 3 +--
36cfb7
 ip/ipvrf.c       | 3 +--
36cfb7
 lib/bpf.c        | 3 +--
36cfb7
 lib/fs.c         | 3 +--
36cfb7
 lib/inet_proto.c | 3 +--
36cfb7
 misc/ss.c        | 3 +--
36cfb7
 tc/em_ipset.c    | 3 +--
36cfb7
 7 files changed, 7 insertions(+), 14 deletions(-)
36cfb7
36cfb7
diff --git a/ip/ipnetns.c b/ip/ipnetns.c
36cfb7
index 1c0ade90dee5e..427b59c57381d 100644
36cfb7
--- a/ip/ipnetns.c
36cfb7
+++ b/ip/ipnetns.c
36cfb7
@@ -523,8 +523,7 @@ int netns_identify_pid(const char *pidstr, char *name, int len)
36cfb7
 
36cfb7
 		if ((st.st_dev == netst.st_dev) &&
36cfb7
 		    (st.st_ino == netst.st_ino)) {
36cfb7
-			strncpy(name, entry->d_name, len - 1);
36cfb7
-			name[len - 1] = '\0';
36cfb7
+			strlcpy(name, entry->d_name, len);
36cfb7
 		}
36cfb7
 	}
36cfb7
 	closedir(dir);
36cfb7
diff --git a/ip/ipvrf.c b/ip/ipvrf.c
36cfb7
index ae3b48fa81996..f58c8df728265 100644
36cfb7
--- a/ip/ipvrf.c
36cfb7
+++ b/ip/ipvrf.c
36cfb7
@@ -333,8 +333,7 @@ static int vrf_path(char *vpath, size_t len)
36cfb7
 		if (vrf)
36cfb7
 			*vrf = '\0';
36cfb7
 
36cfb7
-		strncpy(vpath, start, len - 1);
36cfb7
-		vpath[len - 1] = '\0';
36cfb7
+		strlcpy(vpath, start, len);
36cfb7
 
36cfb7
 		/* if vrf path is just / then return nothing */
36cfb7
 		if (!strcmp(vpath, "/"))
36cfb7
diff --git a/lib/bpf.c b/lib/bpf.c
36cfb7
index 7eb754ad7cb56..e072cba214067 100644
36cfb7
--- a/lib/bpf.c
36cfb7
+++ b/lib/bpf.c
36cfb7
@@ -424,8 +424,7 @@ static const char *bpf_find_mntpt(const char *fstype, unsigned long magic,
36cfb7
 		ptr = known_mnts;
36cfb7
 		while (*ptr) {
36cfb7
 			if (bpf_valid_mntpt(*ptr, magic) == 0) {
36cfb7
-				strncpy(mnt, *ptr, len - 1);
36cfb7
-				mnt[len - 1] = 0;
36cfb7
+				strlcpy(mnt, *ptr, len);
36cfb7
 				return mnt;
36cfb7
 			}
36cfb7
 			ptr++;
36cfb7
diff --git a/lib/fs.c b/lib/fs.c
36cfb7
index ebe05cd44e11b..86efd4ed2ed80 100644
36cfb7
--- a/lib/fs.c
36cfb7
+++ b/lib/fs.c
36cfb7
@@ -172,8 +172,7 @@ int get_command_name(const char *pid, char *comm, size_t len)
36cfb7
 		if (nl)
36cfb7
 			*nl = '\0';
36cfb7
 
36cfb7
-		strncpy(comm, name, len - 1);
36cfb7
-		comm[len - 1] = '\0';
36cfb7
+		strlcpy(comm, name, len);
36cfb7
 		break;
36cfb7
 	}
36cfb7
 
36cfb7
diff --git a/lib/inet_proto.c b/lib/inet_proto.c
36cfb7
index 53c029039b6d5..bdfd52fdafe5a 100644
36cfb7
--- a/lib/inet_proto.c
36cfb7
+++ b/lib/inet_proto.c
36cfb7
@@ -38,8 +38,7 @@ const char *inet_proto_n2a(int proto, char *buf, int len)
36cfb7
 			free(ncache);
36cfb7
 		icache = proto;
36cfb7
 		ncache = strdup(pe->p_name);
36cfb7
-		strncpy(buf, pe->p_name, len - 1);
36cfb7
-		buf[len - 1] = '\0';
36cfb7
+		strlcpy(buf, pe->p_name, len);
36cfb7
 		return buf;
36cfb7
 	}
36cfb7
 	snprintf(buf, len, "ipproto-%d", proto);
36cfb7
diff --git a/misc/ss.c b/misc/ss.c
36cfb7
index fdb00a9f3f696..6aaae1b5390e4 100644
36cfb7
--- a/misc/ss.c
36cfb7
+++ b/misc/ss.c
36cfb7
@@ -444,8 +444,7 @@ static void user_ent_hash_build(void)
36cfb7
 
36cfb7
 	user_ent_hash_build_init = 1;
36cfb7
 
36cfb7
-	strncpy(name, root, sizeof(name)-1);
36cfb7
-	name[sizeof(name)-1] = 0;
36cfb7
+	strlcpy(name, root, sizeof(name));
36cfb7
 
36cfb7
 	if (strlen(name) == 0 || name[strlen(name)-1] != '/')
36cfb7
 		strcat(name, "/");
36cfb7
diff --git a/tc/em_ipset.c b/tc/em_ipset.c
36cfb7
index b59756515d239..48b287f5ba3b2 100644
36cfb7
--- a/tc/em_ipset.c
36cfb7
+++ b/tc/em_ipset.c
36cfb7
@@ -145,8 +145,7 @@ get_set_byname(const char *setname, struct xt_set_info *info)
36cfb7
 	int res;
36cfb7
 
36cfb7
 	req.op = IP_SET_OP_GET_BYNAME;
36cfb7
-	strncpy(req.set.name, setname, IPSET_MAXNAMELEN);
36cfb7
-	req.set.name[IPSET_MAXNAMELEN - 1] = '\0';
36cfb7
+	strlcpy(req.set.name, setname, IPSET_MAXNAMELEN);
36cfb7
 	res = do_getsockopt(&req;;
36cfb7
 	if (res != 0)
36cfb7
 		return -1;
36cfb7
-- 
e138d9
2.21.0
36cfb7