Skip to content

Commit

Permalink
NetworkPacket::putRawPacket: resize m_data to datasize + memcpy
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nerzhul committed Oct 9, 2017
1 parent 0c9ca27 commit 9d29590
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/network/networkpacket.cpp
Expand Up @@ -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)
Expand Down

0 comments on commit 9d29590

Please sign in to comment.