summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2015-02-12 14:20:38 -0800
committerGuy Harris <guy@alum.mit.edu>2015-02-12 14:20:38 -0800
commit4d13542896772b0fe28a5a41a1de1764ef4e0110 (patch)
treeb727201faca159aa3534dd8d0534fdef78945ab9
parenteae5b3940c592a5c906ec8d94a945fae48d6cba4 (diff)
downloadlibpcap-4d13542896772b0fe28a5a41a1de1764ef4e0110.tar.gz
Don't add null addresses to the address list.
If we don't have an address, don't add a pcap_addr_t with a null addr pointer to the list of addresses; it conveys no information. That seems to happen, at least with a venet device on Linux on the Travis build machine.
-rw-r--r--inet.c35
1 files changed, 27 insertions, 8 deletions
diff --git a/inet.c b/inet.c
index fad7e25b..e7d2104e 100644
--- a/inet.c
+++ b/inet.c
@@ -572,7 +572,8 @@ get_if_description(const char *name)
* Try to get a description for a given device, and then look for that
* device in the specified list of devices.
*
- * If we find it, add the specified address to it and return 0.
+ * If we find it, then, if the specified address isn't null, add it to
+ * the list of addresses for the device and return 0.
*
* If we don't find it, check whether we can open it:
*
@@ -583,9 +584,17 @@ get_if_description(const char *name)
*
* Otherwise, attempt to add an entry for it, with the specified
* ifnet flags and description, and, if that succeeds, add the
- * specified address to it, set *curdev_ret to point to the new
- * entry, and return 0, otherwise return PCAP_ERROR and set errbuf
- * to an error message.
+ * specified address to its list of addresses if that address is
+ * non-null, set *curdev_ret to point to the new entry, and
+ * return 0, otherwise return PCAP_ERROR and set errbuf to an
+ * error message.
+ *
+ * (We can get called with a null address because we might get a list
+ * of interface name/address combinations from the underlying OS, with
+ * the address being absent in some cases, rather than a list of
+ * interfaces with each interface having a list of addresses, so this
+ * call may be the only call made to add to the list, and we want to
+ * add interfaces even if they have no addresses.)
*/
int
add_addr_to_iflist(pcap_if_t **alldevs, const char *name, u_int flags,
@@ -616,14 +625,24 @@ add_addr_to_iflist(pcap_if_t **alldevs, const char *name, u_int flags,
return (0);
}
+ if (addr == NULL) {
+ /*
+ * There's no address to add; this entry just meant
+ * "here's a new interface".
+ */
+ return (0);
+ }
+
/*
- * "curdev" is an entry for this interface; add an entry for this
- * address to its list of addresses.
+ * "curdev" is an entry for this interface, and we have an
+ * address for it; add an entry for that address to the
+ * interface's list of addresses.
*
* Allocate the new entry and fill it in.
*/
- return (add_addr_to_dev(curdev, addr, addr_size, netmask, netmask_size,
- broadaddr, broadaddr_size, dstaddr, dstaddr_size, errbuf));
+ return (add_addr_to_dev(curdev, addr, addr_size, netmask,
+ netmask_size, broadaddr, broadaddr_size, dstaddr,
+ dstaddr_size, errbuf));
}
/*