]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
We should not alter an addr_policy_t that has been canonicalized.
authorNick Mathewson <nickm@torproject.org>
Tue, 9 Sep 2008 03:48:01 +0000 (03:48 +0000)
committerNick Mathewson <nickm@torproject.org>
Tue, 9 Sep 2008 03:48:01 +0000 (03:48 +0000)
svn:r16802

ChangeLog
src/common/container.h
src/or/policies.c

index 652dccf6f2c6d336d3897da90cb22fcee9e53521..78db5f96fbe0fb294d6575c4f2c83cefbd1306e2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -10,6 +10,8 @@ Changes in version 0.2.1.6-alpha - 2008-09-xx
       say which? -NM)
     - When testing for libevent functions, set the LDFLAGS variable
       correctly.  (Found by Riastradh.)
+    - Fix an assertion bug in parsing policy-related options; possible fix
+      for bug 811.
 
   o Minor features:
     - Use a lockfile to make sure that two Tor processes are not
index 6faad3435daf0c33e7cdeadeff68fcd807d65772..598e27aaa5a1097be44d7afcca29b5f0d71988cd 100644 (file)
@@ -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 <b>sl</b> indexed
+ * with the variable <b>var</b>, replace the current element with <b>val</b>.
+ * Does not deallocate the current value of <b>var</b>.
+ */
+#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 <b>cmpexpr</b>), and such that one list (<b>sl1</b>) has no
index 8af322440ec1adb4493bcdd308ae341cb2c613b8..b6816a161530055f1a3374f3bc3d593aa8f008db 100644 (file)
@@ -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 <b>dest</b>. Return -1
  * if any tokens are malformed (and don't append any), else return 0.
+ *
+ * If <b>assume_action</b> 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;
 }