minissdpd/getifaddr.c: update
see
-/* $Id: getifaddr.c,v 1.25 2018/07/06 11:47:29 nanard Exp $ */
+/* $Id: getifaddr.c,v 1.26 2019/05/20 19:54:08 nanard Exp $ */
/* vim: tabstop=4 shiftwidth=4 noexpandtab
* MiniUPnP project
* http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/
- * (c) 2006-2018 Thomas Bernard
+ * (c) 2006-2019 Thomas Bernard
* This software is subject to the conditions detailed
* in the LICENCE file provided within the distribution */
@@ -47,7 +47,7 @@ getifaddr(const char * ifname, char * buf, int len,
syslog(LOG_ERR, "socket(PF_INET, SOCK_DGRAM): %m");
return -1;
}
- strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
+ strncpy(ifr.ifr_name, ifname, IFNAMSIZ-1);
ifr.ifr_name[IFNAMSIZ-1] = '\0';
if(ioctl(s, SIOCGIFFLAGS, &ifr, &ifrlen) < 0)
{
@@ -61,7 +61,8 @@ getifaddr(const char * ifname, char * buf, int len,
close(s);
return -1;
}
- strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
+ strncpy(ifr.ifr_name, ifname, IFNAMSIZ-1);
+ ifr.ifr_name[IFNAMSIZ-1] = '\0';
if(ioctl(s, SIOCGIFADDR, &ifr, &ifrlen) < 0)
{
syslog(LOG_ERR, "ioctl(s, SIOCGIFADDR, ...): %m");
@@ -81,7 +82,8 @@ getifaddr(const char * ifname, char * buf, int len,
}
if(mask)
{
- strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
+ strncpy(ifr.ifr_name, ifname, IFNAMSIZ-1);
+ ifr.ifr_name[IFNAMSIZ-1] = '\0';
if(ioctl(s, SIOCGIFNETMASK, &ifr, &ifrlen) < 0)
{
syslog(LOG_ERR, "ioctl(s, SIOCGIFNETMASK, ...): %m");
