Fix UB in NetworkPacket class

This commit is contained in:
sfan5 2023-09-22 21:30:16 +02:00
parent 5109fa7eda
commit d113636a43

@ -63,7 +63,8 @@ void NetworkPacket::putRawPacket(const u8 *data, u32 datasize, session_t peer_id
// split command and datas
m_command = readU16(&data[0]);
memcpy(m_data.data(), &data[2], m_datasize);
if (m_datasize > 0)
memcpy(m_data.data(), &data[2], m_datasize);
}
void NetworkPacket::clear()
@ -553,7 +554,8 @@ Buffer<u8> NetworkPacket::oldForgePacket()
{
Buffer<u8> sb(m_datasize + 2);
writeU16(&sb[0], m_command);
memcpy(&sb[2], m_data.data(), m_datasize);
if (m_datasize > 0)
memcpy(&sb[2], m_data.data(), m_datasize);
return sb;
}