diff options
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); |