From 585a1d64e2153b2c101133f74e7522429e5d11f6 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Mon, 20 May 2019 21:55:17 +0200 Subject: [PATCH] getifaddr.c: properly use strncpy() silent a gcc8 warning --- miniupnpd/getifaddr.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/miniupnpd/getifaddr.c b/miniupnpd/getifaddr.c index f2fb261..a960745 100644 --- a/miniupnpd/getifaddr.c +++ b/miniupnpd/getifaddr.c @@ -1,8 +1,8 @@ -/* $Id: getifaddr.c,v 1.19 2013/12/13 14:28:40 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");