commit 488e9a0502d0f177a00c4bf5f49ec218fdc65870 Merge: 0d44679 99d2869 Author: Nick Mathewson nickm@torproject.org Date: Fri Oct 2 13:54:20 2015 +0200
Merge remote-tracking branch 'teor/routerset-parse-IPv6-literals'
(Minor conflicts)
changes/routerset-parse-IPv6-literals | 5 ++ src/or/routerset.c | 6 +- src/test/test_routerset.c | 102 ++++++++++++++++++++++++++++++++- 3 files changed, 108 insertions(+), 5 deletions(-)
diff --cc src/or/routerset.c index 3be55d3,6a93a32..debe9ec --- a/src/or/routerset.c +++ b/src/or/routerset.c @@@ -107,15 -104,16 +107,17 @@@ routerset_parse(routerset_t *target, co description); smartlist_add(target->country_names, countryname); added_countries = 1; - } else if ((strchr(nick,'.') || strchr(nick, '*')) && - (p = router_parse_addr_policy_item_from_string( + } else if ((strchr(nick,'.') || strchr(nick, ':') || strchr(nick, '*')) + && (p = router_parse_addr_policy_item_from_string( - nick, ADDR_POLICY_REJECT))) { + nick, ADDR_POLICY_REJECT, + &malformed_list))) { + /* IPv4 addresses contain '.', IPv6 addresses contain ':', + * and wildcard addresses contain '*'. */ log_debug(LD_CONFIG, "Adding address %s to %s", nick, description); smartlist_add(target->policies, p); - } else { - log_warn(LD_CONFIG, "Entry '%s' in %s is malformed.", nick, - description); + } else if (malformed_list) { + log_warn(LD_CONFIG, "Entry '%s' in %s is malformed. Discarding entire" + " list.", nick, description); r = -1; tor_free(nick); SMARTLIST_DEL_CURRENT(list, nick); diff --cc src/test/test_routerset.c index 90dfb28,39d088b..3e9317c --- a/src/test/test_routerset.c +++ b/src/test/test_routerset.c @@@ -470,6 -467,96 +470,100 @@@ NS(router_parse_addr_policy_item_from_s }
#undef NS_SUBMODULE + #define NS_SUBMODULE ASPECT(routerset_parse, policy_ipv4) + + /* + * Structural test for routerset_parse, when given a valid IPv4 address + * literal policy. + */ + + NS_DECL(addr_policy_t *, router_parse_addr_policy_item_from_string, - (const char *s, int assume_action)); ++ (const char *s, int assume_action, int *bogus)); + + addr_policy_t *NS(mock_addr_policy); + + static void + NS(test_main)(void *arg) + { + routerset_t *set; + const char *s; + int r; + (void)arg; + + NS_MOCK(router_parse_addr_policy_item_from_string); + NS(mock_addr_policy) = tor_malloc_zero(sizeof(addr_policy_t)); + + set = routerset_new(); + s = "127.0.0.1"; + r = routerset_parse(set, s, ""); + tt_int_op(r, OP_EQ, 0); + tt_int_op(smartlist_len(set->policies), OP_NE, 0); + tt_int_op(CALLED(router_parse_addr_policy_item_from_string), OP_EQ, 1); + + done: + routerset_free(set); + } + + addr_policy_t * -NS(router_parse_addr_policy_item_from_string)(const char *s, int assume_action) ++NS(router_parse_addr_policy_item_from_string)(const char *s, int assume_action, ++ int *bogus) + { + (void)s; + (void)assume_action; + CALLED(router_parse_addr_policy_item_from_string)++; ++ *bogus = 0; + + return NS(mock_addr_policy); + } + + #undef NS_SUBMODULE + #define NS_SUBMODULE ASPECT(routerset_parse, policy_ipv6) + + /* + * Structural test for routerset_parse, when given a valid IPv6 address + * literal policy. + */ + + NS_DECL(addr_policy_t *, router_parse_addr_policy_item_from_string, - (const char *s, int assume_action)); ++ (const char *s, int assume_action, int *bad)); + + addr_policy_t *NS(mock_addr_policy); + + static void + NS(test_main)(void *arg) + { + routerset_t *set; + const char *s; + int r; + (void)arg; + + NS_MOCK(router_parse_addr_policy_item_from_string); + NS(mock_addr_policy) = tor_malloc_zero(sizeof(addr_policy_t)); + + set = routerset_new(); + s = "::1"; + r = routerset_parse(set, s, ""); + tt_int_op(r, OP_EQ, 0); + tt_int_op(smartlist_len(set->policies), OP_NE, 0); + tt_int_op(CALLED(router_parse_addr_policy_item_from_string), OP_EQ, 1); + + done: + routerset_free(set); + } + + addr_policy_t * -NS(router_parse_addr_policy_item_from_string)(const char *s, int assume_action) ++NS(router_parse_addr_policy_item_from_string)(const char *s, ++ int assume_action, int *bad) + { + (void)s; + (void)assume_action; + CALLED(router_parse_addr_policy_item_from_string)++; ++ *bad = 0; + + return NS(mock_addr_policy); + } + + #undef NS_SUBMODULE #define NS_SUBMODULE ASPECT(routerset_union, source_bad)
/*
tor-commits@lists.torproject.org