]> The Tcpdump Group git mirrors - libpcap/commitdiff
Check for zero-length addresses.
authorGuy Harris <[email protected]>
Sun, 12 Mar 2017 05:36:39 +0000 (21:36 -0800)
committerGuy Harris <[email protected]>
Sun, 12 Mar 2017 05:36:39 +0000 (21:36 -0800)
At least on my macOS Sierra machine, the utun0 device has a destination
address with an sa_len of 0 (and an sa_family of AF_UNSPEC).  That's not
valid - sa_len is *supposed* to be the total length of the structure,
but a total length of 0 doesn't even leave room for the sa_len and
sa_family fields, which are present in *all* sockaddr structures.

pcap.c

diff --git a/pcap.c b/pcap.c
index 53151724d7d10ab01972b36c7d2c797905ab018e..14fd2b39b80022472f0d378bc79cc987365eebe0 100644 (file)
--- a/pcap.c
+++ b/pcap.c
@@ -780,7 +780,7 @@ add_addr_to_dev(pcap_if_t *curdev,
        }
 
        curaddr->next = NULL;
-       if (addr != NULL) {
+       if (addr != NULL && addr_size != 0) {
                curaddr->addr = (struct sockaddr *)dup_sockaddr(addr, addr_size);
                if (curaddr->addr == NULL) {
                        (void)pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE,
@@ -791,7 +791,7 @@ add_addr_to_dev(pcap_if_t *curdev,
        } else
                curaddr->addr = NULL;
 
-       if (netmask != NULL) {
+       if (netmask != NULL && netmask_size != 0) {
                curaddr->netmask = (struct sockaddr *)dup_sockaddr(netmask, netmask_size);
                if (curaddr->netmask == NULL) {
                        (void)pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE,
@@ -804,7 +804,7 @@ add_addr_to_dev(pcap_if_t *curdev,
        } else
                curaddr->netmask = NULL;
 
-       if (broadaddr != NULL) {
+       if (broadaddr != NULL && broadaddr_size != 0) {
                curaddr->broadaddr = (struct sockaddr *)dup_sockaddr(broadaddr, broadaddr_size);
                if (curaddr->broadaddr == NULL) {
                        (void)pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE,
@@ -819,7 +819,7 @@ add_addr_to_dev(pcap_if_t *curdev,
        } else
                curaddr->broadaddr = NULL;
 
-       if (dstaddr != NULL) {
+       if (dstaddr != NULL && dstaddr_size != 0) {
                curaddr->dstaddr = (struct sockaddr *)dup_sockaddr(dstaddr, dstaddr_size);
                if (curaddr->dstaddr == NULL) {
                        (void)pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE,