summaryrefslogtreecommitdiff
path: root/src/or/dirvote.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2017-02-15 07:48:42 -0500
committerNick Mathewson <nickm@torproject.org>2017-02-15 07:48:42 -0500
commit76d79d597aeba1d9182414acf038ed376cd5139c (patch)
tree4a666199c7c3d186060a162d86a9d82b0044ce3e /src/or/dirvote.c
parentdec7dc3d823a8a9cc1d9d75d1b803a6e6b308a8e (diff)
parent5d88267bf47fb532b53691ab428cbfd9db3881cf (diff)
downloadtor-76d79d597aeba1d9182414acf038ed376cd5139c.tar.gz
tor-76d79d597aeba1d9182414acf038ed376cd5139c.zip
Merge branch 'maint-0.2.9'
Diffstat (limited to 'src/or/dirvote.c')
-rw-r--r--src/or/dirvote.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/or/dirvote.c b/src/or/dirvote.c
index d14af41667..e92d3b49dc 100644
--- a/src/or/dirvote.c
+++ b/src/or/dirvote.c
@@ -454,16 +454,30 @@ compare_vote_rs(const vote_routerstatus_t *a, const vote_routerstatus_t *b)
b->status.descriptor_digest,
DIGEST_LEN)))
return r;
- if ((r = (int)(b->status.published_on - a->status.published_on)))
- return r;
+ /* If we actually reached this point, then the identities and
+ * the descriptor digests matched, so somebody is making SHA1 collisions.
+ */
+#define CMP_FIELD(utype, itype, field) do { \
+ utype aval = (utype) (itype) a->status.field; \
+ utype bval = (utype) (itype) b->status.field; \
+ utype u = bval - aval; \
+ itype r2 = (itype) u; \
+ if (r2 < 0) { \
+ return -1; \
+ } else if (r2 > 0) { \
+ return 1; \
+ } \
+ } while (0)
+
+ CMP_FIELD(uint64_t, int64_t, published_on);
+
if ((r = strcmp(b->status.nickname, a->status.nickname)))
return r;
- if ((r = (((int)b->status.addr) - ((int)a->status.addr))))
- return r;
- if ((r = (((int)b->status.or_port) - ((int)a->status.or_port))))
- return r;
- if ((r = (((int)b->status.dir_port) - ((int)a->status.dir_port))))
- return r;
+
+ CMP_FIELD(unsigned, int, addr);
+ CMP_FIELD(unsigned, int, or_port);
+ CMP_FIELD(unsigned, int, dir_port);
+
return 0;
}