mirror of
https://github.com/smartcmd/MinecraftConsoles.git
synced 2026-08-20 09:57:09 +00:00
feat: implement bad chat packet handling
This commit is contained in:
parent
0a8b0cb406
commit
d31479a0ab
|
|
@ -2921,7 +2921,16 @@ void ClientConnection::handleContainerOpen(shared_ptr<ContainerOpenPacket> packe
|
|||
case ContainerOpenPacket::LARGE_CHEST: chestString = IDS_CHEST_LARGE; break;
|
||||
case ContainerOpenPacket::ENDER_CHEST: chestString = IDS_TILE_ENDERCHEST; break;
|
||||
case ContainerOpenPacket::CONTAINER: chestString = IDS_CHEST; break;
|
||||
default: assert(false); chestString = -1; break;
|
||||
default:
|
||||
throw IOException(L"ClientConnection::handleContainerOpen - invalid container type");
|
||||
}
|
||||
|
||||
|
||||
|
||||
// izzint - surprised how little checks are here
|
||||
const int MAX_CONTAINER_SIZE = 54; // double chest should be max, right?
|
||||
if (packet->size < 0 || packet->size > MAX_CONTAINER_SIZE) {
|
||||
throw IOException(L"ClientConnection::handleContainerOpen - invalid container size");
|
||||
}
|
||||
|
||||
if( player->openContainer(shared_ptr<SimpleContainer>( new SimpleContainer(chestString, packet->title, packet->customName, packet->size) )))
|
||||
|
|
|
|||
|
|
@ -43,12 +43,25 @@ ChatPacket::ChatPacket(const wstring& message, EChatPacketMessage type, int sour
|
|||
// Read chat packet (throws IOException)
|
||||
void ChatPacket::read(DataInputStream *dis)
|
||||
{
|
||||
m_messageType = (EChatPacketMessage) dis->readShort();
|
||||
// izzint - TODO: i could see this validation being hardcoded becoming
|
||||
// a problem for people who want to expand on chat types, plz review!
|
||||
short msgType = dis->readShort();
|
||||
if (msgType < e_ChatCustom || msgType > e_ChatCommandTeleportToMe)
|
||||
{
|
||||
throw IOException(L"ChatPacket::read - invalid chat type");
|
||||
}
|
||||
m_messageType = static_cast<EChatPacketMessage>(msgType);
|
||||
|
||||
short packedCounts = dis->readShort();
|
||||
int stringCount = (packedCounts >> 4) & 0xF;
|
||||
int intCount = (packedCounts >> 0) & 0xF;
|
||||
|
||||
// izzint - again, why didn't 4j patch this out??
|
||||
if (stringCount > 15 || intCount > MAX_LENGTH)
|
||||
{
|
||||
throw IOException(L"ChatPacket::read - too many string arguments");
|
||||
}
|
||||
|
||||
for(int i = 0; i < stringCount; i++)
|
||||
{
|
||||
m_stringArgs.push_back(readUtf(dis, MAX_LENGTH));
|
||||
|
|
|
|||
Loading…
Reference in a new issue