From aacda9cd8eae992c9359279782234dd626415948 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 9 Sep 2008 03:48:01 +0000 Subject: We should not alter an addr_policy_t that has been canonicalized. svn:r16802 --- src/common/container.h | 9 +++++++++ src/or/policies.c | 21 ++++++++++++++++----- 2 files changed, 25 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/common/container.h b/src/common/container.h index 6faad3435d..598e27aaa5 100644 --- a/src/common/container.h +++ b/src/common/container.h @@ -222,6 +222,15 @@ char *smartlist_join_strings2(smartlist_t *sl, const char *join, --var ## _sl_len; \ STMT_END +/** Helper: While in a SMARTLIST_FOREACH loop over the list sl indexed + * with the variable var, replace the current element with val. + * Does not deallocate the current value of var. + */ +#define SMARTLIST_REPLACE_CURRENT(sl, var, val) \ + STMT_BEGIN \ + smartlist_set(sl, var ## _sl_idx, val); \ + STMT_END + /* Helper: Given two lists of items, possibly of different types, such that * both lists are sorted on some common field (as determened by a comparison * expression cmpexpr), and such that one list (sl1) has no diff --git a/src/or/policies.c b/src/or/policies.c index 8af322440e..b6816a1615 100644 --- a/src/or/policies.c +++ b/src/or/policies.c @@ -102,6 +102,10 @@ policy_expand_private(smartlist_t **policy) * Given a linked list of config lines containing "allow" and "deny" * tokens, parse them and append the result to dest. Return -1 * if any tokens are malformed (and don't append any), else return 0. + * + * If assume_action is nonnegative, then insert its action + * (ADDR_POLICY_ACCEPT or ADDR_POLICY_REJECT) for items that specify no + * action. */ static int parse_addr_policy(config_line_t *cfg, smartlist_t **dest, @@ -399,11 +403,18 @@ load_policy_from_option(config_line_t *config, smartlist_t **policy, return -1; } if (*policy) { - SMARTLIST_FOREACH(*policy, addr_policy_t *, n, { - /* ports aren't used. */ - n->prt_min = 1; - n->prt_max = 65535; - }); + SMARTLIST_FOREACH_BEGIN(*policy, addr_policy_t *, n) { + /* ports aren't used in these. */ + if (n->prt_min > 1 || n->prt_max != 65535) { + addr_policy_t newp, *c; + memcpy(&newp, n, sizeof(newp)); + newp.prt_min = 1; + newp.prt_max = 65535; + c = addr_policy_get_canonical_entry(&newp); + SMARTLIST_REPLACE_CURRENT(*policy, n, c); + addr_policy_free(n); + } + } SMARTLIST_FOREACH_END(n); } return 0; } -- cgit v1.2.3-54-g00ecf