Replace overlay_render_sid_prefix() with alloca_tohex()

To eliminate timebomb bugs caused by rotor wraparound
This commit is contained in:
Andrew Bettison 2012-07-04 10:30:46 +09:30
parent d72e4d20ea
commit 72769e162b
10 changed files with 21 additions and 41 deletions

View File

@ -1132,7 +1132,7 @@ unsigned char *keyring_find_sas_private(keyring_file *k,unsigned char *sid,
if (sas_public)
*sas_public=
k->contexts[cn]->identities[in]->keypairs[kp]->public_key;
if (0) WHYF("Found SAS entry for %s*",overlay_render_sid_prefix(sid,7));
if (0) DEBUGF("Found SAS entry for %s*", alloca_tohex(sid, 7));
RETURN(k->contexts[cn]->identities[in]->keypairs[kp]->private_key);
}
@ -1289,10 +1289,10 @@ unsigned char *keyring_find_sas_public(keyring_file *k,unsigned char *sid)
for(i=0;i<sid_sas_mapping_count;i++)
{
if (memcmp(sid,sid_sas_mappings[i].sid,SID_SIZE)) continue;
if (sid_sas_mappings[i].validP)
{ if (0)
WHYF("Found SAS public entry for %s*",overlay_render_sid_prefix(sid,7));
RETURN(sid_sas_mappings[i].sas_public); }
if (sid_sas_mappings[i].validP) {
if (0) DEBUGF("Found SAS public entry for %s*", alloca_tohex(sid, 7));
RETURN(sid_sas_mappings[i].sas_public);
}
/* Don't flood the network with mapping requests */
if (((now-sid_sas_mappings[i].last_request_time_in_ms)<1000)
&&((now-sid_sas_mappings[i].last_request_time_in_ms)>=0))

View File

@ -309,7 +309,7 @@ int overlay_frame_process(struct overlay_interface *interface,overlay_frame *f)
if (overlay_get_nexthop(f->destination,f->nexthop,&len,
&f->nexthop_interface))
WHYF("Could not find next hop for %s* - dropping frame",
overlay_render_sid_prefix(f->destination,7));
alloca_tohex(f->destination, 7));
dontForward=1;
}
f->ttl--;

View File

@ -920,8 +920,8 @@ int overlay_tick_interface(int i, long long now)
{
if (debug&DEBUG_QUEUES)
DEBUGF("dequeuing %s* -> %s* NOW (queue length=%d)",
overlay_render_sid_prefix((*p)->source,7),
overlay_render_sid_prefix((*p)->destination,7),
alloca_tohex((*p)->source, 7),
alloca_tohex((*p)->destination, 7),
overlay_tx[q].length);
t=*p;
*p=t->next;

View File

@ -422,7 +422,7 @@ int overlay_saw_mdp_frame(overlay_mdp_frame *mdp,long long now)
if (0)
WHYF("Received packet with listener (MDP ports: src=%s*:%d, dst=%d)",
overlay_render_sid_prefix(mdp->out.src.sid,7),
alloca_tohex(mdp->out.src.sid, 7),
mdp->out.src.port,mdp->out.dst.port);

View File

@ -246,7 +246,7 @@ int overlay_payload_enqueue(int q,overlay_frame *p,int forceBroadcastP)
*/
if (0)
WHYF("Enqueuing packet for %s* (q[%d]length = %d)",
overlay_render_sid_prefix(p->destination,7),
alloca_tohex(p->destination, 7),
q,overlay_tx[q].length);
if (q==OQ_ISOCHRONOUS_VOICE&&(!forceBroadcastP)) {
/* Dispatch voice data immediately.

View File

@ -1008,23 +1008,6 @@ int overlay_route_recalc_neighbour_metrics(overlay_neighbour *n,long long now)
}
int ors_rotor=0;
char ors_out[4][SID_STRLEN+1];
char *overlay_render_sid_prefix(const unsigned char *sid,int l)
{
int zero=0;
if (l<0) l=0;
if (l>SID_STRLEN) l=SID_STRLEN;
ors_rotor++;
ors_rotor&=3;
extractSid(sid,&zero,ors_out[ors_rotor]);
ors_out[ors_rotor][l]=0;
return ors_out[ors_rotor];
}
/*
Self-announcement acks bounce back to the self-announcer from immediate neighbours
who report the link score they have calculated based on listening to self-announces
@ -1112,8 +1095,7 @@ int overlay_route_record_link(long long now,unsigned char *to,
}
DEBUGF("route_record_link(0x%llx,%s*,%s*,0x%08x-0x%08x,%d)",
now,overlay_render_sid_prefix(to,7),
overlay_render_sid_prefix(via,7),s1,s2,score);
now, alloca_tohex(to, 7), alloca_tohex(via, 7), s1, s2, score);
overlay_node *n=overlay_route_find_node(to,SID_SIZE,1 /* create node if missing */);
if (!n) return WHY("Could not find or create entry for node");
@ -1199,8 +1181,8 @@ int overlay_route_dump()
if (overlay_neighbours[n].node)
{
strbuf_sprintf(b," %s* : %lldms ago :",
overlay_render_sid_prefix(overlay_neighbours[n].node->sid,7),
(now-overlay_neighbours[n].last_observation_time_ms));
alloca_tohex(overlay_neighbours[n].node->sid, 7),
now - overlay_neighbours[n].last_observation_time_ms);
for(i=0;i<OVERLAY_MAX_INTERFACES;i++)
if (overlay_neighbours[n].scores[i])
strbuf_sprintf(b," %d(via #%d)",
@ -1216,7 +1198,7 @@ int overlay_route_dump()
{
if (!overlay_nodes[bin][slot].sid[0]) continue;
strbuf_sprintf(b," %s* : %d :",overlay_render_sid_prefix(overlay_nodes[bin][slot].sid,7),
strbuf_sprintf(b," %s* : %d :", alloca_tohex(overlay_nodes[bin][slot].sid, 7),
overlay_nodes[bin][slot].best_link_score);
for(o=0;o<OVERLAY_MAX_OBSERVATIONS;o++)
{
@ -1226,7 +1208,7 @@ int overlay_route_dump()
if (ob->corrected_score)
strbuf_sprintf(b," %d/%d via %s*",
ob->corrected_score,ob->gateways_en_route,
overlay_render_sid_prefix(ob->sender_prefix,7));
alloca_tohex(ob->sender_prefix, 7));
}
}
strbuf_sprintf(b,"\n");
@ -1358,8 +1340,7 @@ int overlay_route_node_info(overlay_mdp_frame *mdp,
if (0)
DEBUGF("Looking for node %s* (prefix len=0x%x)",
overlay_render_sid_prefix(mdp->nodeinfo.sid,
mdp->nodeinfo.sid_prefix_length),
alloca_tohex(mdp->nodeinfo.sid, mdp->nodeinfo.sid_prefix_length),
mdp->nodeinfo.sid_prefix_length
);

View File

@ -342,7 +342,7 @@ int rhizome_add_manifest(rhizome_manifest *m_in,int ttl)
return WHY("rhizome_store_bundle() failed.");
DEBUGF("Announcing arrival of manifest %s* version %lld",
overlay_render_sid_prefix(m_in->cryptoSignPublic,8),m_in->version);
alloca_tohex(m_in->cryptoSignPublic, 8), m_in->version);
monitor_announce_bundle(m_in);
return 0;
}

View File

@ -238,7 +238,7 @@ int overlay_rhizome_add_advertisements(int interface_number,overlay_buffer *e)
long long version = rhizome_manifest_get_ll(m, "version");
DEBUGF("Stop cramming %s advertisements: not enough space for %s*:v%lld (%d bytes, size limit=%d, used=%d)",
pass?"BARs":"manifests",
overlay_render_sid_prefix(m->cryptoSignPublic,8),
alloca_tohex(m->cryptoSignPublic, 8),
version,
blob_bytes,e->sizeLimit,e->length);
rhizome_manifest_free(m);
@ -277,7 +277,7 @@ int overlay_rhizome_add_advertisements(int interface_number,overlay_buffer *e)
(m, (char *)&e->bytes[e->length+overhead], blob_bytes);
long long version = rhizome_manifest_get_ll(m, "version");
WHYF("Advertising manifest %s* version %lld",
overlay_render_sid_prefix(m->cryptoSignPublic,8),
alloca_tohex(m->cryptoSignPublic, 8),
version);
rhizome_manifest_free(m);
}

View File

@ -1343,7 +1343,6 @@ int overlay_mdp_dispatch(overlay_mdp_frame *mdp,int userGeneratedFrameP,
int ob_bcopy(overlay_buffer *b,int from, int to, int len);
int ob_setbyte(overlay_buffer *b,int ofs,unsigned char value);
char *overlay_render_sid_prefix(const unsigned char *sid,int l);
int dump_payload(overlay_frame *p,char *message);
int urandombytes(unsigned char *x,unsigned long long xlen);

4
vomp.c
View File

@ -1198,8 +1198,8 @@ int app_vomp_status(int argc, const char *const *argv, struct command_line_optio
mdp2.vompevent.call_session_token);
else {
fprintf(stderr,"%s* -> %s* (%s -> %s)",
overlay_render_sid_prefix(mdp2.vompevent.local_sid,6),
overlay_render_sid_prefix(mdp2.vompevent.remote_sid,6),
alloca_tohex(mdp2.vompevent.local_sid, 6),
alloca_tohex(mdp2.vompevent.remote_sid, 6),
strlen(mdp2.vompevent.local_did)
?mdp2.vompevent.local_did:"<no local number>",
strlen(mdp2.vompevent.remote_did)