[General] Add integrity checks to Handshake packet

0.6.3
Koncord 7 years ago committed by Koncord
parent f9ff5f10df
commit 1f4e6e9114

@ -99,6 +99,13 @@ void Networking::processPlayerPacket(RakNet::Packet *packet)
myPacket->setPlayer(player); myPacket->setPlayer(player);
myPacket->Read(); 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()) if (player->isHandshaked())
{ {
LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Wrong handshake with player %d, name: %s", player->getId(), LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Wrong handshake with player %d, name: %s", player->getId(),

@ -16,6 +16,11 @@ PacketHandshake::PacketHandshake(RakNet::RakPeerInterface *peer) : PlayerPacket(
void PacketHandshake::Packet(RakNet::BitStream *bs, bool send) void PacketHandshake::Packet(RakNet::BitStream *bs, bool send)
{ {
PlayerPacket::Packet(bs, 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;
}
} }

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

Loading…
Cancel
Save