ctdb-common: Consistently use strlcpy() on interface names
authorMartin Schwenke <martin@meltin.net>
Mon, 1 Aug 2016 05:03:56 +0000 (15:03 +1000)
committerAmitay Isaacs <amitay@samba.org>
Wed, 3 Aug 2016 03:29:23 +0000 (05:29 +0200)
Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/common/system_linux.c

index 8bb18f836f0e6954f735e7fd92ad7d35cd0e1f15..b66ce670288d6e1dc2e879dba22e11697249fa15 100644 (file)
@@ -116,7 +116,7 @@ int ctdb_sys_send_arp(const ctdb_sock_addr *addr, const char *iface)
                }
 
                /* get the mac address */
-               strncpy(if_hwaddr.ifr_name, iface, sizeof(if_hwaddr.ifr_name)-1);
+               strlcpy(if_hwaddr.ifr_name, iface, sizeof(if_hwaddr.ifr_name));
                ret = ioctl(s, SIOCGIFHWADDR, &if_hwaddr);
                if ( ret < 0 ) {
                        close(s);
@@ -210,7 +210,7 @@ int ctdb_sys_send_arp(const ctdb_sock_addr *addr, const char *iface)
                }
 
                /* get the mac address */
-               strncpy(if_hwaddr.ifr_name, iface, sizeof(if_hwaddr.ifr_name)-1);
+               strlcpy(if_hwaddr.ifr_name, iface, sizeof(if_hwaddr.ifr_name));
                ret = ioctl(s, SIOCGIFHWADDR, &if_hwaddr);
                if ( ret < 0 ) {
                        close(s);
@@ -602,7 +602,7 @@ bool ctdb_sys_check_iface_exists(const char *iface)
                return true;
        }
 
-       strncpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name)-1);
+       strlcpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name));
        if (ioctl(s, SIOCGIFINDEX, &ifr) < 0 && errno == ENODEV) {
                DEBUG(DEBUG_CRIT,(__location__ " interface '%s' not found\n", iface));
                close(s);