]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Reject votes (not consensuses) with >64 known-flags
authorNick Mathewson <nickm@torproject.org>
Thu, 13 Sep 2012 15:45:05 +0000 (11:45 -0400)
committerNick Mathewson <nickm@torproject.org>
Thu, 13 Sep 2012 15:45:05 +0000 (11:45 -0400)
Our flag voting code needs to handle unrecognized flags, so it stores
them in a 64-bit bitfield.  But we never actually checked for too many
flags, so we were potentially doing stuff like U64_LITERAL(1)<<flagnum
with flagnum >= 64.  That's undefined behavior.

Fix for bug 6833; bugfix on 0.2.0.1-alpha.

changes/bug6833 [new file with mode: 0644]
src/or/or.h
src/or/routerparse.c

diff --git a/changes/bug6833 b/changes/bug6833
new file mode 100644 (file)
index 0000000..4a6a5d3
--- /dev/null
@@ -0,0 +1,4 @@
+  o Minor bugfixes (directory authority):
+    - Reject consensus votes with more than 64 known-flags. We aren't even
+      close to that limit yet, and our code doesn't handle it
+      correctly. Fixes bug 6833; bugfix on 0.2.0.1-alpha.
index bb5482bf8383a58f644e1fae2a2f2e4873e393ce..f7914b830dfda6eb45ec6e2eec342ac8f58ba839 100644 (file)
@@ -2101,6 +2101,9 @@ typedef struct vote_microdesc_hash_t {
 typedef struct vote_routerstatus_t {
   routerstatus_t status; /**< Underlying 'status' object for this router.
                           * Flags are redundant. */
+  /** How many known-flags are allowed in a vote? This is the width of
+   * the flags field of vote_routerstatus_t */
+#define MAX_KNOWN_FLAGS_IN_VOTE 64
   uint64_t flags; /**< Bit-field for all recognized flags; index into
                    * networkstatus_t.known_flags. */
   char *version; /**< The version that the authority says this router is
index 22f7d78d88c117258328aa9c6e419d60faa16674..496b90d4ad412fd38a6eaf71907332779ea7bc0d 100644 (file)
@@ -3004,6 +3004,11 @@ networkstatus_parse_vote_from_string(const char *s, const char **eos_out,
     log_warn(LD_DIR, "known-flags not in order");
     goto err;
   }
+  if (ns->type != NS_TYPE_CONSENSUS &&
+      smartlist_len(ns->known_flags) > MAX_KNOWN_FLAGS_IN_VOTE) {
+    log_warn(LD_DIR, "Too many known-flags in consensus vote or opinion");
+    goto err;
+  }
 
   tok = find_opt_by_keyword(tokens, K_PARAMS);
   if (tok) {