summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/address.c24
-rw-r--r--src/common/address.h8
2 files changed, 20 insertions, 12 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);
diff --git a/src/common/address.h b/src/common/address.h
index 7d49fb59bc..d2841e1c9d 100644
--- a/src/common/address.h
+++ b/src/common/address.h
@@ -310,11 +310,11 @@ get_interface_address_list(int severity, int include_internal)
tor_addr_port_t *tor_addr_port_new(const tor_addr_t *addr, uint16_t port);
#ifdef ADDRESS_PRIVATE
-STATIC smartlist_t *get_interface_addresses_raw(int severity);
+MOCK_DECL(smartlist_t *,get_interface_addresses_raw,(int severity));
STATIC int tor_addr_is_multicast(const tor_addr_t *a);
-STATIC int get_interface_address6_via_udp_socket_hack(int severity,
- sa_family_t family,
- tor_addr_t *addr);
+MOCK_DECL(int,get_interface_address6_via_udp_socket_hack,(int severity,
+ sa_family_t family,
+ tor_addr_t *addr));
#ifdef HAVE_IFADDRS_TO_SMARTLIST
STATIC smartlist_t *ifaddrs_to_smartlist(const struct ifaddrs *ifa);