don't use heap allocated buffers in ssu

This commit is contained in:
Jeff Becker 2017-01-08 11:09:33 -05:00
parent d83fc3181b
commit 01ab027615
2 changed files with 20 additions and 30 deletions

View file

@ -154,8 +154,7 @@ namespace transport
{
uint32_t msgID = bufbe32toh (buf); // message ID
buf += 4;
uint8_t frag[4];
frag[0] = 0;
uint8_t frag[4] = {0};
memcpy (frag + 1, buf, 3);
buf += 3;
uint32_t fragmentInfo = bufbe32toh (frag); // fragment info
@ -371,7 +370,7 @@ namespace transport
void SSUData::SendMsgAck (uint32_t msgID)
{
uint8_t * buf = new uint8_t[48 + 18]; // actual length is 44 = 37 + 7 but pad it to multiple of 16
uint8_t buf[48 + 18] = {0}; // actual length is 44 = 37 + 7 but pad it to multiple of 16
uint8_t * payload = buf + sizeof (SSUHeader);
*payload = DATA_FLAG_EXPLICIT_ACKS_INCLUDED; // flag
payload++;
@ -384,7 +383,6 @@ namespace transport
// encrypt message with session key
m_Session.FillHeaderAndEncrypt (PAYLOAD_TYPE_DATA, buf, 48);
m_Session.Send (buf, 48);
delete [] buf;
}
void SSUData::SendFragmentAck (uint32_t msgID, int fragmentNum)
@ -394,7 +392,7 @@ namespace transport
LogPrint (eLogWarning, "SSU: Fragment number ", fragmentNum, " exceeds 64");
return;
}
uint8_t * buf = new uint8_t[64 + 18];
uint8_t buf[64 + 18] = {0};
uint8_t * payload = buf + sizeof (SSUHeader);
*payload = DATA_FLAG_ACK_BITFIELDS_INCLUDED; // flag
payload++;
@ -414,7 +412,6 @@ namespace transport
// encrypt message with session key
m_Session.FillHeaderAndEncrypt (PAYLOAD_TYPE_DATA, buf, len);
m_Session.Send (buf, len);
delete [] buf;
}
void SSUData::ScheduleResend()