diff --git a/src/hw_sock_raw.c b/src/hw_sock_raw.c index 2872c85..c50d281 100644 --- a/src/hw_sock_raw.c +++ b/src/hw_sock_raw.c @@ -198,7 +198,7 @@ int hw_device_sock_raw_open(struct hw_sock_raw *phw_sock_raw, struct ec *pec, co ec_log(10, "HW_OPEN", "binding raw socket to %s\n", devname); (void)memset(&ifr, 0, sizeof(ifr)); - (void)strncpy(ifr.ifr_name, devname, min(strlen(devname), IFNAMSIZ)); + (void)strncpy(ifr.ifr_name, devname, min(strlen(devname), IFNAMSIZ - 1)); ioctl(phw_sock_raw->sockfd, SIOCGIFMTU, &ifr); phw_sock_raw->common.mtu_size = ifr.ifr_mtu; ec_log(10, "hw_open", "got mtu size %d\n", phw_sock_raw->common.mtu_size); diff --git a/src/hw_sock_raw_mmaped.c b/src/hw_sock_raw_mmaped.c index fb5dc7c..4ef433e 100644 --- a/src/hw_sock_raw_mmaped.c +++ b/src/hw_sock_raw_mmaped.c @@ -225,7 +225,7 @@ int hw_device_sock_raw_mmaped_open(struct hw_sock_raw_mmaped *phw_sock_raw_mmape ec_log(10, "HW_OPEN", "binding raw socket to %s\n", devname); (void)memset(&ifr, 0, sizeof(ifr)); - (void)strncpy(ifr.ifr_name, devname, IFNAMSIZ); + (void)strncpy(ifr.ifr_name, devname, min(strlen(devname), IFNAMSIZ - 1)); ioctl(phw_sock_raw_mmaped->sockfd, SIOCGIFMTU, &ifr); phw_sock_raw_mmaped->common.mtu_size = ifr.ifr_mtu; ec_log(10, "hw_open", "got mtu size %d\n", phw_sock_raw_mmaped->common.mtu_size);