ulDNSHandlePacket() - check length before calculating payload size
@@ -916,7 +916,13 @@ 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 );
+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 ) )
{
@@ -928,6 +934,7 @@ size_t uxPayloadSize = pxNetworkBuffer->xDataLength - sizeof( UDPPacket_t );
uxPayloadSize,
pdFALSE );
}
+ }
/* The packet was not consumed. */
return pdFAIL;
