Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/bsd/libpcap/dist Fix the rest of the places where s...



details:   https://anonhg.NetBSD.org/src/rev/76995653860f
branches:  trunk
changeset: 966039:76995653860f
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Oct 11 18:20:20 2019 +0000

description:
Fix the rest of the places where strncpy was called instead of pcap_strlcpy
to copy the interface name. The kernel requires the interface to be NUL
terminated anyway and will fail with ENAMETOOLONG otherwise. Pointed out
by Robert Swindells.

diffstat:

 external/bsd/libpcap/dist/pcap-bpf.c |  24 ++++++++++++------------
 1 files changed, 12 insertions(+), 12 deletions(-)

diffs (108 lines):

diff -r 37e9f9c023cd -r 76995653860f external/bsd/libpcap/dist/pcap-bpf.c
--- a/external/bsd/libpcap/dist/pcap-bpf.c      Fri Oct 11 18:05:52 2019 +0000
+++ b/external/bsd/libpcap/dist/pcap-bpf.c      Fri Oct 11 18:20:20 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pcap-bpf.c,v 1.9 2019/10/01 16:02:11 christos Exp $    */
+/*     $NetBSD: pcap-bpf.c,v 1.10 2019/10/11 18:20:20 christos Exp $   */
 
 /*
  * Copyright (c) 1993, 1994, 1995, 1996, 1998
@@ -22,7 +22,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: pcap-bpf.c,v 1.9 2019/10/01 16:02:11 christos Exp $");
+__RCSID("$NetBSD: pcap-bpf.c,v 1.10 2019/10/11 18:20:20 christos Exp $");
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
@@ -628,7 +628,7 @@
        /*
         * Now bind to the device.
         */
-       (void)strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+       pcap_strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
        if (ioctl(fd, BIOCSETIF, (caddr_t)&ifr) < 0) {
                switch (errno) {
 
@@ -835,7 +835,7 @@
        /*
         * Now bind to the device.
         */
-       (void)strncpy(ifr.ifr_name, p->opt.device, sizeof(ifr.ifr_name));
+       pcap_strlcpy(ifr.ifr_name, p->opt.device, sizeof(ifr.ifr_name));
        if (ioctl(fd, BIOCSETIF, (caddr_t)&ifr) < 0) {
                switch (errno) {
 
@@ -1445,7 +1445,7 @@
                                    strerror(errno));
                        } else {
                                memset(&req, 0, sizeof(req));
-                               strncpy(req.ifm_name, pb->device,
+                               pcap_strlcpy(req.ifm_name, pb->device,
                                    sizeof(req.ifm_name));
                                if (ioctl(sock, SIOCGIFMEDIA, &req) < 0) {
                                        fprintf(stderr,
@@ -1459,7 +1459,7 @@
                                                 * turn it off.
                                                 */
                                                memset(&ifr, 0, sizeof(ifr));
-                                               (void)strncpy(ifr.ifr_name,
+                                               pcap_strlcpy(ifr.ifr_name,
                                                    pb->device,
                                                    sizeof(ifr.ifr_name));
                                                ifr.ifr_media =
@@ -2002,7 +2002,7 @@
                        status = PCAP_ERROR;
                        goto bad;
                }
-               (void)strncpy(ifrname, p->opt.device, ifnamsiz);
+               pcap_strlcpy(ifrname, p->opt.device, ifnamsiz);
                if (ioctl(fd, BIOCSETIF, (caddr_t)&ifr) < 0) {
                        pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
                            errno, "BIOCSETIF: %s", p->opt.device);
@@ -2033,7 +2033,7 @@
                        /*
                         * Now bind to the device.
                         */
-                       (void)strncpy(ifrname, p->opt.device, ifnamsiz);
+                       pcap_strlcpy(ifrname, p->opt.device, ifnamsiz);
 #ifdef BIOCSETLIF
                        if (ioctl(fd, BIOCSETLIF, (caddr_t)&ifr) < 0)
 #else
@@ -2066,7 +2066,7 @@
                                 */
                                (void) ioctl(fd, BIOCSBLEN, (caddr_t)&v);
 
-                               (void)strncpy(ifrname, p->opt.device, ifnamsiz);
+                               pcap_strlcpy(ifrname, p->opt.device, ifnamsiz);
 #ifdef BIOCSETLIF
                                if (ioctl(fd, BIOCSETLIF, (caddr_t)&ifr) >= 0)
 #else
@@ -2764,7 +2764,7 @@
                return (-1);
        }
        memset(&req, 0, sizeof(req));
-       strncpy(req.ifm_name, name, sizeof(req.ifm_name));
+       pcap_strlcpy(req.ifm_name, name, sizeof(req.ifm_name));
        if (ioctl(sock, SIOCGIFMEDIA, &req) < 0) {
                if (errno == EOPNOTSUPP || errno == EINVAL || errno == ENOTTY ||
                    errno == ENODEV || errno == EPERM) {
@@ -2891,7 +2891,7 @@
        }
 
        memset(&req, 0, sizeof req);
-       strncpy(req.ifm_name, p->opt.device, sizeof req.ifm_name);
+       pcap_strlcpy(req.ifm_name, p->opt.device, sizeof(req.ifm_name));
 
        /*
         * Find out how many media types we have.
@@ -3001,7 +3001,7 @@
                                return (PCAP_ERROR);
                        }
                        memset(&ifr, 0, sizeof(ifr));
-                       (void)strncpy(ifr.ifr_name, p->opt.device,
+                       pcap_strlcpy(ifr.ifr_name, p->opt.device,
                            sizeof(ifr.ifr_name));
                        ifr.ifr_media = req.ifm_current | IFM_IEEE80211_MONITOR;
                        if (ioctl(sock, SIOCSIFMEDIA, &ifr) == -1) {



Home | Main Index | Thread Index | Old Index