test: dirserv_router_has_valid_address() with zero-family addresses

Sometimes tor doesn't initialise an address, so its family is zero.

Failing test for 31793. Future commits will fix the code.
This commit is contained in:
teor 2019-09-19 15:24:01 +10:00
parent d6d3e829dd
commit 46fea1dfee
No known key found for this signature in database
GPG Key ID: 10FEAA0E7075672A

View File

@ -1271,10 +1271,44 @@ test_address_dirserv_router_addr_private(void *ignored)
(void)ignored; (void)ignored;
/* A stub routerinfo structure, with only its address fields set. */ /* A stub routerinfo structure, with only its address fields set. */
routerinfo_t *ri = NULL; routerinfo_t *ri = NULL;
CHECK_RI_ADDR("1.0.0.1", 0); CHECK_RI_ADDR("1.0.0.1", 0);
CHECK_RI_ADDR("10.0.0.1", -1); CHECK_RI_ADDR("10.0.0.1", -1);
CHECK_RI_ADDR6("2600::1", 0); CHECK_RI_ADDR6("2600::1", 0);
CHECK_RI_ADDR6("fe80::1", -1); CHECK_RI_ADDR6("fe80::1", -1);
/* Null addresses */
/* IPv4 null fails, regardless of IPv6 */
CHECK_RI_ADDR("0.0.0.0", -1);
{
ri = tor_malloc_zero(sizeof(routerinfo_t));
ri->addr = 0; /* 0.0.0.0 */
tor_addr_parse(&ri->ipv6_addr, "::");
tt_int_op(dirserv_router_has_valid_address(ri), OP_EQ, -1);
tor_free(ri);
}
/* IPv6 null succeeds, because IPv4 is not null */
CHECK_RI_ADDR6("::", 0);
/* Byte-zeroed null addresses */
/* IPv4 null fails, regardless of IPv6 */
{
ri = tor_malloc_zero(sizeof(routerinfo_t));
tt_int_op(dirserv_router_has_valid_address(ri), OP_EQ, -1);
tor_free(ri);
}
/* IPv6 null succeeds, because IPv4 is not internal */
{
ri = tor_malloc_zero(sizeof(routerinfo_t));
ri->addr = 16777217; /* 1.0.0.1 */
tt_int_op(dirserv_router_has_valid_address(ri), OP_EQ, 0);
tor_free(ri);
}
done: done:
tor_free(ri); tor_free(ri);
} }