diff --git a/neighbours.cpp b/neighbours.cpp index 8693360..5a80298 100644 --- a/neighbours.cpp +++ b/neighbours.cpp @@ -94,6 +94,7 @@ void Neighbours::fullUpdate() { void Neighbours::addPotentialNei(const Neighbour& nei) { if(neiType.find(nei.id) != neiType.end()) return; // We already know him + fprintf(stderr, "[INFO] Adding potential neighbour %lX\n", nei.id); potentialNei.push_back(nei); lastRecv.insert({nei.id, 0}); lastIHU.insert({nei.id, 0}); diff --git a/packetParser.cpp b/packetParser.cpp index c5ec304..071b6e2 100644 --- a/packetParser.cpp +++ b/packetParser.cpp @@ -14,6 +14,11 @@ PacketParser::PacketParser(Neighbours* nei, Protocol* proto, void PacketParser::parse(Bytes pck, const SockAddr& addr) { u64 peerId; + if(pck.size() < 8) { + fprintf(stderr, "[WARNING] Bad packet size.\n"); + return; + } + pck >> peerId; 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) { u8 type, len; + if(pck.size() < 2) { + fprintf(stderr, "[WARNING] Bad packet size from %lX.\n", nei); + return; + } pck >> type >> len; fprintf(stderr, "[INFO] Parsing %d from %lX.\n", type, nei); @@ -86,8 +95,6 @@ void PacketParser::receiveNeigh(Bytes& pck) { if(id == protocol->getSelfId()) continue; - fprintf(stderr, "[INFO] Adding neighbour %lX\n", id); - Neighbour nei(id, addr); neighbours->addPotentialNei(nei); }