Improve robustness to badly shaped packets
This commit is contained in:
parent
e8a2c37d96
commit
676a3822ed
2 changed files with 10 additions and 2 deletions
|
@ -94,6 +94,7 @@ void Neighbours::fullUpdate() {
|
||||||
void Neighbours::addPotentialNei(const Neighbour& nei) {
|
void Neighbours::addPotentialNei(const Neighbour& nei) {
|
||||||
if(neiType.find(nei.id) != neiType.end())
|
if(neiType.find(nei.id) != neiType.end())
|
||||||
return; // We already know him
|
return; // We already know him
|
||||||
|
fprintf(stderr, "[INFO] Adding potential neighbour %lX\n", nei.id);
|
||||||
potentialNei.push_back(nei);
|
potentialNei.push_back(nei);
|
||||||
lastRecv.insert({nei.id, 0});
|
lastRecv.insert({nei.id, 0});
|
||||||
lastIHU.insert({nei.id, 0});
|
lastIHU.insert({nei.id, 0});
|
||||||
|
|
|
@ -14,6 +14,11 @@ PacketParser::PacketParser(Neighbours* nei, Protocol* proto,
|
||||||
|
|
||||||
void PacketParser::parse(Bytes pck, const SockAddr& addr) {
|
void PacketParser::parse(Bytes pck, const SockAddr& addr) {
|
||||||
u64 peerId;
|
u64 peerId;
|
||||||
|
if(pck.size() < 8) {
|
||||||
|
fprintf(stderr, "[WARNING] Bad packet size.\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
pck >> peerId;
|
pck >> peerId;
|
||||||
neighbours->receivedFrom(peerId, addr);
|
neighbours->receivedFrom(peerId, addr);
|
||||||
|
|
||||||
|
@ -24,6 +29,10 @@ void PacketParser::parse(Bytes pck, const SockAddr& addr) {
|
||||||
|
|
||||||
void PacketParser::readTLV(Bytes& pck, u64 nei, const SockAddr& addr) {
|
void PacketParser::readTLV(Bytes& pck, u64 nei, const SockAddr& addr) {
|
||||||
u8 type, len;
|
u8 type, len;
|
||||||
|
if(pck.size() < 2) {
|
||||||
|
fprintf(stderr, "[WARNING] Bad packet size from %lX.\n", nei);
|
||||||
|
return;
|
||||||
|
}
|
||||||
pck >> type >> len;
|
pck >> type >> len;
|
||||||
|
|
||||||
fprintf(stderr, "[INFO] Parsing %d from %lX.\n", type, nei);
|
fprintf(stderr, "[INFO] Parsing %d from %lX.\n", type, nei);
|
||||||
|
@ -86,8 +95,6 @@ void PacketParser::receiveNeigh(Bytes& pck) {
|
||||||
if(id == protocol->getSelfId())
|
if(id == protocol->getSelfId())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
fprintf(stderr, "[INFO] Adding neighbour %lX\n", id);
|
|
||||||
|
|
||||||
Neighbour nei(id, addr);
|
Neighbour nei(id, addr);
|
||||||
neighbours->addPotentialNei(nei);
|
neighbours->addPotentialNei(nei);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue