diff options
author | Nick Mathewson <nickm@torproject.org> | 2013-07-08 11:35:25 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2013-07-08 11:35:25 -0400 |
commit | 7a4145c45aa0833af96cdb4b5c3fba90731c7037 (patch) | |
tree | 9c27e7b6629a83b3f1872b9e3f3d71225ad1e74e | |
parent | c78c8de015ac62eb3fa529f932bcf86dae9f3d9d (diff) | |
parent | b34279d3ab2bae2a1393427e0866da018cf8b678 (diff) | |
download | tor-7a4145c45aa0833af96cdb4b5c3fba90731c7037.tar.gz tor-7a4145c45aa0833af96cdb4b5c3fba90731c7037.zip |
Merge branch 'bug9200' into maint-0.2.4
-rw-r--r-- | changes/bug9200 | 5 | ||||
-rw-r--r-- | src/or/dirvote.c | 14 |
2 files changed, 17 insertions, 2 deletions
diff --git a/changes/bug9200 b/changes/bug9200 new file mode 100644 index 0000000000..7b64dd1744 --- /dev/null +++ b/changes/bug9200 @@ -0,0 +1,5 @@ + o Major bugfixes: + - Fix a bug in the voting algorithm that could yield incorrect results + when a non-naming authority declared too many flags. Fixes bug 9200; + bugfix on 0.2.0.3-alpha. + diff --git a/src/or/dirvote.c b/src/or/dirvote.c index 0c386e604e..e0af66e22d 100644 --- a/src/or/dirvote.c +++ b/src/or/dirvote.c @@ -1590,10 +1590,19 @@ networkstatus_compute_consensus(smartlist_t *votes, unnamed_flag[i] = named_flag[i] = -1; chosen_named_idx = smartlist_string_pos(flags, "Named"); - /* Build the flag index. */ + /* Build the flag indexes. Note that no vote can have more than 64 members + * for known_flags, so no value will be greater than 63, so it's safe to + * do U64_LITERAL(1) << index on these values. But note also that + * named_flag and unnamed_flag are initialized to -1, so we need to check + * that they're actually set before doing U64_LITERAL(1) << index with + * them.*/ SMARTLIST_FOREACH_BEGIN(votes, networkstatus_t *, v) { flag_map[v_sl_idx] = tor_malloc_zero( sizeof(int)*smartlist_len(v->known_flags)); + if (smartlist_len(v->known_flags) > MAX_KNOWN_FLAGS_IN_VOTE) { + log_warn(LD_BUG, "Somehow, a vote has %d entries in known_flags", + smartlist_len(v->known_flags)); + } SMARTLIST_FOREACH_BEGIN(v->known_flags, const char *, fl) { int p = smartlist_string_pos(flags, fl); tor_assert(p >= 0); @@ -1727,7 +1736,8 @@ networkstatus_compute_consensus(smartlist_t *votes, if (rs->flags & (U64_LITERAL(1) << i)) ++flag_counts[flag_map[v_sl_idx][i]]; } - if (rs->flags & (U64_LITERAL(1) << named_flag[v_sl_idx])) { + if (named_flag[v_sl_idx] >= 0 && + (rs->flags & (U64_LITERAL(1) << named_flag[v_sl_idx]))) { if (chosen_name && strcmp(chosen_name, rs->status.nickname)) { log_notice(LD_DIR, "Conflict on naming for router: %s vs %s", chosen_name, rs->status.nickname); |