Skip to content

Commit 888e4df

Browse files
committed
Intial version with UTs fixed
1 parent 28cb4eb commit 888e4df

File tree

5 files changed

+201
-12
lines changed

5 files changed

+201
-12
lines changed

source/FreeRTOS_ND.c

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@
147147
MACAddress_t * const pxMACAddress,
148148
NetworkEndPoint_t ** ppxEndPoint )
149149
{
150-
eARPLookupResult_t eReturn;
150+
eARPLookupResult_t eReturn = eARPCacheMiss;
151151

152152
/* Mostly used multi-cast address is ff02::. */
153153
if( xIsIPv6AllowedMulticast( pxAddressToLookup ) != pdFALSE )
@@ -157,14 +157,20 @@
157157
if( ppxEndPoint != NULL )
158158
{
159159
*ppxEndPoint = pxFindLocalEndpoint();
160-
}
161160

162-
eReturn = eARPCacheHit;
161+
if (*ppxEndPoint != NULL)
162+
{
163+
eReturn = eARPCacheHit;
164+
}
165+
else
166+
{
167+
/* No link-local endpoint configured, eARPCacheHit */
168+
}
169+
}
163170
}
164171
else
165172
{
166-
/* Not a multicast IP address. */
167-
eReturn = eARPCacheMiss;
173+
/* Not a multicast IP address, eARPCacheHit */
168174
}
169175

170176
return eReturn;
@@ -955,6 +961,23 @@
955961
*/
956962
eFrameProcessingResult_t prvProcessICMPMessage_IPv6( NetworkBufferDescriptor_t * const pxNetworkBuffer )
957963
{
964+
/*
965+
ICMPv6 messages have the following general format:
966+
967+
0 1 2 3
968+
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
969+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
970+
| Type | Code | Checksum |
971+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
972+
| |
973+
+ Message Body +
974+
| |
975+
976+
The packet should contain atleast 4 bytes of general fields
977+
978+
*/
979+
if( pxNetworkBuffer->xDataLength >= ( size_t ) ( ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER + ipICMPv6_GENERAL_FIELD_SIZE ) )
980+
{
958981
/* MISRA Ref 11.3.1 [Misaligned access] */
959982
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
960983
/* coverity[misra_c_2012_rule_11_3_violation] */
@@ -1029,6 +1052,14 @@
10291052

10301053
/* Find the total length of the IP packet. */
10311054
uxDataLength = ipNUMERIC_CAST( size_t, FreeRTOS_ntohs( pxICMPPacket->xIPHeader.usPayloadLength ) );
1055+
1056+
uxNeededSize = ( size_t ) ( ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER + uxDataLength );
1057+
if( uxNeededSize > pxNetworkBuffer->xDataLength )
1058+
{
1059+
FreeRTOS_printf( ( "Too small\n" ) );
1060+
break;
1061+
}
1062+
10321063
uxDataLength = uxDataLength - sizeof( *pxICMPEchoHeader );
10331064

10341065
/* Find the first byte of the data within the ICMP packet. */
@@ -1105,6 +1136,16 @@
11051136
break;
11061137

11071138
case ipICMP_NEIGHBOR_ADVERTISEMENT_IPv6:
1139+
{
1140+
size_t uxICMPSize;
1141+
uxICMPSize = sizeof( ICMPHeader_IPv6_t );
1142+
uxNeededSize = ( size_t ) ( ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER + uxICMPSize );
1143+
1144+
if( uxNeededSize > pxNetworkBuffer->xDataLength )
1145+
{
1146+
FreeRTOS_printf( ( "Too small\n" ) );
1147+
break;
1148+
}
11081149
/* MISRA Ref 11.3.1 [Misaligned access] */
11091150
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
11101151
/* coverity[misra_c_2012_rule_11_3_violation] */
@@ -1126,14 +1167,15 @@
11261167
{
11271168
prvCheckWaitingBuffer( &( pxICMPHeader_IPv6->xIPv6Address ) );
11281169
}
1129-
1170+
}
11301171
break;
11311172

11321173
case ipICMP_ROUTER_SOLICITATION_IPv6:
11331174
break;
11341175

11351176
#if ( ipconfigUSE_RA != 0 )
11361177
case ipICMP_ROUTER_ADVERTISEMENT_IPv6:
1178+
/* Size check is done inside vReceiveRA */
11371179
vReceiveRA( pxNetworkBuffer );
11381180
break;
11391181
#endif /* ( ipconfigUSE_RA != 0 ) */
@@ -1143,7 +1185,12 @@
11431185
break;
11441186
} /* switch( pxICMPHeader_IPv6->ucTypeOfMessage ) */
11451187
} /* if( pxEndPoint->bits.bIPv6 != pdFALSE_UNSIGNED ) */
1146-
1188+
}
1189+
else
1190+
{
1191+
/* Malformed ICMPv6 packet, release the network buffer (performed
1192+
in prvProcessEthernetPacket)*/
1193+
}
11471194
return eReleaseBuffer;
11481195
}
11491196
/*-----------------------------------------------------------*/

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)