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

ulDNSHandlePacket() - check length before calculating payload size #1615

Merged
merged 1 commit into from
Dec 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call me crazy, but why have a return value if it can never be anything other than pdFAIL?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though this handler never consumes the buffer, the IP stack expects handling code to return a status value indicating whether or not the buffer was consumed.

Expand Down