[General] Add basic integrity check to reading of ActorList packets

Additionally, add newlines to files missing them.
This commit is contained in:
David Cernat 2017-05-16 14:20:40 +03:00
parent 252a28fe24
commit f527fe9ebe
11 changed files with 46 additions and 22 deletions

View file

@ -36,11 +36,16 @@ bool ActorProcessor::Process(RakNet::Packet &packet, BaseActorList &actorList) n
ActorPacket *myPacket = Networking::get().getActorPacketController()->GetPacket(packet.data[0]); ActorPacket *myPacket = Networking::get().getActorPacketController()->GetPacket(packet.data[0]);
myPacket->setActorList(&actorList); myPacket->setActorList(&actorList);
actorList.isValid = true;
if (!processor.second->avoidReading) if (!processor.second->avoidReading)
myPacket->Read(); myPacket->Read();
processor.second->Do(*myPacket, *player, actorList); if (actorList.isValid)
processor.second->Do(*myPacket, *player, actorList);
else
LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, "Received %s that failed integrity check and was ignored!", processor.second->strPacketID.c_str());
return true; return true;
} }
} }

View file

@ -22,22 +22,27 @@ bool ActorProcessor::Process(RakNet::Packet &packet, ActorList &actorList)
myPacket->SetReadStream(&bsIn); myPacket->SetReadStream(&bsIn);
BOOST_FOREACH(processors_t::value_type &processor, processors) BOOST_FOREACH(processors_t::value_type &processor, processors)
{ {
if (processor.first == packet.data[0]) if (processor.first == packet.data[0])
{ {
myGuid = Main::get().getLocalPlayer()->guid; myGuid = Main::get().getLocalPlayer()->guid;
request = packet.length == myPacket->headerSize(); request = packet.length == myPacket->headerSize();
if (!request && !processor.second->avoidReading) actorList.isValid = true;
{
myPacket->Read();
}
processor.second->Do(*myPacket, actorList); if (!request && !processor.second->avoidReading)
{
myPacket->Read();
}
return true; if (actorList.isValid)
} processor.second->Do(*myPacket, actorList);
} else
LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, "Received %s that failed integrity check and was ignored!", processor.second->strPacketID.c_str());
return true;
}
}
return false; return false;
} }

View file

@ -70,6 +70,8 @@ namespace mwmp
ESM::Cell cell; ESM::Cell cell;
unsigned char action; // 0 - Clear and set in entirety, 1 - Add item, 2 - Remove item, 3 - Request items unsigned char action; // 0 - Clear and set in entirety, 1 - Add item, 2 - Remove item, 3 - Request items
bool isValid;
}; };
} }

View file

@ -25,6 +25,12 @@ void PacketActorList::Packet(RakNet::BitStream *bs, bool send)
RW(actorList->count, send); RW(actorList->count, send);
if (actorList->count > 2000)
{
actorList->isValid = false;
return;
}
RW(actorList->cell.mData.mFlags, send); RW(actorList->cell.mData.mFlags, send);
RW(actorList->cell.mData.mX, send); RW(actorList->cell.mData.mX, send);
RW(actorList->cell.mData.mY, send); RW(actorList->cell.mData.mY, send);
@ -43,6 +49,12 @@ void PacketActorList::Packet(RakNet::BitStream *bs, bool send)
RW(actor.refNumIndex, send); RW(actor.refNumIndex, send);
RW(actor.mpNum, send); RW(actor.mpNum, send);
if (actor.refId.empty() || (actor.refNumIndex != 0 && actor.mpNum != 0))
{
actorList->isValid = false;
return;
}
if (!send) if (!send)
{ {
actorList->baseActors.push_back(actor); actorList->baseActors.push_back(actor);