Skip to content

Commit 9d29590

Browse files
committedOct 9, 2017
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
1 parent 0c9ca27 commit 9d29590

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed
 

‎src/network/networkpacket.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ void NetworkPacket::putRawPacket(u8 *data, u32 datasize, session_t peer_id)
5959
m_datasize = datasize - 2;
6060
m_peer_id = peer_id;
6161

62+
m_data.resize(m_datasize);
63+
6264
// split command and datas
6365
m_command = readU16(&data[0]);
64-
m_data = std::vector<u8>(&data[2], &data[2 + m_datasize]);
66+
memcpy(&m_data[0], &data[2], m_datasize);
6567
}
6668

6769
const char* NetworkPacket::getString(u32 from_offset)

0 commit comments

Comments
 (0)
Please sign in to comment.