fix TcpPacket::readPacket

This commit is contained in:
sehraf 2016-06-28 17:37:22 +02:00
parent c15c979851
commit ea07a138bb

View File

@ -186,19 +186,26 @@ int TcpPacket::readPacket(void *buf, int size)
if (data)
{
free(data);
data = NULL ;
}
datasize = size - TCP_PSEUDO_HDR_SIZE;
if(datasize == 0) // this happens!
{
data = NULL ;
return 0 ;
}
// this happens for control packets (e.g. syn/ack/fin)
if(datasize == 0)
{
// data is already NULL
// just return packet size
return size;
}
data = (uint8 *) rs_malloc(datasize);
if(data == NULL)
{
// malloc failed!
// return 0 to drop packet (will be retransmitted eventually)
return 0 ;
}
/* now the data */
memcpy(data, (void *) &(((uint8 *) buf)[20]), datasize);