diff options
author | Loic Blot <loic.blot@unix-experience.fr> | 2017-10-10 00:47:37 +0200 |
---|---|---|
committer | Loic Blot <loic.blot@unix-experience.fr> | 2017-10-10 00:47:46 +0200 |
commit | 9d295906efc7eec58dba3f7494f4e444d2c8d00f (patch) | |
tree | 1d8f4df5dfb0df03271c3b06482f126abbba7aab /src | |
parent | 0c9ca27ffce7d53ede74bd6ccbf590d1cbe94b7b (diff) | |
download | minetest-9d295906efc7eec58dba3f7494f4e444d2c8d00f.tar.gz minetest-9d295906efc7eec58dba3f7494f4e444d2c8d00f.tar.bz2 minetest-9d295906efc7eec58dba3f7494f4e444d2c8d00f.zip |
NetworkPacket::putRawPacket: resize m_data to datasize + memcpy
In some cases NetworkPacket was created using default constructor and m_data is not properly sized.
This fixed out of bounds memory copy
Also use memcpy instead of std::vector affectation to enhance packet creation
Diffstat (limited to 'src')
-rw-r--r-- | src/network/networkpacket.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/network/networkpacket.cpp b/src/network/networkpacket.cpp index a35db9574..14b1ac440 100644 --- a/src/network/networkpacket.cpp +++ b/src/network/networkpacket.cpp @@ -59,9 +59,11 @@ void NetworkPacket::putRawPacket(u8 *data, u32 datasize, session_t peer_id) m_datasize = datasize - 2; m_peer_id = peer_id; + m_data.resize(m_datasize); + // split command and datas m_command = readU16(&data[0]); - m_data = std::vector<u8>(&data[2], &data[2 + m_datasize]); + memcpy(&m_data[0], &data[2], m_datasize); } const char* NetworkPacket::getString(u32 from_offset) |