[or-cvs] r16526: {tor} Also special case "accept 1-65535" case, do not leak in non- (tor/trunk/src/or)

weasel at seul.org weasel at seul.org
Wed Aug 13 12:46:01 UTC 2008


Author: weasel
Date: 2008-08-13 08:46:00 -0400 (Wed, 13 Aug 2008)
New Revision: 16526

Modified:
   tor/trunk/src/or/policies.c
Log:
Also special case "accept 1-65535" case, do not leak in non-exit case

Modified: tor/trunk/src/or/policies.c
===================================================================
--- tor/trunk/src/or/policies.c	2008-08-13 12:45:53 UTC (rev 16525)
+++ tor/trunk/src/or/policies.c	2008-08-13 12:46:00 UTC (rev 16526)
@@ -1086,7 +1086,9 @@
  * 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 @@
   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 @@
   /* 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 @@
   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);



More information about the tor-commits mailing list