Skip to content

Commit cecf06e

Browse files
authored
Merge branch 'main' into dev-ip-build-sep
2 parents b6cccc3 + 4f67761 commit cecf06e

File tree

4 files changed

+97
-90
lines changed

4 files changed

+97
-90
lines changed

.github/.cSpellWords.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ BLXNS
8989
bmcr
9090
BMSR
9191
BPDG
92+
BPIALL
9293
brgintclr
9394
brginten
9495
brgintstat

source/FreeRTOS_DNS.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,9 @@ const MACAddress_t xMDNS_MacAddressIPv6 = { { 0x33, 0x33, 0x00, 0x00, 0x00, 0xFB
257257

258258
/* 'xFamily' might not be used when IPv6 is disabled. */
259259
( void ) xFamily;
260+
/* 'pcName' might not be used when DNS cache is disabled. */
261+
( void ) pcName;
262+
260263
pvBuffer = pvPortMalloc( sizeof( *pxAddrInfo ) );
261264

262265
if( pvBuffer != NULL )

source/FreeRTOS_DNS_Parser.c

Lines changed: 91 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747

4848
#if ( ipconfigUSE_DNS != 0 )
4949

50+
#if ( ( ipconfigUSE_DNS_CACHE != 0 ) || ( ipconfigDNS_USE_CALLBACKS != 0 ) || ( ipconfigUSE_MDNS != 0 ) || ( ipconfigUSE_LLMNR != 0 ) )
5051

5152
/**
5253
* @brief Read the Name field out of a DNS response packet.
@@ -56,110 +57,111 @@
5657
*
5758
* @return If a fully formed name was found, then return the number of bytes processed in pucByte.
5859
*/
59-
size_t DNS_ReadNameField( ParseSet_t * pxSet,
60-
size_t uxDestLen )
61-
{
62-
size_t uxNameLen = 0U;
63-
size_t uxIndex = 0U;
64-
size_t uxSourceLen = pxSet->uxSourceBytesRemaining;
65-
const uint8_t * pucByte = pxSet->pucByte;
66-
67-
/* uxCount gets the values from pucByte and counts down to 0.
68-
* No need to have a different type than that of pucByte */
69-
size_t uxCount;
70-
71-
if( uxSourceLen == ( size_t ) 0U )
60+
size_t DNS_ReadNameField( ParseSet_t * pxSet,
61+
size_t uxDestLen )
7262
{
73-
/* Return 0 value in case of error. */
74-
uxIndex = 0U;
75-
}
63+
size_t uxNameLen = 0U;
64+
size_t uxIndex = 0U;
65+
size_t uxSourceLen = pxSet->uxSourceBytesRemaining;
66+
const uint8_t * pucByte = pxSet->pucByte;
7667

77-
/* Determine if the name is the fully coded name, or an offset to the name
78-
* elsewhere in the message. */
79-
else if( ( pucByte[ uxIndex ] & dnsNAME_IS_OFFSET ) == dnsNAME_IS_OFFSET )
80-
{
81-
/* Jump over the two byte offset. */
82-
if( uxSourceLen > sizeof( uint16_t ) )
83-
{
84-
uxIndex += sizeof( uint16_t );
85-
}
86-
else
68+
/* uxCount gets the values from pucByte and counts down to 0.
69+
* No need to have a different type than that of pucByte */
70+
size_t uxCount;
71+
72+
if( uxSourceLen == ( size_t ) 0U )
8773
{
74+
/* Return 0 value in case of error. */
8875
uxIndex = 0U;
8976
}
90-
}
91-
else
92-
{
93-
/* 'uxIndex' points to the full name. Walk over the string. */
94-
while( ( uxIndex < uxSourceLen ) && ( pucByte[ uxIndex ] != ( uint8_t ) 0x00U ) )
95-
{
96-
/* If this is not the first time through the loop, then add a
97-
* separator in the output. */
98-
if( ( uxNameLen > 0U ) )
99-
{
100-
/*
101-
* uxNameLen can never be greater than uxDestLen, since there are checks
102-
* outside this condition, so the check is removed.
103-
*/
104-
pxSet->pcName[ uxNameLen ] = '.';
105-
uxNameLen++;
106-
}
107-
108-
/* Process the first/next sub-string. */
109-
uxCount = ( size_t ) pucByte[ uxIndex ];
11077

111-
/* uxIndex should point to the first character now, unless uxCount
112-
* is an offset field. */
113-
uxIndex++;
114-
115-
if( ( uxIndex + uxCount ) > uxSourceLen )
78+
/* Determine if the name is the fully coded name, or an offset to the name
79+
* elsewhere in the message. */
80+
else if( ( pucByte[ uxIndex ] & dnsNAME_IS_OFFSET ) == dnsNAME_IS_OFFSET )
81+
{
82+
/* Jump over the two byte offset. */
83+
if( uxSourceLen > sizeof( uint16_t ) )
11684
{
117-
uxIndex = 0U;
118-
break;
85+
uxIndex += sizeof( uint16_t );
11986
}
120-
121-
if( ( uxNameLen + uxCount ) >= uxDestLen )
87+
else
12288
{
12389
uxIndex = 0U;
124-
break;
125-
}
126-
127-
while( uxCount-- != 0U )
128-
{
129-
/*
130-
* uxNameLen can never be greater than uxDestLen, since there are checks
131-
* outside this condition, so the check is removed.
132-
*/
133-
pxSet->pcName[ uxNameLen ] = ( char ) pucByte[ uxIndex ];
134-
uxNameLen++;
135-
uxIndex++;
13690
}
13791
}
138-
139-
/* Confirm that a fully formed name was found. */
140-
if( uxIndex > 0U )
92+
else
14193
{
142-
/* Here, there is no need to check for pucByte[ uxindex ] == 0 because:
143-
* When we break out of the above while loop, uxIndex is made 0 thereby
144-
* failing above check. Whenever we exit the loop otherwise, either
145-
* pucByte[ uxIndex ] == 0 (which makes the check here unnecessary) or
146-
* uxIndex >= uxSourceLen (which makes sure that we do not go in the 'if'
147-
* case).
148-
*/
149-
if( uxIndex < uxSourceLen )
94+
/* 'uxIndex' points to the full name. Walk over the string. */
95+
while( ( uxIndex < uxSourceLen ) && ( pucByte[ uxIndex ] != ( uint8_t ) 0x00U ) )
15096
{
151-
pxSet->pcName[ uxNameLen ] = '\0';
97+
/* If this is not the first time through the loop, then add a
98+
* separator in the output. */
99+
if( ( uxNameLen > 0U ) )
100+
{
101+
/*
102+
* uxNameLen can never be greater than uxDestLen, since there are checks
103+
* outside this condition, so the check is removed.
104+
*/
105+
pxSet->pcName[ uxNameLen ] = '.';
106+
uxNameLen++;
107+
}
108+
109+
/* Process the first/next sub-string. */
110+
uxCount = ( size_t ) pucByte[ uxIndex ];
111+
112+
/* uxIndex should point to the first character now, unless uxCount
113+
* is an offset field. */
152114
uxIndex++;
115+
116+
if( ( uxIndex + uxCount ) > uxSourceLen )
117+
{
118+
uxIndex = 0U;
119+
break;
120+
}
121+
122+
if( ( uxNameLen + uxCount ) >= uxDestLen )
123+
{
124+
uxIndex = 0U;
125+
break;
126+
}
127+
128+
while( uxCount-- != 0U )
129+
{
130+
/*
131+
* uxNameLen can never be greater than uxDestLen, since there are checks
132+
* outside this condition, so the check is removed.
133+
*/
134+
pxSet->pcName[ uxNameLen ] = ( char ) pucByte[ uxIndex ];
135+
uxNameLen++;
136+
uxIndex++;
137+
}
153138
}
154-
else
139+
140+
/* Confirm that a fully formed name was found. */
141+
if( uxIndex > 0U )
155142
{
156-
uxIndex = 0U;
143+
/* Here, there is no need to check for pucByte[ uxindex ] == 0 because:
144+
* When we break out of the above while loop, uxIndex is made 0 thereby
145+
* failing above check. Whenever we exit the loop otherwise, either
146+
* pucByte[ uxIndex ] == 0 (which makes the check here unnecessary) or
147+
* uxIndex >= uxSourceLen (which makes sure that we do not go in the 'if'
148+
* case).
149+
*/
150+
if( uxIndex < uxSourceLen )
151+
{
152+
pxSet->pcName[ uxNameLen ] = '\0';
153+
uxIndex++;
154+
}
155+
else
156+
{
157+
uxIndex = 0U;
158+
}
157159
}
158160
}
159-
}
160161

161-
return uxIndex;
162-
}
162+
return uxIndex;
163+
}
164+
#endif /* ipconfigUSE_DNS_CACHE || ipconfigDNS_USE_CALLBACKS || ipconfigUSE_MDNS || ipconfigUSE_LLMNR */
163165

164166
/**
165167
* @brief Simple routine that jumps over the NAME field of a resource record.
@@ -285,7 +287,7 @@
285287
* for easier access. */
286288

287289
/* MISRA Ref 11.3.1 [Misaligned access] */
288-
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
290+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
289291
/* coverity[misra_c_2012_rule_11_3_violation] */
290292
xSet.pxDNSMessageHeader = ( ( DNSMessage_t * )
291293
pucUDPPayloadBuffer );
@@ -355,15 +357,15 @@
355357
}
356358
#endif
357359

358-
#if ( ipconfigUSE_DNS_CACHE == 1 ) || ( ipconfigDNS_USE_CALLBACKS == 1 )
360+
#if ( ( ipconfigUSE_DNS_CACHE != 0 ) || ( ipconfigDNS_USE_CALLBACKS != 0 ) || ( ipconfigUSE_MDNS != 0 ) || ( ipconfigUSE_LLMNR != 0 ) )
359361
if( x == 0U )
360362
{
361363
uxResult = DNS_ReadNameField( &xSet,
362364
sizeof( xSet.pcName ) );
363365
( void ) uxResult;
364366
}
365367
else
366-
#endif /* ipconfigUSE_DNS_CACHE || ipconfigDNS_USE_CALLBACKS */
368+
#endif /* ipconfigUSE_DNS_CACHE || ipconfigDNS_USE_CALLBACKS || ipconfigUSE_MDNS || ipconfigUSE_LLMNR */
367369
{
368370
/* Skip the variable length pcName field. */
369371
uxResult = DNS_SkipNameField( xSet.pucByte,
@@ -721,7 +723,7 @@
721723
* fields of the structure. */
722724

723725
/* MISRA Ref 11.3.1 [Misaligned access] */
724-
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
726+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
725727
/* coverity[misra_c_2012_rule_11_3_violation] */
726728
pxDNSAnswerRecord = ( ( DNSAnswerRecord_t * ) pxSet->pucByte );
727729

@@ -874,7 +876,7 @@
874876
/* Cast the response to DNSAnswerRecord for easy access to fields of the DNS response. */
875877

876878
/* MISRA Ref 11.3.1 [Misaligned access] */
877-
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
879+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
878880
/* coverity[misra_c_2012_rule_11_3_violation] */
879881
pxDNSAnswerRecord = ( ( DNSAnswerRecord_t * ) pxSet->pucByte );
880882

source/include/FreeRTOS_DNS_Globals.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@
189189
uint16_t usClass; /**< Only the value 'dnsCLASS_IN' is recognised, which stands for "Internet". */
190190
char * pcRequestedName; /**< A pointer to the full name of the host being looked up. */
191191
#endif
192-
#if ( ipconfigUSE_DNS_CACHE == 1 ) || ( ipconfigDNS_USE_CALLBACKS == 1 ) || ( ipconfigUSE_MDNS == 1 )
192+
193+
#if ( ( ipconfigUSE_DNS_CACHE != 0 ) || ( ipconfigDNS_USE_CALLBACKS != 0 ) || ( ipconfigUSE_MDNS != 0 ) || ( ipconfigUSE_LLMNR != 0 ) )
193194
BaseType_t xDoStore; /**< Becomes true when a DNS reply was requested by this device,
194195
* i.e. it has a matching request ID. */
195196
char pcName[ ipconfigDNS_CACHE_NAME_LENGTH ]; /**< A copy of the name that is mentioned in the questions. */

0 commit comments

Comments
 (0)