[General] Add integrity checks to Handshake packet

This commit is contained in:
Koncord 2018-07-03 18:40:58 +08:00 committed by Koncord
parent f9ff5f10df
commit 1f4e6e9114
3 changed files with 17 additions and 2 deletions

View file

@ -99,6 +99,13 @@ void Networking::processPlayerPacket(RakNet::Packet *packet)
myPacket->setPlayer(player);
myPacket->Read();
if (!myPacket->isPacketValid())
{
LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, "Invalid handshake packet from %d", player->getId());
kickPlayer(player->guid);
return;
}
if (player->isHandshaked())
{
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Wrong handshake with player %d, name: %s", player->getId(),

View file

@ -16,6 +16,11 @@ PacketHandshake::PacketHandshake(RakNet::RakPeerInterface *peer) : PlayerPacket(
void PacketHandshake::Packet(RakNet::BitStream *bs, bool send)
{
PlayerPacket::Packet(bs, send);
RW(player->npc.mName, send);
RW(player->passw, send);
if (!RW(player->npc.mName, send, true, maxNameLen) ||
!RW(player->passw, send, true, maxPasswLen))
{
packetValid = false;
return;
}
}

View file

@ -15,6 +15,9 @@ namespace mwmp
PacketHandshake(RakNet::RakPeerInterface *peer);
virtual void Packet(RakNet::BitStream *bs, bool send);
const static uint32_t maxNameLen = 256;
const static uint32_t maxPasswLen = 256;
};
}