Skip to content

Commit

Permalink
Fix for name resolution responses containing 0.0.0.0 (#1127)
Browse files Browse the repository at this point in the history
* Ignores name resolution responses that contain 0.0.0.0
Prevents sending name resolution responses with 0.0.0.0
---------

Co-authored-by: Emil Popov <epopov@cardinalkinetic.com>
Co-authored-by: Tony Josi <tonyjosi@amazon.com>
  • Loading branch information
3 people committed Apr 18, 2024
1 parent 1bc37d3 commit a53e71a
Show file tree
Hide file tree
Showing 2 changed files with 242 additions and 9 deletions.
34 changes: 32 additions & 2 deletions source/FreeRTOS_DNS_Parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,13 @@
xDNSHookReturn = xApplicationDNSQueryHook_Multi( &xEndPoint, xSet.pcName );
#endif

/* During the early stages of boot or after a DHCP lease expires, our end-point
* may have an IP address of 0.0.0.0. Do not respond to name queries with that address. */
if( ( xDNSHookReturn != pdFALSE ) && ( xEndPoint.bits.bIPv6 == pdFALSE ) && ( xEndPoint.ipv4_settings.ulIPAddress == 0U ) )
{
xDNSHookReturn = pdFALSE;
}

if( xDNSHookReturn != pdFALSE )
{
int16_t usLength;
Expand Down Expand Up @@ -655,7 +662,21 @@

if( pxSet->uxSourceBytesRemaining >= ( sizeof( DNSAnswerRecord_t ) + pxSet->uxAddressLength ) )
{
xDoAccept = pdTRUE;
/* Ignore responses containing an IP of 0.0.0.0.
* If we don't stop parsing this now, the code below will
* invoke the user callback and also store this invalid address in our cache. */
void * pvCopyDest;
const void * pvCopySource;
uint32_t ulTestAddress;

pvCopySource = &( pxSet->pucByte[ sizeof( DNSAnswerRecord_t ) ] );
pvCopyDest = &( ulTestAddress );
( void ) memcpy( pvCopyDest, pvCopySource, pxSet->uxAddressLength );

if( ulTestAddress != 0U )
{
xDoAccept = pdTRUE;
}
}
}
else
Expand Down Expand Up @@ -798,8 +819,10 @@
}
#endif /* ipconfigUSE_DNS_CACHE */

if( ( ulReturnIPAddress == 0U ) && ( pxSet->ulIPAddress != 0U ) )
if( ulReturnIPAddress == 0U )
{
/* Here pxSet->ulIPAddress should be not equal tp 0 since pxSet->ulIPAddress is copied from
* pxSet->pucByte[ sizeof( DNSAnswerRecord_t ) ] and os verified to be non zero above. */
/* Remember the first IP-address that is found. */
ulReturnIPAddress = pxSet->ulIPAddress;
}
Expand Down Expand Up @@ -1121,6 +1144,13 @@
break;
}

/* During the early stages of boot or after a DHCP lease expires, our end-point
* may have an IP address of 0.0.0.0. Do not respond to name queries with that address. */
if( xEndPoint.ipv4_settings.ulIPAddress == 0U )
{
break;
}

/* Someone is looking for a device with ucNBNSName,
* prepare a positive reply.
* The reply will be a bit longer than the request, so make some space.
Expand Down
Loading

0 comments on commit a53e71a

Please sign in to comment.