]> The Tcpdump Group git mirrors - libpcap/commitdiff
Network routines: fix a Coverity warning
authorFrancois-Xavier Le Bail <[email protected]>
Fri, 16 Jan 2015 13:28:10 +0000 (14:28 +0100)
committerFrancois-Xavier Le Bail <[email protected]>
Fri, 16 Jan 2015 13:28:10 +0000 (14:28 +0100)
The warning was:
CID 602256 (#1 of 2): Buffer not null terminated (BUFFER_SIZE_WARNING)
CID 602256 (#2 of 2): Buffer not null terminated (BUFFER_SIZE_WARNING)
buffer_size_warning: Calling strncpy with a maximum size argument of 16 bytes
on destination array ifr.ifr_ifrn.ifrn_name of size 16 bytes might leave
the destination string unterminated.

inet.c

diff --git a/inet.c b/inet.c
index 036b2db316d6b4084a5dc76d59a416e07db786f2..fad7e25bcab1c9fb025b54ce555eb34bcfeb3e51 100644 (file)
--- a/inet.c
+++ b/inet.c
@@ -905,7 +905,7 @@ pcap_lookupnet(device, netp, maskp, errbuf)
        /* XXX Work around Linux kernel bug */
        ifr.ifr_addr.sa_family = AF_INET;
 #endif
-       (void)strncpy(ifr.ifr_name, device, sizeof(ifr.ifr_name));
+       (void)strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name));
        if (ioctl(fd, SIOCGIFADDR, (char *)&ifr) < 0) {
                if (errno == EADDRNOTAVAIL) {
                        (void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
@@ -925,7 +925,7 @@ pcap_lookupnet(device, netp, maskp, errbuf)
        /* XXX Work around Linux kernel bug */
        ifr.ifr_addr.sa_family = AF_INET;
 #endif
-       (void)strncpy(ifr.ifr_name, device, sizeof(ifr.ifr_name));
+       (void)strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name));
        if (ioctl(fd, SIOCGIFNETMASK, (char *)&ifr) < 0) {
                (void)snprintf(errbuf, PCAP_ERRBUF_SIZE,
                    "SIOCGIFNETMASK: %s: %s", device, pcap_strerror(errno));