Also special case "accept 1-65535" case, do not leak in non-exit case

svn:r16526
This commit is contained in:
Peter Palfrader 2008-08-13 12:46:00 +00:00
parent 8ef2fe4b37
commit c4e8fe11db

View File

@ -1086,7 +1086,9 @@ policy_summary_add_item(smartlist_t *summary, addr_policy_t *p)
* The summary will either be an "accept" plus a comma-seperated list of port * The summary will either be an "accept" plus a comma-seperated list of port
* ranges or a "reject" plus portranges, depending on which is shorter. * ranges or a "reject" plus portranges, depending on which is shorter.
* *
* If no exits are allowed at all then NULL is returned. * If no exits are allowed at all then NULL is returned, if no ports
* are blocked instead of "reject " we return "accept 1-65535" (this
* is an exception to the shorter-representation-wins rule).
*/ */
char * char *
policy_summarize(smartlist_t *policy) policy_summarize(smartlist_t *policy)
@ -1095,7 +1097,7 @@ policy_summarize(smartlist_t *policy)
smartlist_t *accepts, *rejects; smartlist_t *accepts, *rejects;
int i, last, start_prt; int i, last, start_prt;
size_t accepts_len, rejects_len, shorter_len, final_size; size_t accepts_len, rejects_len, shorter_len, final_size;
char *accepts_str, *rejects_str, *shorter_str, *result; char *accepts_str = NULL, *rejects_str = NULL, *shorter_str, *result;
const char *prefix; const char *prefix;
tor_assert(policy); tor_assert(policy);
@ -1141,8 +1143,14 @@ policy_summarize(smartlist_t *policy)
/* Figure out which of the two stringlists will be shorter and use /* Figure out which of the two stringlists will be shorter and use
* that to build the result * that to build the result
*/ */
if (smartlist_len(accepts) == 0) /* no exits at all */ if (smartlist_len(accepts) == 0) { /* no exits at all */
return NULL; result = NULL;
goto cleanup;
}
if (smartlist_len(rejects) == 0) { /* no rejects at all */
result = tor_strdup("accept 1-65535");
goto cleanup;
}
accepts_str = smartlist_join_strings(accepts, ",", 0, &accepts_len); accepts_str = smartlist_join_strings(accepts, ",", 0, &accepts_len);
rejects_str = smartlist_join_strings(rejects, ",", 0, &rejects_len); rejects_str = smartlist_join_strings(rejects, ",", 0, &rejects_len);
@ -1161,6 +1169,7 @@ policy_summarize(smartlist_t *policy)
result = malloc(final_size); result = malloc(final_size);
tor_snprintf(result, final_size, "%s %s", prefix, shorter_str); tor_snprintf(result, final_size, "%s %s", prefix, shorter_str);
cleanup:
/* cleanup */ /* cleanup */
SMARTLIST_FOREACH(summary, policy_summary_item_t *, s, tor_free(s)); SMARTLIST_FOREACH(summary, policy_summary_item_t *, s, tor_free(s));
smartlist_clear(summary); smartlist_clear(summary);