|
47 | 47 |
|
48 | 48 | #if ( ipconfigUSE_DNS != 0 ) |
49 | 49 |
|
| 50 | + #if ( ( ipconfigUSE_DNS_CACHE != 0 ) || ( ipconfigDNS_USE_CALLBACKS != 0 ) || ( ipconfigUSE_MDNS != 0 ) || ( ipconfigUSE_LLMNR != 0 ) ) |
50 | 51 |
|
51 | 52 | /** |
52 | 53 | * @brief Read the Name field out of a DNS response packet. |
|
56 | 57 | * |
57 | 58 | * @return If a fully formed name was found, then return the number of bytes processed in pucByte. |
58 | 59 | */ |
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 ) |
72 | 62 | { |
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; |
76 | 67 |
|
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 ) |
87 | 73 | { |
| 74 | + /* Return 0 value in case of error. */ |
88 | 75 | uxIndex = 0U; |
89 | 76 | } |
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 ]; |
110 | 77 |
|
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 ) ) |
116 | 84 | { |
117 | | - uxIndex = 0U; |
118 | | - break; |
| 85 | + uxIndex += sizeof( uint16_t ); |
119 | 86 | } |
120 | | - |
121 | | - if( ( uxNameLen + uxCount ) >= uxDestLen ) |
| 87 | + else |
122 | 88 | { |
123 | 89 | 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++; |
136 | 90 | } |
137 | 91 | } |
138 | | - |
139 | | - /* Confirm that a fully formed name was found. */ |
140 | | - if( uxIndex > 0U ) |
| 92 | + else |
141 | 93 | { |
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 ) ) |
150 | 96 | { |
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. */ |
152 | 114 | 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 | + } |
153 | 138 | } |
154 | | - else |
| 139 | + |
| 140 | + /* Confirm that a fully formed name was found. */ |
| 141 | + if( uxIndex > 0U ) |
155 | 142 | { |
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 | + } |
157 | 159 | } |
158 | 160 | } |
159 | | - } |
160 | 161 |
|
161 | | - return uxIndex; |
162 | | - } |
| 162 | + return uxIndex; |
| 163 | + } |
| 164 | + #endif /* ipconfigUSE_DNS_CACHE || ipconfigDNS_USE_CALLBACKS || ipconfigUSE_MDNS || ipconfigUSE_LLMNR */ |
163 | 165 |
|
164 | 166 | /** |
165 | 167 | * @brief Simple routine that jumps over the NAME field of a resource record. |
|
285 | 287 | * for easier access. */ |
286 | 288 |
|
287 | 289 | /* 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 */ |
289 | 291 | /* coverity[misra_c_2012_rule_11_3_violation] */ |
290 | 292 | xSet.pxDNSMessageHeader = ( ( DNSMessage_t * ) |
291 | 293 | pucUDPPayloadBuffer ); |
|
355 | 357 | } |
356 | 358 | #endif |
357 | 359 |
|
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 ) ) |
359 | 361 | if( x == 0U ) |
360 | 362 | { |
361 | 363 | uxResult = DNS_ReadNameField( &xSet, |
362 | 364 | sizeof( xSet.pcName ) ); |
363 | 365 | ( void ) uxResult; |
364 | 366 | } |
365 | 367 | else |
366 | | - #endif /* ipconfigUSE_DNS_CACHE || ipconfigDNS_USE_CALLBACKS */ |
| 368 | + #endif /* ipconfigUSE_DNS_CACHE || ipconfigDNS_USE_CALLBACKS || ipconfigUSE_MDNS || ipconfigUSE_LLMNR */ |
367 | 369 | { |
368 | 370 | /* Skip the variable length pcName field. */ |
369 | 371 | uxResult = DNS_SkipNameField( xSet.pucByte, |
|
721 | 723 | * fields of the structure. */ |
722 | 724 |
|
723 | 725 | /* 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 */ |
725 | 727 | /* coverity[misra_c_2012_rule_11_3_violation] */ |
726 | 728 | pxDNSAnswerRecord = ( ( DNSAnswerRecord_t * ) pxSet->pucByte ); |
727 | 729 |
|
|
874 | 876 | /* Cast the response to DNSAnswerRecord for easy access to fields of the DNS response. */ |
875 | 877 |
|
876 | 878 | /* 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 */ |
878 | 880 | /* coverity[misra_c_2012_rule_11_3_violation] */ |
879 | 881 | pxDNSAnswerRecord = ( ( DNSAnswerRecord_t * ) pxSet->pucByte ); |
880 | 882 |
|
|
0 commit comments