Skip to content

Commit e1536d8

Browse files
committed
Initial version with UTs fixed
1 parent 19134e1 commit e1536d8

File tree

5 files changed

+201
-16
lines changed

5 files changed

+201
-16
lines changed

source/FreeRTOS_ND.c

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@
153153
MACAddress_t * const pxMACAddress,
154154
NetworkEndPoint_t ** ppxEndPoint )
155155
{
156-
eResolutionLookupResult_t eReturn;
156+
eResolutionLookupResult_t eReturn = eResolutionCacheMiss;
157157

158158
/* Mostly used multi-cast address is ff02::. */
159159
if( xIsIPv6AllowedMulticast( pxAddressToLookup ) != pdFALSE )
@@ -163,14 +163,20 @@
163163
if( ppxEndPoint != NULL )
164164
{
165165
*ppxEndPoint = pxFindLocalEndpoint();
166-
}
167166

168-
eReturn = eResolutionCacheHit;
167+
if (*ppxEndPoint != NULL)
168+
{
169+
eReturn = eResolutionCacheHit;
170+
}
171+
else
172+
{
173+
/* No link-local endpoint configured, eResolutionCacheMiss */
174+
}
175+
}
169176
}
170177
else
171178
{
172-
/* Not a multicast IP address. */
173-
eReturn = eResolutionCacheMiss;
179+
/* Not a multicast IP address, eResolutionCacheMiss */
174180
}
175181

176182
return eReturn;
@@ -977,6 +983,23 @@
977983
* @return A const value 'eReleaseBuffer' which means that the network must still be released.
978984
*/
979985
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 ) )
9801003
{
9811004
/* MISRA Ref 11.3.1 [Misaligned access] */
9821005
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
@@ -1052,6 +1075,14 @@
10521075

10531076
/* Find the total length of the IP packet. */
10541077
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+
10551086
uxDataLength = uxDataLength - sizeof( *pxICMPEchoHeader );
10561087

10571088
/* Find the first byte of the data within the ICMP packet. */
@@ -1128,6 +1159,17 @@
11281159
break;
11291160

11301161
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+
11311173
/* MISRA Ref 11.3.1 [Misaligned access] */
11321174
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
11331175
/* coverity[misra_c_2012_rule_11_3_violation] */
@@ -1149,14 +1191,15 @@
11491191
{
11501192
prvCheckWaitingBuffer( &( pxICMPHeader_IPv6->xIPv6Address ) );
11511193
}
1152-
1194+
}
11531195
break;
11541196

11551197
case ipICMP_ROUTER_SOLICITATION_IPv6:
11561198
break;
11571199

11581200
#if ( ipconfigUSE_RA != 0 )
11591201
case ipICMP_ROUTER_ADVERTISEMENT_IPv6:
1202+
/* Size check is done inside vReceiveRA */
11601203
vReceiveRA( pxNetworkBuffer );
11611204
break;
11621205
#endif /* ( ipconfigUSE_RA != 0 ) */
@@ -1167,6 +1210,13 @@
11671210
} /* switch( pxICMPHeader_IPv6->ucTypeOfMessage ) */
11681211
} /* if( pxEndPoint->bits.bIPv6 != pdFALSE_UNSIGNED ) */
11691212

1213+
}
1214+
else
1215+
{
1216+
/* Malformed ICMPv6 packet, release the network buffer (performed
1217+
in prvProcessEthernetPacket)*/
1218+
}
1219+
11701220
return eReleaseBuffer;
11711221
}
11721222
/*-----------------------------------------------------------*/

source/include/FreeRTOS_IPv6_Private.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@
132132
struct xNetworkEndPoint;
133133
struct xNetworkInterface;
134134

135+
#define ipICMPv6_GENERAL_FIELD_SIZE (4U)
136+
135137
#include "pack_struct_start.h"
136138
struct xIP_HEADER_IPv6
137139
{

test/cbmc/proofs/ND/prvProcessICMPMessage_IPv6/ProcessICMPMessage_IPv6_harness.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ void harness()
137137
uint16_t usEthernetBufferSize;
138138
NetworkBufferDescriptor_t * pxLocalARPWaitingNetworkBuffer;
139139

140-
__CPROVER_assume( ( ulLen >= sizeof( ICMPPacket_IPv6_t ) ) && ( ulLen < ipconfigNETWORK_MTU ) );
140+
/* Following assumption is to make sure ulLen doesnt go
141+
* beyond CBMC_MAX_OBJECT_SIZE */
142+
__CPROVER_assume( ulLen < ( CBMC_MAX_OBJECT_SIZE - ipBUFFER_PADDING ) );
141143

142144
pxNetworkBuffer = pxGetNetworkBufferWithDescriptor( ulLen, 0 );
143145

0 commit comments

Comments
 (0)