diff options
author | teor (Tim Wilson-Brown) <teor2345@gmail.com> | 2015-09-29 07:04:49 +0200 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2015-09-29 10:17:05 +0200 |
commit | 7fa102b48783b51673095e1ddcb2f88050a2ba32 (patch) | |
tree | 2ca26db29d68f8a31397b1c04a16a752b5d9f04b /src/common/address.c | |
parent | 3ea834ce0a63f275fd806f9ebeec64a2bbcd1b55 (diff) | |
download | tor-7fa102b48783b51673095e1ddcb2f88050a2ba32.tar.gz tor-7fa102b48783b51673095e1ddcb2f88050a2ba32.zip |
Add checks and unit tests for get_interface_address* failure
Ensure that either a valid address is returned in address pointers,
or that the address data is zeroed on error.
Ensure that free_interface_address6_list handles NULL lists.
Add unit tests for get_interface_address* failure cases.
Fixes bug #17173.
Patch by fk/teor, not in any released version of tor.
Diffstat (limited to 'src/common/address.c')
-rw-r--r-- | src/common/address.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/common/address.c b/src/common/address.c index fc85f8eba2..cfa8fd1dca 100644 --- a/src/common/address.c +++ b/src/common/address.c @@ -1506,8 +1506,8 @@ get_interface_addresses_ioctl(int severity) * Return a new smartlist of tor_addr_t on success, and NULL on failure. * (An empty smartlist indicates that we successfully learned that we have no * addresses.) Log failure messages at <b>severity</b>. */ -STATIC smartlist_t * -get_interface_addresses_raw(int severity) +MOCK_IMPL(smartlist_t *, +get_interface_addresses_raw,(int severity)) { smartlist_t *result = NULL; #if defined(HAVE_IFADDRS_TO_SMARTLIST) @@ -1547,10 +1547,10 @@ tor_addr_is_multicast(const tor_addr_t *a) * UDP socket trickery. Only look for address of given <b>family</b>. * Set result to *<b>addr</b>. Return 0 on success, -1 on failure. */ -STATIC int -get_interface_address6_via_udp_socket_hack(int severity, - sa_family_t family, - tor_addr_t *addr) +MOCK_IMPL(int, +get_interface_address6_via_udp_socket_hack,(int severity, + sa_family_t family, + tor_addr_t *addr)) { struct sockaddr_storage my_addr, target_addr; int sock=-1, r=-1; @@ -1614,6 +1614,8 @@ get_interface_address6_via_udp_socket_hack(int severity, err: if (sock >= 0) tor_close_socket(sock); + if (r == -1) + memset(addr, 0, sizeof(tor_addr_t)); return r; } @@ -1632,6 +1634,8 @@ get_interface_address6,(int severity, sa_family_t family, tor_addr_t *addr)) int rv = -1; tor_assert(addr); + memset(addr, 0, sizeof(tor_addr_t)); + /* Get a list of public or internal IPs in arbitrary order */ addrs = get_interface_address6_list(severity, family, 1); @@ -1656,8 +1660,10 @@ get_interface_address6,(int severity, sa_family_t family, tor_addr_t *addr)) void free_interface_address6_list(smartlist_t *addrs) { - SMARTLIST_FOREACH(addrs, tor_addr_t *, a, tor_free(a)); - smartlist_free(addrs); + if (addrs != NULL) { + SMARTLIST_FOREACH(addrs, tor_addr_t *, a, tor_free(a)); + smartlist_free(addrs); + } } /** Return a smartlist of the IP addresses of type family from all interfaces @@ -1975,6 +1981,8 @@ get_interface_address,(int severity, uint32_t *addr)) tor_addr_t local_addr; int r; + memset(addr, 0, sizeof(uint32_t)); + r = get_interface_address6(severity, AF_INET, &local_addr); if (r>=0) *addr = tor_addr_to_ipv4h(&local_addr); |