diff options
author | rubenwardy <rw@rubenwardy.com> | 2019-03-06 22:24:39 +0000 |
---|---|---|
committer | rubenwardy <rw@rubenwardy.com> | 2019-03-11 22:07:19 +0000 |
commit | fc24bf09153f17bec023cde164a039202102a66c (patch) | |
tree | 69425602940e80b7eb1a8e0b6b35159072db6bff /src/network | |
parent | 9329b99cba735842f704f378679cbc000a4c8868 (diff) | |
download | minetest-fc24bf09153f17bec023cde164a039202102a66c.tar.gz minetest-fc24bf09153f17bec023cde164a039202102a66c.tar.bz2 minetest-fc24bf09153f17bec023cde164a039202102a66c.zip |
Fix incorrect string length check after cast
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/networkpacket.cpp | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/network/networkpacket.cpp b/src/network/networkpacket.cpp index 35a131a34..6d869e5eb 100644 --- a/src/network/networkpacket.cpp +++ b/src/network/networkpacket.cpp @@ -110,11 +110,12 @@ NetworkPacket& NetworkPacket::operator>>(std::string& dst) NetworkPacket& NetworkPacket::operator<<(const std::string &src) { - u16 msgsize = src.size(); - if (msgsize > STRING_MAX_LEN) { + if (src.size() > STRING_MAX_LEN) { throw PacketError("String too long"); } + u16 msgsize = src.size(); + *this << msgsize; putRawString(src.c_str(), (u32)msgsize); @@ -124,11 +125,12 @@ NetworkPacket& NetworkPacket::operator<<(const std::string &src) void NetworkPacket::putLongString(const std::string &src) { - u32 msgsize = src.size(); - if (msgsize > LONG_STRING_MAX_LEN) { + if (src.size() > LONG_STRING_MAX_LEN) { throw PacketError("String too long"); } + u32 msgsize = src.size(); + *this << msgsize; putRawString(src.c_str(), msgsize); @@ -160,11 +162,12 @@ NetworkPacket& NetworkPacket::operator>>(std::wstring& dst) NetworkPacket& NetworkPacket::operator<<(const std::wstring &src) { - u16 msgsize = src.size(); - if (msgsize > WIDE_STRING_MAX_LEN) { + if (src.size() > WIDE_STRING_MAX_LEN) { throw PacketError("String too long"); } + u16 msgsize = src.size(); + *this << msgsize; // Write string |