ip: use strlcpy() to avoid truncation

This fixes gcc-8 warnings about strncpy bounds by using
strlcpy instead.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
This commit is contained in:
Stephen Hemminger 2018-03-19 09:31:09 -07:00
parent 95744efac4
commit fc9d755a3e
1 changed files with 7 additions and 7 deletions

View File

@ -1114,7 +1114,7 @@ static int do_chflags(const char *dev, __u32 flags, __u32 mask)
int fd; int fd;
int err; int err;
strncpy(ifr.ifr_name, dev, IFNAMSIZ); strlcpy(ifr.ifr_name, dev, IFNAMSIZ);
fd = get_ctl_fd(); fd = get_ctl_fd();
if (fd < 0) if (fd < 0)
return -1; return -1;
@ -1141,8 +1141,8 @@ static int do_changename(const char *dev, const char *newdev)
int fd; int fd;
int err; int err;
strncpy(ifr.ifr_name, dev, IFNAMSIZ); strlcpy(ifr.ifr_name, dev, IFNAMSIZ);
strncpy(ifr.ifr_newname, newdev, IFNAMSIZ); strlcpy(ifr.ifr_newname, newdev, IFNAMSIZ);
fd = get_ctl_fd(); fd = get_ctl_fd();
if (fd < 0) if (fd < 0)
return -1; return -1;
@ -1165,7 +1165,7 @@ static int set_qlen(const char *dev, int qlen)
if (s < 0) if (s < 0)
return -1; return -1;
strncpy(ifr.ifr_name, dev, IFNAMSIZ); strlcpy(ifr.ifr_name, dev, IFNAMSIZ);
if (ioctl(s, SIOCSIFTXQLEN, &ifr) < 0) { if (ioctl(s, SIOCSIFTXQLEN, &ifr) < 0) {
perror("SIOCSIFXQLEN"); perror("SIOCSIFXQLEN");
close(s); close(s);
@ -1185,7 +1185,7 @@ static int set_mtu(const char *dev, int mtu)
if (s < 0) if (s < 0)
return -1; return -1;
strncpy(ifr.ifr_name, dev, IFNAMSIZ); strlcpy(ifr.ifr_name, dev, IFNAMSIZ);
if (ioctl(s, SIOCSIFMTU, &ifr) < 0) { if (ioctl(s, SIOCSIFMTU, &ifr) < 0) {
perror("SIOCSIFMTU"); perror("SIOCSIFMTU");
close(s); close(s);
@ -1212,7 +1212,7 @@ static int get_address(const char *dev, int *htype)
return -1; return -1;
} }
strncpy(ifr.ifr_name, dev, IFNAMSIZ); strlcpy(ifr.ifr_name, dev, IFNAMSIZ);
if (ioctl(s, SIOCGIFINDEX, &ifr) < 0) { if (ioctl(s, SIOCGIFINDEX, &ifr) < 0) {
perror("SIOCGIFINDEX"); perror("SIOCGIFINDEX");
close(s); close(s);
@ -1243,7 +1243,7 @@ static int parse_address(const char *dev, int hatype, int halen,
int alen; int alen;
memset(ifr, 0, sizeof(*ifr)); memset(ifr, 0, sizeof(*ifr));
strncpy(ifr->ifr_name, dev, IFNAMSIZ); strlcpy(ifr->ifr_name, dev, IFNAMSIZ);
ifr->ifr_hwaddr.sa_family = hatype; ifr->ifr_hwaddr.sa_family = hatype;
alen = ll_addr_a2n(ifr->ifr_hwaddr.sa_data, 14, lla); alen = ll_addr_a2n(ifr->ifr_hwaddr.sa_data, 14, lla);
if (alen < 0) if (alen < 0)