From d4c3821eca6249399a2d690c3c8735526d1d5a4c Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 21 Dec 2014 20:01:42 +0100 Subject: Fixed coverity issues in protocols. Fixes CID 73099, CID 66411. --- src/Protocol/Protocol18x.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/Protocol/Protocol18x.cpp') diff --git a/src/Protocol/Protocol18x.cpp b/src/Protocol/Protocol18x.cpp index ce580d73e..1a13f4f7c 100644 --- a/src/Protocol/Protocol18x.cpp +++ b/src/Protocol/Protocol18x.cpp @@ -1723,7 +1723,11 @@ void cProtocol180::AddReceivedData(const char * a_Data, size_t a_Size) { // Decompress the data: AString CompressedData; - m_ReceivedData.ReadString(CompressedData, CompressedSize); + if (!m_ReceivedData.ReadString(CompressedData, CompressedSize)) + { + m_Client->Kick("Compression failure"); + return; + } InflateString(CompressedData.data(), CompressedSize, UncompressedData); PacketLen = UncompressedData.size(); } @@ -1765,7 +1769,7 @@ void cProtocol180::AddReceivedData(const char * a_Data, size_t a_Size) AString PacketData; bb.ReadAll(PacketData); bb.ResetRead(); - bb.ReadVarInt(PacketType); + bb.ReadVarInt(PacketType); // We have already read the packet type once, it will be there again ASSERT(PacketData.size() > 0); // We have written an extra NUL, so there had to be at least one byte read PacketData.resize(PacketData.size() - 1); AString PacketDataHex; -- cgit v1.2.3 From ccdf03daaf880dd0c89a03b50c11eb083ee1cfb0 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Wed, 24 Dec 2014 07:20:17 +0100 Subject: Refactored all player block placing to go through hooks. Fixes #1618. --- src/Protocol/Protocol18x.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Protocol/Protocol18x.cpp') diff --git a/src/Protocol/Protocol18x.cpp b/src/Protocol/Protocol18x.cpp index 1a13f4f7c..72827ac47 100644 --- a/src/Protocol/Protocol18x.cpp +++ b/src/Protocol/Protocol18x.cpp @@ -207,9 +207,9 @@ void cProtocol180::SendBlockChanges(int a_ChunkX, int a_ChunkZ, const sSetBlockV Pkt.WriteVarInt((UInt32)a_Changes.size()); for (sSetBlockVector::const_iterator itr = a_Changes.begin(), end = a_Changes.end(); itr != end; ++itr) { - short Coords = (short) (itr->y | (itr->z << 8) | (itr->x << 12)); + short Coords = (short) (itr->m_RelY | (itr->m_RelZ << 8) | (itr->m_RelX << 12)); Pkt.WriteShort(Coords); - Pkt.WriteVarInt((itr->BlockType & 0xFFF) << 4 | (itr->BlockMeta & 0xF)); + Pkt.WriteVarInt((itr->m_BlockType & 0xFFF) << 4 | (itr->m_BlockMeta & 0xF)); } // for itr - a_Changes[] } -- cgit v1.2.3 From 06c2669cf6b03feb15990004087e882ac846b061 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sat, 3 Jan 2015 22:23:49 +0100 Subject: Protocols: Ignore garbage data at the end of PluginMessage packets. Fixes #1692. --- src/Protocol/Protocol18x.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/Protocol/Protocol18x.cpp') diff --git a/src/Protocol/Protocol18x.cpp b/src/Protocol/Protocol18x.cpp index 72827ac47..21b098735 100644 --- a/src/Protocol/Protocol18x.cpp +++ b/src/Protocol/Protocol18x.cpp @@ -2331,6 +2331,16 @@ void cProtocol180::HandlePacketPluginMessage(cByteBuffer & a_ByteBuffer) if (Channel.substr(0, 3) == "MC|") { HandleVanillaPluginMessage(a_ByteBuffer, Channel); + + // Skip any unread data (vanilla sometimes sends garbage at the end of a packet; #1692): + if (a_ByteBuffer.GetReadableSpace() > 1) + { + LOGD("Protocol 1.8: Skipping garbage data at the end of a vanilla PluginMessage packet, %u bytes", + a_ByteBuffer.GetReadableSpace() - 1 + ); + a_ByteBuffer.SkipRead(a_ByteBuffer.GetReadableSpace() - 1); + } + return; } -- cgit v1.2.3 From 7d13a2a77a030a4f458ac01a51f8a4216a4a44b4 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sat, 3 Jan 2015 22:39:55 +0100 Subject: Fixed Linux compilation. --- src/Protocol/Protocol18x.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Protocol/Protocol18x.cpp') diff --git a/src/Protocol/Protocol18x.cpp b/src/Protocol/Protocol18x.cpp index 21b098735..3c4e049bd 100644 --- a/src/Protocol/Protocol18x.cpp +++ b/src/Protocol/Protocol18x.cpp @@ -2336,7 +2336,7 @@ void cProtocol180::HandlePacketPluginMessage(cByteBuffer & a_ByteBuffer) if (a_ByteBuffer.GetReadableSpace() > 1) { LOGD("Protocol 1.8: Skipping garbage data at the end of a vanilla PluginMessage packet, %u bytes", - a_ByteBuffer.GetReadableSpace() - 1 + static_cast(a_ByteBuffer.GetReadableSpace() - 1) ); a_ByteBuffer.SkipRead(a_ByteBuffer.GetReadableSpace() - 1); } -- cgit v1.2.3