netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Phil Sutter <phil@nwl.cc>
To: Stephen Hemminger <stephen@networkplumber.org>
Cc: netdev@vger.kernel.org
Subject: [iproute PATCH 3/6] Convert harmful calls to strncpy() to strlcpy()
Date: Fri,  1 Sep 2017 18:52:53 +0200	[thread overview]
Message-ID: <20170901165256.21459-4-phil@nwl.cc> (raw)
In-Reply-To: <20170901165256.21459-1-phil@nwl.cc>

This patch converts spots where manual buffer termination was missing to
strlcpy() since that does what is needed.

Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 genl/ctrl.c     | 2 +-
 ip/ipvrf.c      | 2 +-
 ip/xfrm_state.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/genl/ctrl.c b/genl/ctrl.c
index 6abd52582d0d3..448988eb90e2b 100644
--- a/genl/ctrl.c
+++ b/genl/ctrl.c
@@ -313,7 +313,7 @@ static int ctrl_list(int cmd, int argc, char **argv)
 
 		if (matches(*argv, "name") == 0) {
 			NEXT_ARG();
-			strncpy(d, *argv, sizeof (d) - 1);
+			strlcpy(d, *argv, sizeof(d));
 			addattr_l(nlh, 128, CTRL_ATTR_FAMILY_NAME,
 				  d, strlen(d) + 1);
 		} else if (matches(*argv, "id") == 0) {
diff --git a/ip/ipvrf.c b/ip/ipvrf.c
index b74c501e0970c..f9277e1e66bdf 100644
--- a/ip/ipvrf.c
+++ b/ip/ipvrf.c
@@ -74,7 +74,7 @@ static int vrf_identify(pid_t pid, char *name, size_t len)
 			if (end)
 				*end = '\0';
 
-			strncpy(name, vrf, len - 1);
+			strlcpy(name, vrf, len);
 			break;
 		}
 	}
diff --git a/ip/xfrm_state.c b/ip/xfrm_state.c
index e11c93bf1c3b5..4483fb8f71d2c 100644
--- a/ip/xfrm_state.c
+++ b/ip/xfrm_state.c
@@ -125,7 +125,7 @@ static int xfrm_algo_parse(struct xfrm_algo *alg, enum xfrm_attr_type_t type,
 	fprintf(stderr, "warning: ALGO-NAME/ALGO-KEYMAT values will be sent to the kernel promiscuously! (verifying them isn't implemented yet)\n");
 #endif
 
-	strncpy(alg->alg_name, name, sizeof(alg->alg_name));
+	strlcpy(alg->alg_name, name, sizeof(alg->alg_name));
 
 	if (slen > 2 && strncmp(key, "0x", 2) == 0) {
 		/* split two chars "0x" from the top */
-- 
2.13.1

  parent reply	other threads:[~2017-09-01 16:53 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-01 16:52 [iproute PATCH 0/6] strlcpy() and strlcat() for iproute2 Phil Sutter
2017-09-01 16:52 ` [iproute PATCH 1/6] utils: Implement strlcpy() and strlcat() Phil Sutter
2017-09-04 14:49   ` David Laight
2017-09-04 15:00     ` Phil Sutter
2017-09-04 18:25       ` Stephen Hemminger
2017-09-06 13:59         ` David Laight
2017-09-06 15:25           ` Stephen Hemminger
2017-09-06 16:51           ` [iproute PATCH] utils: Review " Phil Sutter
2017-09-01 16:52 ` [iproute PATCH 2/6] Convert the obvious cases to strlcpy() Phil Sutter
2017-09-01 19:13   ` Daniel Borkmann
2017-09-01 16:52 ` Phil Sutter [this message]
2017-09-01 16:52 ` [iproute PATCH 4/6] ipxfrm: Replace STRBUF_CAT macro with strlcat() Phil Sutter
2017-09-01 16:52 ` [iproute PATCH 5/6] tc_util: No need to terminate an snprintf'ed buffer Phil Sutter
2017-09-01 16:52 ` [iproute PATCH 6/6] lnstat_util: Make sure buffer is NUL-terminated Phil Sutter
2017-09-01 19:12 ` [iproute PATCH 0/6] strlcpy() and strlcat() for iproute2 Stephen Hemminger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170901165256.21459-4-phil@nwl.cc \
    --to=phil@nwl.cc \
    --cc=netdev@vger.kernel.org \
    --cc=stephen@networkplumber.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).