summaryrefslogtreecommitdiff
path: root/src/or/policies.c
diff options
context:
space:
mode:
authorPeter Palfrader <peter@palfrader.org>2008-08-13 12:46:00 +0000
committerPeter Palfrader <peter@palfrader.org>2008-08-13 12:46:00 +0000
commitc4e8fe11db76a98f685ea443f0a632206fa43991 (patch)
treeb98affa5142eccf4186d0df9b9138c80258c5106 /src/or/policies.c
parent8ef2fe4b3722016a1f801a6d0fdc6dd81715baab (diff)
downloadtor-c4e8fe11db76a98f685ea443f0a632206fa43991.tar.gz
tor-c4e8fe11db76a98f685ea443f0a632206fa43991.zip
Also special case "accept 1-65535" case, do not leak in non-exit case
svn:r16526
Diffstat (limited to 'src/or/policies.c')
-rw-r--r--src/or/policies.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/or/policies.c b/src/or/policies.c
index 9489eef48a..1efc60adc0 100644
--- a/src/or/policies.c
+++ b/src/or/policies.c
@@ -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
* 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 *
policy_summarize(smartlist_t *policy)
@@ -1095,7 +1097,7 @@ policy_summarize(smartlist_t *policy)
smartlist_t *accepts, *rejects;
int i, last, start_prt;
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;
tor_assert(policy);
@@ -1141,8 +1143,14 @@ policy_summarize(smartlist_t *policy)
/* Figure out which of the two stringlists will be shorter and use
* that to build the result
*/
- if (smartlist_len(accepts) == 0) /* no exits at all */
- return NULL;
+ if (smartlist_len(accepts) == 0) { /* no exits at all */
+ 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);
rejects_str = smartlist_join_strings(rejects, ",", 0, &rejects_len);
@@ -1161,6 +1169,7 @@ policy_summarize(smartlist_t *policy)
result = malloc(final_size);
tor_snprintf(result, final_size, "%s %s", prefix, shorter_str);
+cleanup:
/* cleanup */
SMARTLIST_FOREACH(summary, policy_summary_item_t *, s, tor_free(s));
smartlist_clear(summary);