Description: Satisfy GCC pedantery for strncpy() calls
 The code has some strncpy() calls which GCC no longer accepts with
 -Wall -Werror.  Write them more carefully and use memcpy() where
 applicable.
 .
 Encountered while looking into #980607.
Author: Dennis Filder <d.filder@web.de>
Last-Update: 2021-02-09
---
diff --git netcfg-1.169/autoconfig.c netcfg-1.169/autoconfig.c
index f254cf3..3db3a5a 100644
--- netcfg-1.169/autoconfig.c
+++ netcfg-1.169/autoconfig.c
@@ -343,15 +343,18 @@ static int netcfg_dhcpv6(struct debconfclient *client, struct netcfg_interface *
 
 		if (!strncmp("nameserver[", l, 11) && ns_idx < NETCFG_NAMESERVERS_MAX) {
 			p = strstr(l, "] ") + 2;
-			strncpy(interface->nameservers[ns_idx], p, sizeof(interface->nameservers[ns_idx]));
+			strncpy(interface->nameservers[ns_idx], p, sizeof(interface->nameservers[ns_idx])-1);
+			interface->nameservers[ns_idx][sizeof(interface->nameservers[ns_idx])-1]='\0';
 			ns_idx++;
 		} else if (!strncmp("NTP server[", l, 11) && ntp_idx < NETCFG_NTPSERVERS_MAX) {
 			p = strstr(l, "] ") + 2;
-			strncpy(interface->ntp_servers[ntp_idx], p, sizeof(interface->ntp_servers[ntp_idx]));
+			strncpy(interface->ntp_servers[ntp_idx], p, sizeof(interface->ntp_servers[ntp_idx])-1);
+			interface->ntp_servers[ntp_idx][sizeof(interface->ntp_servers[ntp_idx])-1]='\0';
 			ntp_idx++;
 		} else if (!strncmp("Domain search list[0] ", l, 21)) {
 			p = strstr(l, "] ") + 2;
-			strncpy(domain, p, sizeof(domain));
+			strncpy(domain, p, sizeof(domain)-1);
+			domain[sizeof(domain)-1]='\0';
 			/* Strip trailing . */
 			if (domain[strlen(domain)-1] == '.') {
 				domain[strlen(domain)-1] = '\0';
diff --git netcfg-1.169/dhcp.c netcfg-1.169/dhcp.c
index fe06950..26bc6f6 100644
--- netcfg-1.169/dhcp.c
+++ netcfg-1.169/dhcp.c
@@ -667,7 +667,8 @@ int read_resolv_conf_nameservers(char *resolv_conf_file, struct netcfg_interface
             	rtrim(buf);
 
                 ptr = buf + strlen("nameserver ");
-                strncpy(interface->nameservers[i], ptr, NETCFG_ADDRSTRLEN);
+                memcpy(interface->nameservers[i], ptr, NETCFG_ADDRSTRLEN-1);
+                interface->nameservers[i][NETCFG_ADDRSTRLEN-1]='\0';
                 di_debug("Read nameserver %s", interface->nameservers[i]);
                 i++;
                 if (i >= NETCFG_NAMESERVERS_MAX) {
diff --git netcfg-1.169/netcfg-common.c netcfg-1.169/netcfg-common.c
index c6d1d8d..2a8fa00 100644
--- netcfg-1.169/netcfg-common.c
+++ netcfg-1.169/netcfg-common.c
@@ -245,7 +245,8 @@ int is_raw_80211(const char *iface)
     struct ifreq ifr;
     struct sockaddr sa;
 
-    strncpy(ifr.ifr_name, iface, IFNAMSIZ);
+    strncpy(ifr.ifr_name, iface, IFNAMSIZ-1);
+    ifr.ifr_name[IFNAMSIZ-1]='\0';
 
     if (skfd && ioctl(skfd, SIOCGIFHWADDR, &ifr) < 0) {
         di_warning("Unable to retrieve interface type.");
@@ -408,12 +409,13 @@ int get_all_ifs (int all, char*** ptr)
     char ibuf[512];
     char** list = NULL;
     size_t len = 0;
+    ibuf[sizeof(ibuf)-1]='\0';
 
     if (getifaddrs(&ifap) == -1)
         return 0;
 
     for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
-        strncpy(ibuf, ifa->ifa_name, sizeof(ibuf));
+        strncpy(ibuf, ifa->ifa_name, sizeof(ibuf)-1);
         if (ifa->ifa_flags & IFF_LOOPBACK)   /* ignore loopback devices */
             continue;
 #if defined(__linux__)
@@ -1310,11 +1312,12 @@ void interface_up (const char *if_name)
 {
     struct ifreq ifr;
 
-    strncpy(ifr.ifr_name, if_name, IFNAMSIZ);
+    strncpy(ifr.ifr_name, if_name, IFNAMSIZ-1);
+    ifr.ifr_name[IFNAMSIZ-1]='\0';
 
     if (skfd && ioctl(skfd, SIOCGIFFLAGS, &ifr) >= 0) {
         di_info("Activating interface %s", if_name);
-        strncpy(ifr.ifr_name, if_name, IFNAMSIZ);
+        strncpy(ifr.ifr_name, if_name, IFNAMSIZ-1);
         ifr.ifr_flags |= (IFF_UP | IFF_RUNNING);
         ioctl(skfd, SIOCSIFFLAGS, &ifr);
     } else {
@@ -1326,11 +1329,12 @@ void interface_down (const char *if_name)
 {
     struct ifreq ifr;
 
-    strncpy(ifr.ifr_name, if_name, IFNAMSIZ);
+    strncpy(ifr.ifr_name, if_name, IFNAMSIZ-1);
+    ifr.ifr_name[IFNAMSIZ-1]='\0';
 
     if (skfd && ioctl(skfd, SIOCGIFFLAGS, &ifr) >= 0) {
         di_info("Taking down interface %s", if_name);
-        strncpy(ifr.ifr_name, if_name, IFNAMSIZ);
+        strncpy(ifr.ifr_name, if_name, IFNAMSIZ-1);
         ifr.ifr_flags &= ~IFF_UP;
         ioctl(skfd, SIOCSIFFLAGS, &ifr);
     } else {
@@ -1580,7 +1584,8 @@ int netcfg_parse_cidr_address(const char *address, struct netcfg_interface *inte
     char *maskptr, *addrstr, addrbuf[NETCFG_ADDRSTRLEN];
     int i;
     
-    strncpy(addrbuf, address, NETCFG_ADDRSTRLEN);
+    strncpy(addrbuf, address, NETCFG_ADDRSTRLEN-1);
+    addrbuf[NETCFG_ADDRSTRLEN-1]='\0';
     addrstr = strtrim(addrbuf);
     
     if ((maskptr = strchr(addrstr, '/'))) {
