summaryrefslogtreecommitdiffstats
path: root/src/Protocol
diff options
context:
space:
mode:
authorHowaner <franzi.moos@googlemail.com>2014-09-25 19:22:46 +0200
committerHowaner <franzi.moos@googlemail.com>2014-09-25 19:22:46 +0200
commitdd423a2467f39550d7f54ef8e22a1089793ea7d4 (patch)
treea13a8d59404456a9c28b4c6d93f68851d03ffbcb /src/Protocol
parentFixed wrong Surrounding size (diff)
parentRedstone: Fixed a crash with repeaters on a chunk border. (diff)
downloadcuberite-dd423a2467f39550d7f54ef8e22a1089793ea7d4.tar
cuberite-dd423a2467f39550d7f54ef8e22a1089793ea7d4.tar.gz
cuberite-dd423a2467f39550d7f54ef8e22a1089793ea7d4.tar.bz2
cuberite-dd423a2467f39550d7f54ef8e22a1089793ea7d4.tar.lz
cuberite-dd423a2467f39550d7f54ef8e22a1089793ea7d4.tar.xz
cuberite-dd423a2467f39550d7f54ef8e22a1089793ea7d4.tar.zst
cuberite-dd423a2467f39550d7f54ef8e22a1089793ea7d4.zip
Diffstat (limited to 'src/Protocol')
-rw-r--r--src/Protocol/Protocol17x.cpp8
-rw-r--r--src/Protocol/Protocol18x.cpp13
2 files changed, 11 insertions, 10 deletions
diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp
index 67a4c47a7..73d2a74f9 100644
--- a/src/Protocol/Protocol17x.cpp
+++ b/src/Protocol/Protocol17x.cpp
@@ -1519,9 +1519,6 @@ void cProtocol172::AddReceivedData(const char * a_Data, size_t a_Size)
VERIFY(m_ReceivedData.ReadToByteBuffer(bb, (int)PacketLen));
m_ReceivedData.CommitRead();
- // Write one NUL extra, so that we can detect over-reads
- bb.Write("\0", 1);
-
UInt32 PacketType;
if (!bb.ReadVarInt(PacketType))
{
@@ -1529,6 +1526,9 @@ void cProtocol172::AddReceivedData(const char * a_Data, size_t a_Size)
break;
}
+ // Write one NUL extra, so that we can detect over-reads
+ bb.Write("\0", 1);
+
// Log the packet info into the comm log file:
if (g_ShouldLogCommIn)
{
@@ -1536,7 +1536,7 @@ void cProtocol172::AddReceivedData(const char * a_Data, size_t a_Size)
bb.ReadAll(PacketData);
bb.ResetRead();
bb.ReadVarInt(PacketType);
- ASSERT(PacketData.size() > 0);
+ 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;
CreateHexDump(PacketDataHex, PacketData.data(), PacketData.size(), 16);
diff --git a/src/Protocol/Protocol18x.cpp b/src/Protocol/Protocol18x.cpp
index a92ab5f54..33b6ca68e 100644
--- a/src/Protocol/Protocol18x.cpp
+++ b/src/Protocol/Protocol18x.cpp
@@ -1716,7 +1716,7 @@ void cProtocol180::AddReceivedData(const char * a_Data, size_t a_Size)
m_ReceivedData.ResetRead();
break;
}
- cByteBuffer bb(PacketLen);
+ cByteBuffer bb(PacketLen + 1);
VERIFY(m_ReceivedData.ReadToByteBuffer(bb, (int)PacketLen));
m_ReceivedData.CommitRead();
@@ -1731,9 +1731,6 @@ void cProtocol180::AddReceivedData(const char * a_Data, size_t a_Size)
}
}
- // Write one NUL extra, so that we can detect over-reads
- bb.Write("\0", 1);
-
UInt32 PacketType;
if (!bb.ReadVarInt(PacketType))
{
@@ -1741,6 +1738,9 @@ void cProtocol180::AddReceivedData(const char * a_Data, size_t a_Size)
break;
}
+ // Write one NUL extra, so that we can detect over-reads
+ bb.Write("\0", 1);
+
// Log the packet info into the comm log file:
if (g_ShouldLogCommIn)
{
@@ -1748,7 +1748,7 @@ void cProtocol180::AddReceivedData(const char * a_Data, size_t a_Size)
bb.ReadAll(PacketData);
bb.ResetRead();
bb.ReadVarInt(PacketType);
- ASSERT(PacketData.size() > 0);
+ 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;
CreateHexDump(PacketDataHex, PacketData.data(), PacketData.size(), 16);
@@ -1782,7 +1782,8 @@ void cProtocol180::AddReceivedData(const char * a_Data, size_t a_Size)
return;
}
- if (bb.GetReadableSpace() != 0)
+ // The packet should have 1 byte left in the buffer - the NUL we had added
+ if (bb.GetReadableSpace() != 1)
{
// Read more or less than packet length, report as error
LOGWARNING("Protocol 1.8: Wrong number of bytes read for packet 0x%x, state %d. Read " SIZE_T_FMT " bytes, packet contained %u bytes",