From: Stephen Hemminger <stephen@networkplumber.org>
To: netdev@vger.kernel.org
Cc: Stephen Hemminger <stephen@networkplumber.org>
Subject: [PATCH iproute2 v2 3/9] ip: use strlcpy() to avoid truncation
Date: Tue, 20 Mar 2018 13:29:03 -0700 [thread overview]
Message-ID: <20180320202909.22166-4-stephen@networkplumber.org> (raw)
In-Reply-To: <20180320202909.22166-1-stephen@networkplumber.org>
This fixes gcc-8 warnings about strncpy bounds by using
strlcpy instead.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
ip/iplink.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/ip/iplink.c b/ip/iplink.c
index d401311bcad9..cca530eeeb09 100644
--- a/ip/iplink.c
+++ b/ip/iplink.c
@@ -1114,7 +1114,7 @@ static int do_chflags(const char *dev, __u32 flags, __u32 mask)
int fd;
int err;
- strncpy(ifr.ifr_name, dev, IFNAMSIZ);
+ strlcpy(ifr.ifr_name, dev, IFNAMSIZ);
fd = get_ctl_fd();
if (fd < 0)
return -1;
@@ -1141,8 +1141,8 @@ static int do_changename(const char *dev, const char *newdev)
int fd;
int err;
- strncpy(ifr.ifr_name, dev, IFNAMSIZ);
- strncpy(ifr.ifr_newname, newdev, IFNAMSIZ);
+ strlcpy(ifr.ifr_name, dev, IFNAMSIZ);
+ strlcpy(ifr.ifr_newname, newdev, IFNAMSIZ);
fd = get_ctl_fd();
if (fd < 0)
return -1;
@@ -1165,7 +1165,7 @@ static int set_qlen(const char *dev, int qlen)
if (s < 0)
return -1;
- strncpy(ifr.ifr_name, dev, IFNAMSIZ);
+ strlcpy(ifr.ifr_name, dev, IFNAMSIZ);
if (ioctl(s, SIOCSIFTXQLEN, &ifr) < 0) {
perror("SIOCSIFXQLEN");
close(s);
@@ -1185,7 +1185,7 @@ static int set_mtu(const char *dev, int mtu)
if (s < 0)
return -1;
- strncpy(ifr.ifr_name, dev, IFNAMSIZ);
+ strlcpy(ifr.ifr_name, dev, IFNAMSIZ);
if (ioctl(s, SIOCSIFMTU, &ifr) < 0) {
perror("SIOCSIFMTU");
close(s);
@@ -1212,7 +1212,7 @@ static int get_address(const char *dev, int *htype)
return -1;
}
- strncpy(ifr.ifr_name, dev, IFNAMSIZ);
+ strlcpy(ifr.ifr_name, dev, IFNAMSIZ);
if (ioctl(s, SIOCGIFINDEX, &ifr) < 0) {
perror("SIOCGIFINDEX");
close(s);
@@ -1243,7 +1243,7 @@ static int parse_address(const char *dev, int hatype, int halen,
int alen;
memset(ifr, 0, sizeof(*ifr));
- strncpy(ifr->ifr_name, dev, IFNAMSIZ);
+ strlcpy(ifr->ifr_name, dev, IFNAMSIZ);
ifr->ifr_hwaddr.sa_family = hatype;
alen = ll_addr_a2n(ifr->ifr_hwaddr.sa_data, 14, lla);
if (alen < 0)
--
2.16.2
next prev parent reply other threads:[~2018-03-20 20:29 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-20 20:29 [PATCH iproute2 v2 0/9] gcc-8 warning fixes Stephen Hemminger
2018-03-20 20:29 ` [PATCH iproute2 v2 1/9] bridge: avoid snprint truncation on time Stephen Hemminger
2018-03-20 20:29 ` [PATCH iproute2 v2 2/9] pedit: fix strncpy warning Stephen Hemminger
2018-03-20 20:29 ` Stephen Hemminger [this message]
2018-03-20 20:29 ` [PATCH iproute2 v2 4/9] tunnel: use strlcpy to avoid strncpy warnings Stephen Hemminger
2018-03-20 20:29 ` [PATCH iproute2 v2 5/9] namespace: fix warning snprintf buffer Stephen Hemminger
2018-03-21 9:21 ` Sergei Shtylyov
2018-03-20 20:29 ` [PATCH iproute2 v2 6/9] tc_class: fix snprintf warning Stephen Hemminger
2018-03-20 20:29 ` [PATCH iproute2 v2 7/9] ematch: fix possible snprintf overflow Stephen Hemminger
2018-03-20 20:29 ` [PATCH iproute2 v2 8/9] misc: avoid snprintf warnings in ss and nstat Stephen Hemminger
2018-03-20 20:29 ` [PATCH iproute2 v2 9/9] bpf: avoid compiler warnings about strncpy Stephen Hemminger
2018-03-20 21:12 ` Daniel Borkmann
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=20180320202909.22166-4-stephen@networkplumber.org \
--to=stephen@networkplumber.org \
--cc=netdev@vger.kernel.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