Skip to content

Commit 525a420

Browse files
authored
Discard UDPv6 with zero checksum. (#790)
* Reject UDPv6 if checksum is 0. * Fix MISRA violations.
1 parent 8926945 commit 525a420

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

source/FreeRTOS_Sockets.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5487,7 +5487,7 @@ BaseType_t xSocketSetSocketID( const Socket_t xSocket,
54875487
FreeRTOS_Socket_t * pxSocket = ( FreeRTOS_Socket_t * ) xSocket;
54885488
BaseType_t xReturn = -pdFREERTOS_ERRNO_EINVAL;
54895489

5490-
if( xSocketValid( pxSocket ) )
5490+
if( xSocketValid( pxSocket ) == pdTRUE )
54915491
{
54925492
xReturn = 0;
54935493
pxSocket->pvSocketID = pvSocketID;
@@ -5509,7 +5509,7 @@ void * pvSocketGetSocketID( const ConstSocket_t xSocket )
55095509
const FreeRTOS_Socket_t * pxSocket = ( const FreeRTOS_Socket_t * ) xSocket;
55105510
void * pvReturn = NULL;
55115511

5512-
if( xSocketValid( pxSocket ) )
5512+
if( xSocketValid( pxSocket ) == pdTRUE )
55135513
{
55145514
pvReturn = pxSocket->pvSocketID;
55155515
}

source/FreeRTOS_UDP_IPv6.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,17 @@ BaseType_t xProcessReceivedUDPPacket_IPv6( NetworkBufferDescriptor_t * pxNetwork
446446

447447
do
448448
{
449+
/* UDPv6 doesn't allow zero-checksum, refer to RFC2460 - section 8.1.
450+
* Some platforms (such as Zynq) pass the packet to upper layer for flexibility to allow zero-checksum. */
451+
if( pxUDPPacket_IPv6->xUDPHeader.usChecksum == 0U )
452+
{
453+
FreeRTOS_debug_printf( ( "xProcessReceivedUDPPacket_IPv6: Drop packets with checksum %d\n",
454+
pxUDPPacket_IPv6->xUDPHeader.usChecksum ) );
455+
456+
xReturn = pdFAIL;
457+
break;
458+
}
459+
449460
if( pxSocket != NULL )
450461
{
451462
if( xCheckRequiresARPResolution( pxNetworkBuffer ) == pdTRUE )

0 commit comments

Comments
 (0)