Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Commit

Permalink
ulDNSHandlePacket() - check length before calculating payload size (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
gkwicker authored Dec 13, 2019
1 parent f5e0e07 commit d82b44f
Showing 1 changed file with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -916,18 +916,25 @@ for testing purposes, by the module iot_test_freertos_tcp.c
uint32_t ulDNSHandlePacket( NetworkBufferDescriptor_t *pxNetworkBuffer )
{
DNSMessage_t *pxDNSMessageHeader;
size_t uxPayloadSize = pxNetworkBuffer->xDataLength - sizeof( UDPPacket_t );

if( uxPayloadSize >= sizeof( DNSMessage_t ) )
{
pxDNSMessageHeader =
( DNSMessage_t * ) ( pxNetworkBuffer->pucEthernetBuffer + sizeof( UDPPacket_t ) );

/* The parameter pdFALSE indicates that the reply was not expected. */
prvParseDNSReply( ( uint8_t * ) pxDNSMessageHeader,
uxPayloadSize,
pdFALSE );
}
size_t uxPayloadSize;

/* Only proceed if the payload length indicated in the header
appears to be valid. */
if( pxNetworkBuffer->xDataLength >= sizeof( UDPPacket_t ) )
{
uxPayloadSize = pxNetworkBuffer->xDataLength - sizeof( UDPPacket_t );

if( uxPayloadSize >= sizeof( DNSMessage_t ) )
{
pxDNSMessageHeader =
( DNSMessage_t * ) ( pxNetworkBuffer->pucEthernetBuffer + sizeof( UDPPacket_t ) );

/* The parameter pdFALSE indicates that the reply was not expected. */
prvParseDNSReply( ( uint8_t * ) pxDNSMessageHeader,
uxPayloadSize,
pdFALSE );
}
}

/* The packet was not consumed. */
return pdFAIL;
Expand Down

0 comments on commit d82b44f

Please sign in to comment.