|
153 | 153 | MACAddress_t * const pxMACAddress, |
154 | 154 | NetworkEndPoint_t ** ppxEndPoint ) |
155 | 155 | { |
156 | | - eResolutionLookupResult_t eReturn; |
| 156 | + eResolutionLookupResult_t eReturn = eResolutionCacheMiss; |
157 | 157 |
|
158 | 158 | /* Mostly used multi-cast address is ff02::. */ |
159 | 159 | if( xIsIPv6AllowedMulticast( pxAddressToLookup ) != pdFALSE ) |
|
163 | 163 | if( ppxEndPoint != NULL ) |
164 | 164 | { |
165 | 165 | *ppxEndPoint = pxFindLocalEndpoint(); |
166 | | - } |
167 | 166 |
|
168 | | - eReturn = eResolutionCacheHit; |
| 167 | + if (*ppxEndPoint != NULL) |
| 168 | + { |
| 169 | + eReturn = eResolutionCacheHit; |
| 170 | + } |
| 171 | + else |
| 172 | + { |
| 173 | + /* No link-local endpoint configured, eResolutionCacheMiss */ |
| 174 | + } |
| 175 | + } |
169 | 176 | } |
170 | 177 | else |
171 | 178 | { |
172 | | - /* Not a multicast IP address. */ |
173 | | - eReturn = eResolutionCacheMiss; |
| 179 | + /* Not a multicast IP address, eResolutionCacheMiss */ |
174 | 180 | } |
175 | 181 |
|
176 | 182 | return eReturn; |
|
977 | 983 | * @return A const value 'eReleaseBuffer' which means that the network must still be released. |
978 | 984 | */ |
979 | 985 | eFrameProcessingResult_t prvProcessICMPMessage_IPv6( NetworkBufferDescriptor_t * const pxNetworkBuffer ) |
| 986 | + { |
| 987 | + /* |
| 988 | + ICMPv6 messages have the following general format: |
| 989 | +
|
| 990 | + 0 1 2 3 |
| 991 | + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |
| 992 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 993 | + | Type | Code | Checksum | |
| 994 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 995 | + | | |
| 996 | + + Message Body + |
| 997 | + | | |
| 998 | +
|
| 999 | + The packet should contain atleast 4 bytes of general fields |
| 1000 | +
|
| 1001 | + */ |
| 1002 | + if( pxNetworkBuffer->xDataLength >= ( size_t ) ( ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER + ipICMPv6_GENERAL_FIELD_SIZE ) ) |
980 | 1003 | { |
981 | 1004 | /* MISRA Ref 11.3.1 [Misaligned access] */ |
982 | 1005 | /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ |
|
1052 | 1075 |
|
1053 | 1076 | /* Find the total length of the IP packet. */ |
1054 | 1077 | uxDataLength = ipNUMERIC_CAST( size_t, FreeRTOS_ntohs( pxICMPPacket->xIPHeader.usPayloadLength ) ); |
| 1078 | + |
| 1079 | + uxNeededSize = ( size_t ) ( ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER + uxDataLength ); |
| 1080 | + if( uxNeededSize > pxNetworkBuffer->xDataLength ) |
| 1081 | + { |
| 1082 | + FreeRTOS_printf( ( "Too small\n" ) ); |
| 1083 | + break; |
| 1084 | + } |
| 1085 | + |
1055 | 1086 | uxDataLength = uxDataLength - sizeof( *pxICMPEchoHeader ); |
1056 | 1087 |
|
1057 | 1088 | /* Find the first byte of the data within the ICMP packet. */ |
|
1128 | 1159 | break; |
1129 | 1160 |
|
1130 | 1161 | case ipICMP_NEIGHBOR_ADVERTISEMENT_IPv6: |
| 1162 | + { |
| 1163 | + size_t uxICMPSize; |
| 1164 | + uxICMPSize = sizeof( ICMPHeader_IPv6_t ); |
| 1165 | + uxNeededSize = ( size_t ) ( ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER + uxICMPSize ); |
| 1166 | + |
| 1167 | + if( uxNeededSize > pxNetworkBuffer->xDataLength ) |
| 1168 | + { |
| 1169 | + FreeRTOS_printf( ( "Too small\n" ) ); |
| 1170 | + break; |
| 1171 | + } |
| 1172 | + |
1131 | 1173 | /* MISRA Ref 11.3.1 [Misaligned access] */ |
1132 | 1174 | /* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */ |
1133 | 1175 | /* coverity[misra_c_2012_rule_11_3_violation] */ |
|
1149 | 1191 | { |
1150 | 1192 | prvCheckWaitingBuffer( &( pxICMPHeader_IPv6->xIPv6Address ) ); |
1151 | 1193 | } |
1152 | | - |
| 1194 | + } |
1153 | 1195 | break; |
1154 | 1196 |
|
1155 | 1197 | case ipICMP_ROUTER_SOLICITATION_IPv6: |
1156 | 1198 | break; |
1157 | 1199 |
|
1158 | 1200 | #if ( ipconfigUSE_RA != 0 ) |
1159 | 1201 | case ipICMP_ROUTER_ADVERTISEMENT_IPv6: |
| 1202 | + /* Size check is done inside vReceiveRA */ |
1160 | 1203 | vReceiveRA( pxNetworkBuffer ); |
1161 | 1204 | break; |
1162 | 1205 | #endif /* ( ipconfigUSE_RA != 0 ) */ |
|
1167 | 1210 | } /* switch( pxICMPHeader_IPv6->ucTypeOfMessage ) */ |
1168 | 1211 | } /* if( pxEndPoint->bits.bIPv6 != pdFALSE_UNSIGNED ) */ |
1169 | 1212 |
|
| 1213 | + } |
| 1214 | + else |
| 1215 | + { |
| 1216 | + /* Malformed ICMPv6 packet, release the network buffer (performed |
| 1217 | + in prvProcessEthernetPacket)*/ |
| 1218 | + } |
| 1219 | + |
1170 | 1220 | return eReleaseBuffer; |
1171 | 1221 | } |
1172 | 1222 | /*-----------------------------------------------------------*/ |
|
0 commit comments