mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
fix TcpPacket::readPacket
This commit is contained in:
parent
c15c979851
commit
ea07a138bb
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user