Merge pull request #428 from sehraf/pr-fix-udp

fix TcpPacket::readPacket
This commit is contained in:
Cyril Soler 2016-06-28 12:37:04 -04:00 committed by GitHub
commit 019ed127bd

View File

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