diff --git a/.github/.cSpellWords.txt b/.github/.cSpellWords.txt index 319b2239e..9431d40fb 100644 --- a/.github/.cSpellWords.txt +++ b/.github/.cSpellWords.txt @@ -89,6 +89,7 @@ BLXNS bmcr BMSR BPDG +BPIALL brgintclr brginten brgintstat diff --git a/source/FreeRTOS_DNS.c b/source/FreeRTOS_DNS.c index 4357f4443..4ef18c424 100644 --- a/source/FreeRTOS_DNS.c +++ b/source/FreeRTOS_DNS.c @@ -257,6 +257,9 @@ const MACAddress_t xMDNS_MacAddressIPv6 = { { 0x33, 0x33, 0x00, 0x00, 0x00, 0xFB /* 'xFamily' might not be used when IPv6 is disabled. */ ( void ) xFamily; + /* 'pcName' might not be used when DNS cache is disabled. */ + ( void ) pcName; + pvBuffer = pvPortMalloc( sizeof( *pxAddrInfo ) ); if( pvBuffer != NULL ) diff --git a/source/FreeRTOS_DNS_Parser.c b/source/FreeRTOS_DNS_Parser.c index 6aa3306f6..a1a3f2038 100644 --- a/source/FreeRTOS_DNS_Parser.c +++ b/source/FreeRTOS_DNS_Parser.c @@ -47,6 +47,7 @@ #if ( ipconfigUSE_DNS != 0 ) + #if ( ( ipconfigUSE_DNS_CACHE != 0 ) || ( ipconfigDNS_USE_CALLBACKS != 0 ) || ( ipconfigUSE_MDNS != 0 ) || ( ipconfigUSE_LLMNR != 0 ) ) /** * @brief Read the Name field out of a DNS response packet. @@ -56,110 +57,111 @@ * * @return If a fully formed name was found, then return the number of bytes processed in pucByte. */ - size_t DNS_ReadNameField( ParseSet_t * pxSet, - size_t uxDestLen ) - { - size_t uxNameLen = 0U; - size_t uxIndex = 0U; - size_t uxSourceLen = pxSet->uxSourceBytesRemaining; - const uint8_t * pucByte = pxSet->pucByte; - - /* uxCount gets the values from pucByte and counts down to 0. - * No need to have a different type than that of pucByte */ - size_t uxCount; - - if( uxSourceLen == ( size_t ) 0U ) + size_t DNS_ReadNameField( ParseSet_t * pxSet, + size_t uxDestLen ) { - /* Return 0 value in case of error. */ - uxIndex = 0U; - } + size_t uxNameLen = 0U; + size_t uxIndex = 0U; + size_t uxSourceLen = pxSet->uxSourceBytesRemaining; + const uint8_t * pucByte = pxSet->pucByte; - /* Determine if the name is the fully coded name, or an offset to the name - * elsewhere in the message. */ - else if( ( pucByte[ uxIndex ] & dnsNAME_IS_OFFSET ) == dnsNAME_IS_OFFSET ) - { - /* Jump over the two byte offset. */ - if( uxSourceLen > sizeof( uint16_t ) ) - { - uxIndex += sizeof( uint16_t ); - } - else + /* uxCount gets the values from pucByte and counts down to 0. + * No need to have a different type than that of pucByte */ + size_t uxCount; + + if( uxSourceLen == ( size_t ) 0U ) { + /* Return 0 value in case of error. */ uxIndex = 0U; } - } - else - { - /* 'uxIndex' points to the full name. Walk over the string. */ - while( ( uxIndex < uxSourceLen ) && ( pucByte[ uxIndex ] != ( uint8_t ) 0x00U ) ) - { - /* If this is not the first time through the loop, then add a - * separator in the output. */ - if( ( uxNameLen > 0U ) ) - { - /* - * uxNameLen can never be greater than uxDestLen, since there are checks - * outside this condition, so the check is removed. - */ - pxSet->pcName[ uxNameLen ] = '.'; - uxNameLen++; - } - - /* Process the first/next sub-string. */ - uxCount = ( size_t ) pucByte[ uxIndex ]; - /* uxIndex should point to the first character now, unless uxCount - * is an offset field. */ - uxIndex++; - - if( ( uxIndex + uxCount ) > uxSourceLen ) + /* Determine if the name is the fully coded name, or an offset to the name + * elsewhere in the message. */ + else if( ( pucByte[ uxIndex ] & dnsNAME_IS_OFFSET ) == dnsNAME_IS_OFFSET ) + { + /* Jump over the two byte offset. */ + if( uxSourceLen > sizeof( uint16_t ) ) { - uxIndex = 0U; - break; + uxIndex += sizeof( uint16_t ); } - - if( ( uxNameLen + uxCount ) >= uxDestLen ) + else { uxIndex = 0U; - break; - } - - while( uxCount-- != 0U ) - { - /* - * uxNameLen can never be greater than uxDestLen, since there are checks - * outside this condition, so the check is removed. - */ - pxSet->pcName[ uxNameLen ] = ( char ) pucByte[ uxIndex ]; - uxNameLen++; - uxIndex++; } } - - /* Confirm that a fully formed name was found. */ - if( uxIndex > 0U ) + else { - /* Here, there is no need to check for pucByte[ uxindex ] == 0 because: - * When we break out of the above while loop, uxIndex is made 0 thereby - * failing above check. Whenever we exit the loop otherwise, either - * pucByte[ uxIndex ] == 0 (which makes the check here unnecessary) or - * uxIndex >= uxSourceLen (which makes sure that we do not go in the 'if' - * case). - */ - if( uxIndex < uxSourceLen ) + /* 'uxIndex' points to the full name. Walk over the string. */ + while( ( uxIndex < uxSourceLen ) && ( pucByte[ uxIndex ] != ( uint8_t ) 0x00U ) ) { - pxSet->pcName[ uxNameLen ] = '\0'; + /* If this is not the first time through the loop, then add a + * separator in the output. */ + if( ( uxNameLen > 0U ) ) + { + /* + * uxNameLen can never be greater than uxDestLen, since there are checks + * outside this condition, so the check is removed. + */ + pxSet->pcName[ uxNameLen ] = '.'; + uxNameLen++; + } + + /* Process the first/next sub-string. */ + uxCount = ( size_t ) pucByte[ uxIndex ]; + + /* uxIndex should point to the first character now, unless uxCount + * is an offset field. */ uxIndex++; + + if( ( uxIndex + uxCount ) > uxSourceLen ) + { + uxIndex = 0U; + break; + } + + if( ( uxNameLen + uxCount ) >= uxDestLen ) + { + uxIndex = 0U; + break; + } + + while( uxCount-- != 0U ) + { + /* + * uxNameLen can never be greater than uxDestLen, since there are checks + * outside this condition, so the check is removed. + */ + pxSet->pcName[ uxNameLen ] = ( char ) pucByte[ uxIndex ]; + uxNameLen++; + uxIndex++; + } } - else + + /* Confirm that a fully formed name was found. */ + if( uxIndex > 0U ) { - uxIndex = 0U; + /* Here, there is no need to check for pucByte[ uxindex ] == 0 because: + * When we break out of the above while loop, uxIndex is made 0 thereby + * failing above check. Whenever we exit the loop otherwise, either + * pucByte[ uxIndex ] == 0 (which makes the check here unnecessary) or + * uxIndex >= uxSourceLen (which makes sure that we do not go in the 'if' + * case). + */ + if( uxIndex < uxSourceLen ) + { + pxSet->pcName[ uxNameLen ] = '\0'; + uxIndex++; + } + else + { + uxIndex = 0U; + } } } - } - return uxIndex; - } + return uxIndex; + } + #endif /* ipconfigUSE_DNS_CACHE || ipconfigDNS_USE_CALLBACKS || ipconfigUSE_MDNS || ipconfigUSE_LLMNR */ /** * @brief Simple routine that jumps over the NAME field of a resource record. @@ -285,7 +287,7 @@ * for easier access. */ /* MISRA Ref 11.3.1 [Misaligned access] */ -/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ + /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ /* coverity[misra_c_2012_rule_11_3_violation] */ xSet.pxDNSMessageHeader = ( ( DNSMessage_t * ) pucUDPPayloadBuffer ); @@ -355,7 +357,7 @@ } #endif - #if ( ipconfigUSE_DNS_CACHE == 1 ) || ( ipconfigDNS_USE_CALLBACKS == 1 ) + #if ( ( ipconfigUSE_DNS_CACHE != 0 ) || ( ipconfigDNS_USE_CALLBACKS != 0 ) || ( ipconfigUSE_MDNS != 0 ) || ( ipconfigUSE_LLMNR != 0 ) ) if( x == 0U ) { uxResult = DNS_ReadNameField( &xSet, @@ -363,7 +365,7 @@ ( void ) uxResult; } else - #endif /* ipconfigUSE_DNS_CACHE || ipconfigDNS_USE_CALLBACKS */ + #endif /* ipconfigUSE_DNS_CACHE || ipconfigDNS_USE_CALLBACKS || ipconfigUSE_MDNS || ipconfigUSE_LLMNR */ { /* Skip the variable length pcName field. */ uxResult = DNS_SkipNameField( xSet.pucByte, @@ -721,7 +723,7 @@ * fields of the structure. */ /* MISRA Ref 11.3.1 [Misaligned access] */ -/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ + /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxDNSAnswerRecord = ( ( DNSAnswerRecord_t * ) pxSet->pucByte ); @@ -874,7 +876,7 @@ /* Cast the response to DNSAnswerRecord for easy access to fields of the DNS response. */ /* MISRA Ref 11.3.1 [Misaligned access] */ -/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ + /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ /* coverity[misra_c_2012_rule_11_3_violation] */ pxDNSAnswerRecord = ( ( DNSAnswerRecord_t * ) pxSet->pucByte ); diff --git a/source/include/FreeRTOS_DNS_Globals.h b/source/include/FreeRTOS_DNS_Globals.h index b523badbb..0de266e6c 100644 --- a/source/include/FreeRTOS_DNS_Globals.h +++ b/source/include/FreeRTOS_DNS_Globals.h @@ -189,7 +189,8 @@ uint16_t usClass; /**< Only the value 'dnsCLASS_IN' is recognised, which stands for "Internet". */ char * pcRequestedName; /**< A pointer to the full name of the host being looked up. */ #endif - #if ( ipconfigUSE_DNS_CACHE == 1 ) || ( ipconfigDNS_USE_CALLBACKS == 1 ) || ( ipconfigUSE_MDNS == 1 ) + + #if ( ( ipconfigUSE_DNS_CACHE != 0 ) || ( ipconfigDNS_USE_CALLBACKS != 0 ) || ( ipconfigUSE_MDNS != 0 ) || ( ipconfigUSE_LLMNR != 0 ) ) BaseType_t xDoStore; /**< Becomes true when a DNS reply was requested by this device, * i.e. it has a matching request ID. */ char pcName[ ipconfigDNS_CACHE_NAME_LENGTH ]; /**< A copy of the name that is mentioned in the questions. */