diff options
author | Nick Mathewson <nickm@torproject.org> | 2007-05-19 20:08:44 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2007-05-19 20:08:44 +0000 |
commit | 6f8866a817ad96494d84d3d05b68ee3b0b72545f (patch) | |
tree | 74d93e5d614830c72af135ed8c31ae431a29cc64 | |
parent | 4d3ec5919eaa470720eb814ff83dd8a7d280c547 (diff) | |
download | tor-6f8866a817ad96494d84d3d05b68ee3b0b72545f.tar tor-6f8866a817ad96494d84d3d05b68ee3b0b72545f.tar.gz |
r12810@catbus: nickm | 2007-05-19 16:08:42 -0400
Fix bugs in extrainfo_insert, and change it to use desc_by_eid_map.
svn:r10222
-rw-r--r-- | src/or/routerlist.c | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/src/or/routerlist.c b/src/or/routerlist.c index bfaeda897..7031ca79c 100644 --- a/src/or/routerlist.c +++ b/src/or/routerlist.c @@ -1780,32 +1780,29 @@ extrainfo_insert(routerlist_t *rl, extrainfo_t *ei) int r = 0; routerinfo_t *ri = digestmap_get(rl->identity_map, ei->cache_info.identity_digest); + signed_descriptor_t *sd; extrainfo_t *ei_tmp; routerlist_check_bug_417(); - if (!ri || routerinfo_incompatible_with_extrainfo(ri,ei)) { - int found = 0; - if (ei->pending_sig || ei->bad_sig) { - extrainfo_free(ei); + + if (!ri) { + /* This router is unknown; we can't even verify the signature. Give up.*/ + goto done; + } + if (routerinfo_incompatible_with_extrainfo(ri, ei)) { + if (ei->bad_sig) /* If the signature didn't check, it's just wrong. */ goto done; - } - /* The signature checks out; let's see if one of the old routers - * matches. */ - SMARTLIST_FOREACH(rl->old_routers, signed_descriptor_t *, sd, { - if (!memcmp(ei->cache_info.identity_digest, - sd->identity_digest, DIGEST_LEN) && - !memcmp(ei->cache_info.signed_descriptor_digest, - sd->extra_info_digest, DIGEST_LEN) && - sd->published_on == ei->cache_info.published_on) { - found = 1; - break; - } - }); - if (!found) { - extrainfo_free(ei); + sd = digestmap_get(rl->desc_by_eid_map, + ei->cache_info.signed_descriptor_digest); + if (!sd || + memcmp(sd->identity_digest, ei->cache_info.identity_digest, + DIGEST_LEN) || + sd->published_on != ei->cache_info.published_on) goto done; - } } + /* Okay, if we make it here, we definitely have a router corresponding to + * this extrainfo. */ + ei_tmp = digestmap_set(rl->extra_info_map, ei->cache_info.signed_descriptor_digest, ei); @@ -1814,6 +1811,9 @@ extrainfo_insert(routerlist_t *rl, extrainfo_t *ei) extrainfo_free(ei_tmp); done: + if (r == 0) + extrainfo_free(ei); + #ifdef DEBUG_ROUTERLIST routerlist_assert_ok(rl); #endif @@ -4862,6 +4862,10 @@ routerinfo_incompatible_with_extrainfo(routerinfo_t *ri, extrainfo_t *ei) tor_free(ei->pending_sig); } + if (memcmp(ei->cache_info.signed_descriptor_digest, + ri->cache_info.extra_info_digest, DIGEST_LEN)) + return 1; /* Digest doesn't match declared value. */ + if (ei->cache_info.published_on < ei->cache_info.published_on) return 1; else if (ei->cache_info.published_on > ei->cache_info.published_on) |