Commit 5da6aa8c by Dwight Engen Committed by Serge Hallyn

coverity: ifr_name buffer not NULL terminated

The kernel (net/core/dev_ioctl.c:dev_ioctl()) is going to NULL terminate this name after the copy-in of the ifr, so even though this is a fixed sized array the last byte isn't usable as part of the name. All the ioctls we're using go through this code path. Use the ifr name in the DEBUG message in case it was possibly truncated. Signed-off-by: 's avatarDwight Engen <dwight.engen@oracle.com> Signed-off-by: 's avatarSerge Hallyn <serge.hallyn@ubuntu.com>
parent e853a32d
...@@ -2059,6 +2059,7 @@ static int setup_hw_addr(char *hwaddr, const char *ifname) ...@@ -2059,6 +2059,7 @@ static int setup_hw_addr(char *hwaddr, const char *ifname)
} }
memcpy(ifr.ifr_name, ifname, IFNAMSIZ); memcpy(ifr.ifr_name, ifname, IFNAMSIZ);
ifr.ifr_name[IFNAMSIZ-1] = '\0';
memcpy((char *) &ifr.ifr_hwaddr, (char *) &sockaddr, sizeof(sockaddr)); memcpy((char *) &ifr.ifr_hwaddr, (char *) &sockaddr, sizeof(sockaddr));
process_lock(); process_lock();
...@@ -2076,7 +2077,7 @@ static int setup_hw_addr(char *hwaddr, const char *ifname) ...@@ -2076,7 +2077,7 @@ static int setup_hw_addr(char *hwaddr, const char *ifname)
if (ret) if (ret)
ERROR("ioctl failure : %s", strerror(errno)); ERROR("ioctl failure : %s", strerror(errno));
DEBUG("mac address '%s' on '%s' has been setup", hwaddr, ifname); DEBUG("mac address '%s' on '%s' has been setup", hwaddr, ifr.ifr_name);
return ret; return ret;
} }
......
...@@ -473,7 +473,8 @@ int lxc_bridge_attach(const char *bridge, const char *ifname) ...@@ -473,7 +473,8 @@ int lxc_bridge_attach(const char *bridge, const char *ifname)
if (fd < 0) if (fd < 0)
return -errno; return -errno;
strncpy(ifr.ifr_name, bridge, IFNAMSIZ); strncpy(ifr.ifr_name, bridge, IFNAMSIZ-1);
ifr.ifr_name[IFNAMSIZ-1] = '\0';
ifr.ifr_ifindex = index; ifr.ifr_ifindex = index;
err = ioctl(fd, SIOCBRADDIF, &ifr); err = ioctl(fd, SIOCBRADDIF, &ifr);
close(fd); close(fd);
......
...@@ -1009,7 +1009,8 @@ int lxc_bridge_attach(const char *bridge, const char *ifname) ...@@ -1009,7 +1009,8 @@ int lxc_bridge_attach(const char *bridge, const char *ifname)
if (fd < 0) if (fd < 0)
return -errno; return -errno;
strncpy(ifr.ifr_name, bridge, IFNAMSIZ); strncpy(ifr.ifr_name, bridge, IFNAMSIZ-1);
ifr.ifr_name[IFNAMSIZ-1] = '\0';
ifr.ifr_ifindex = index; ifr.ifr_ifindex = index;
err = ioctl(fd, SIOCBRADDIF, &ifr); err = ioctl(fd, SIOCBRADDIF, &ifr);
process_lock(); process_lock();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment