diff --git a/src/or/or.h b/src/or/or.h index 2ffda7cd33..f8c8e1eb71 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -1119,7 +1119,6 @@ typedef enum { /** A linked list of policy rules */ typedef struct addr_policy_t { addr_policy_action_t policy_type; /**< What to do when the policy matches.*/ - char *string; /**< String representation of this rule. */ /* XXXX020 make this ipv6-capable */ uint32_t addr; /**< Base address to accept or reject. */ diff --git a/src/or/policies.c b/src/or/policies.c index ba3a375a1b..4cb7047219 100644 --- a/src/or/policies.c +++ b/src/or/policies.c @@ -486,8 +486,11 @@ exit_policy_remove_redundancies(addr_policy_t **dest) tmp=ap; while (tmp) { if (tmp->next && addr_policy_covers(ap, tmp->next)) { + char p1[POLICY_BUF_LEN], p2[POLICY_BUF_LEN]; + policy_write_item(p1, sizeof(p1), tmp->next); + policy_write_item(p2, sizeof(p2), ap); log(LOG_DEBUG, LD_CONFIG, "Removing exit policy %s. It is made " - "redundant by %s.", tmp->next->string, ap->string); + "redundant by %s.", p1, p2); victim = tmp->next; tmp->next = victim->next; victim->next = NULL; @@ -516,8 +519,11 @@ exit_policy_remove_redundancies(addr_policy_t **dest) } } else { /* policy_types are equal. */ if (addr_policy_covers(tmp, ap)) { + char p1[POLICY_BUF_LEN], p2[POLICY_BUF_LEN]; + policy_write_item(p1, sizeof(p1), ap); + policy_write_item(p2, sizeof(p2), tmp); log(LOG_DEBUG, LD_CONFIG, "Removing exit policy %s. It is already " - "covered by %s.", ap->string, tmp->string); + "covered by %s.", ap, tmp); victim = ap; ap = ap->next; @@ -694,7 +700,6 @@ addr_policy_free(addr_policy_t *p) while (p) { e = p; p = p->next; - tor_free(e->string); tor_free(e); } } diff --git a/src/or/routerparse.c b/src/or/routerparse.c index ac1c565d71..84d0c24e4d 100644 --- a/src/or/routerparse.c +++ b/src/or/routerparse.c @@ -2480,7 +2480,6 @@ router_parse_addr_policy(directory_token_t *tok) { addr_policy_t *newe; char *arg; - char buf[POLICY_BUF_LEN]; tor_assert(tok->tp == K_REJECT || tok->tp == K_ACCEPT); @@ -2500,10 +2499,6 @@ router_parse_addr_policy(directory_token_t *tok) &newe->prt_min, &newe->prt_max)) goto policy_read_failed; - if (policy_write_item(buf, sizeof(buf), newe) < 0) - goto policy_read_failed; - - newe->string = tor_strdup(buf); return newe; policy_read_failed: @@ -2540,16 +2535,13 @@ router_parse_addr_policy_private(directory_token_t *tok) nextp = &result; for (net = 0; private_nets[net]; ++net) { - size_t len; + char buf[POLICY_BUF_LEN]; *nextp = tor_malloc_zero(sizeof(addr_policy_t)); (*nextp)->policy_type = (tok->tp == K_REJECT) ? ADDR_POLICY_REJECT : ADDR_POLICY_ACCEPT; - len = strlen(arg)+strlen(private_nets[net])+16; - (*nextp)->string = tor_malloc(len+1); - tor_snprintf((*nextp)->string, len, "%s %s%s", - tok->tp == K_REJECT ? "reject" : "accept", + tor_snprintf(buf, sizeof(buf), "%s%s", private_nets[net], arg); - if (parse_addr_and_port_range((*nextp)->string + 7, + if (parse_addr_and_port_range(buf, &(*nextp)->addr, &(*nextp)->maskbits, &(*nextp)->prt_min, &(*nextp)->prt_max)) { log_warn(LD_BUG, "Couldn't parse an address range we generated!"); @@ -2565,22 +2557,10 @@ router_parse_addr_policy_private(directory_token_t *tok) void assert_addr_policy_ok(addr_policy_t *t) { - addr_policy_t *t2; while (t) { tor_assert(t->policy_type == ADDR_POLICY_REJECT || t->policy_type == ADDR_POLICY_ACCEPT); tor_assert(t->prt_min <= t->prt_max); - t2 = router_parse_addr_policy_from_string(t->string, -1); - tor_assert(t2); - tor_assert(t2->policy_type == t->policy_type); - tor_assert(t2->addr == t->addr); - tor_assert(t2->maskbits == t->maskbits); - tor_assert(t2->prt_min == t->prt_min); - tor_assert(t2->prt_max == t->prt_max); - tor_assert(!strcmp(t2->string, t->string)); - tor_assert(t2->next == NULL); - addr_policy_free(t2); - t = t->next; } diff --git a/src/or/test.c b/src/or/test.c index f556e4101b..0cabd71355 100644 --- a/src/or/test.c +++ b/src/or/test.c @@ -2191,7 +2191,6 @@ test_dir_format(void) r1.platform = tor_strdup(platform); ex1.policy_type = ADDR_POLICY_ACCEPT; - ex1.string = NULL; ex1.addr = 0; ex1.maskbits = 0; ex1.prt_min = ex1.prt_max = 80; @@ -2925,7 +2924,6 @@ test_policies(void) test_eq(16, policy->maskbits); test_eq(1, policy->prt_min); test_eq(65535, policy->prt_max); - test_streq("reject 192.168.0.0/16:*", policy->string); test_assert(ADDR_POLICY_ACCEPTED == compare_addr_to_addr_policy(0x01020304u, 2, policy)); @@ -2957,8 +2955,8 @@ test_policies(void) line.next = NULL; test_assert(0 == policies_parse_exit_policy(&line, &policy, 0, NULL)); test_assert(policy); - test_streq(policy->string, "accept *:80"); - test_streq(policy->next->string, "reject *:*"); + //test_streq(policy->string, "accept *:80"); + //test_streq(policy->next->string, "reject *:*"); test_eq_ptr(policy->next->next, NULL); addr_policy_free(policy);