Skip to content

Commit b6cccc3

Browse files
authored
Merge branch 'main' into dev-ip-build-sep
2 parents 515434d + 96c6f3a commit b6cccc3

File tree

39 files changed

+441
-54
lines changed

39 files changed

+441
-54
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ jobs:
406406
- name: Set up CBMC runner
407407
uses: FreeRTOS/CI-CD-Github-Actions/set_up_cbmc_runner@main
408408
with:
409-
cbmc_version: "5.95.1"
409+
cbmc_version: "6.3.1"
410410

411411
- env:
412412
stepName: Install Dependencies

source/FreeRTOS_DHCP.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
/**
8282
* @brief The number of end-points that are making use of the UDP-socket.
8383
*/
84-
static BaseType_t xDHCPSocketUserCount = 0;
84+
_static BaseType_t xDHCPSocketUserCount = 0;
8585

8686
/*
8787
* Generate a DHCP discover message and send it on the DHCP socket.
@@ -880,7 +880,7 @@
880880
configASSERT( xSocketValid( xDHCPv4Socket ) == pdTRUE );
881881

882882
/* MISRA Ref 11.4.1 [Socket error and integer to pointer conversion] */
883-
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-114 */
883+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-114 */
884884
/* coverity[misra_c_2012_rule_11_4_violation] */
885885
if( xSocketValid( xDHCPv4Socket ) == pdTRUE )
886886
{

source/FreeRTOS_DHCPv6.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@
8080
( ( ( uint32_t ) 1U ) << DHCPv6_Option_Server_Identifier ) )
8181

8282
/** @brief The UDP socket which is shared by all end-points that need DHCPv6. */
83-
static Socket_t xDHCPv6Socket;
83+
_static Socket_t xDHCPv6Socket;
8484

8585
/** @brief A reference count makes sure that the UDP socket will be deleted when it
8686
* is not used anymore. */
87-
static BaseType_t xDHCPv6SocketUserCount;
87+
_static BaseType_t xDHCPv6SocketUserCount;
8888

8989
static BaseType_t prvIsOptionLengthValid( uint16_t usOption,
9090
size_t uxOptionLength,
@@ -146,7 +146,7 @@ static BaseType_t prvDHCPv6_handleOption( struct xNetworkEndPoint * pxEndPoint,
146146
/**
147147
* @brief DHCP IPv6 message object
148148
*/
149-
static DHCPMessage_IPv6_t xDHCPMessage;
149+
_static DHCPMessage_IPv6_t xDHCPMessage;
150150

151151
/**
152152
* @brief Get the DHCP state from a given endpoint.
@@ -1495,7 +1495,13 @@ static BaseType_t prvDHCPv6Analyse( struct xNetworkEndPoint * pxEndPoint,
14951495
}
14961496
else
14971497
{
1498-
ulOptionsReceived |= ( ( ( uint32_t ) 1U ) << usOption );
1498+
/* ulOptionsReceived has only 32-bits, it's not allowed to shift more than 32-bits on it. */
1499+
if( usOption < 32 )
1500+
{
1501+
/* Store the option by bit-map only if it's less than 32. */
1502+
ulOptionsReceived |= ( ( ( uint32_t ) 1U ) << usOption );
1503+
}
1504+
14991505
xReady = prvDHCPv6_handleOption( pxEndPoint, usOption, &( xSet ), pxDHCPMessage, &( xMessage ) );
15001506
}
15011507

source/FreeRTOS_DNS_Parser.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,7 @@
10931093
/* Define the ASCII value of the capital "A". */
10941094
const uint8_t ucCharA = ( uint8_t ) 0x41U;
10951095

1096-
ucByte = ( uint8_t ) ( ( ( pucSource[ 0 ] - ucCharA ) << 4 ) |
1096+
ucByte = ( uint8_t ) ( ( ( ( pucSource[ 0 ] - ucCharA ) & 0x0F ) << 4 ) |
10971097
( pucSource[ 1 ] - ucCharA ) );
10981098

10991099
/* Make sure there are no trailing spaces in the name. */

source/FreeRTOS_IP_Utils.c

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,6 +1706,81 @@ size_t FreeRTOS_min_size_t( size_t a,
17061706
}
17071707
/*-----------------------------------------------------------*/
17081708

1709+
/**
1710+
* @brief Performs a safe addition of two 32-bit integers, preventing overflow and underflow.
1711+
* @param[in] a the first value.
1712+
* @param[in] b the second value.
1713+
* @return The result of a + b if no overflow/underflow occurs, or INT32_MAX/INT32_MIN if overflow/underflow would occur.
1714+
*/
1715+
int32_t FreeRTOS_add_int32( int32_t a,
1716+
int32_t b )
1717+
{
1718+
int32_t ret;
1719+
1720+
if( ( a > 0 ) && ( b > ipINT32_MAX_VALUE - a ) )
1721+
{
1722+
ret = ipINT32_MAX_VALUE; /* Positive overflow */
1723+
}
1724+
else if( ( a < 0 ) && ( b < ipINT32_MIN_VALUE - a ) )
1725+
{
1726+
ret = ipINT32_MIN_VALUE; /* Negative underflow */
1727+
}
1728+
else
1729+
{
1730+
ret = a + b;
1731+
}
1732+
1733+
return ret;
1734+
}
1735+
/*-----------------------------------------------------------*/
1736+
1737+
/**
1738+
* @brief Performs a safe multiplication of two 32-bit integers, preventing overflow and underflow.
1739+
* @param[in] a the first value.
1740+
* @param[in] b the second value.
1741+
* @return The result of a * b if no overflow occurs, or ipINT32_MAX_VALUE if an overflow would occur.
1742+
*/
1743+
int32_t FreeRTOS_multiply_int32( int32_t a,
1744+
int32_t b )
1745+
{
1746+
int32_t ret;
1747+
1748+
/* Check for overflow/underflow */
1749+
if( a > 0 )
1750+
{
1751+
if( ( b > 0 ) && ( a > ipINT32_MAX_VALUE / b ) )
1752+
{
1753+
ret = ipINT32_MAX_VALUE; /* Positive overflow */
1754+
}
1755+
else if( ( b < 0 ) && ( b < ipINT32_MIN_VALUE / a ) )
1756+
{
1757+
ret = ipINT32_MIN_VALUE; /* Negative underflow */
1758+
}
1759+
else
1760+
{
1761+
ret = a * b;
1762+
}
1763+
}
1764+
else
1765+
{
1766+
if( ( b > 0 ) && ( a < ipINT32_MIN_VALUE / b ) )
1767+
{
1768+
ret = ipINT32_MIN_VALUE; /* Negative underflow */
1769+
}
1770+
else if( ( b < 0 ) && ( a < ipINT32_MAX_VALUE / b ) )
1771+
{
1772+
ret = ipINT32_MAX_VALUE; /* Positive overflow */
1773+
}
1774+
else
1775+
{
1776+
ret = a * b;
1777+
}
1778+
}
1779+
1780+
return ret;
1781+
}
1782+
/*-----------------------------------------------------------*/
1783+
17091784
/**
17101785
* @brief Round-up a number to a multiple of 'd'.
17111786
* @param[in] a the first value.

source/FreeRTOS_TCP_Reception.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
size_t uxTCPHeaderOffset = ipSIZE_OF_ETH_HEADER + uxIPHeaderSizePacket( pxNetworkBuffer );
9999

100100
/* MISRA Ref 11.3.1 [Misaligned access] */
101-
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
101+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
102102
/* coverity[misra_c_2012_rule_11_3_violation] */
103103
const ProtocolHeaders_t * pxProtocolHeaders = ( ( ProtocolHeaders_t * )
104104
&( pxNetworkBuffer->pucEthernetBuffer[ uxTCPHeaderOffset ] ) );
@@ -236,7 +236,17 @@
236236
/* Option is only valid in SYN phase. */
237237
if( xHasSYNFlag != 0 )
238238
{
239-
pxSocket->u.xTCP.ucPeerWinScaleFactor = pucPtr[ 2 ];
239+
/* From RFC7323 - section 2.3, we should limit the WSopt not larger than 14. */
240+
if( pucPtr[ 2 ] > tcpTCP_OPT_WSOPT_MAXIMUM_VALUE )
241+
{
242+
FreeRTOS_debug_printf( ( "The WSopt(%u) from SYN packet is larger than maximum value.", pucPtr[ 2 ] ) );
243+
pxSocket->u.xTCP.ucPeerWinScaleFactor = tcpTCP_OPT_WSOPT_MAXIMUM_VALUE;
244+
}
245+
else
246+
{
247+
pxSocket->u.xTCP.ucPeerWinScaleFactor = pucPtr[ 2 ];
248+
}
249+
240250
pxSocket->u.xTCP.bits.bWinScaling = pdTRUE_UNSIGNED;
241251
}
242252

@@ -429,7 +439,7 @@
429439
/* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */
430440

431441
/* MISRA Ref 11.3.1 [Misaligned access] */
432-
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
442+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
433443
/* coverity[misra_c_2012_rule_11_3_violation] */
434444
const ProtocolHeaders_t * pxProtocolHeaders = ( ( ProtocolHeaders_t * )
435445
&( pxNetworkBuffer->pucEthernetBuffer[ ( size_t ) ipSIZE_OF_ETH_HEADER + uxIPHeaderSizePacket( pxNetworkBuffer ) ] ) );

source/FreeRTOS_TCP_WIN.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,18 +1901,33 @@
19011901
const TCPSegment_t * pxSegment )
19021902
{
19031903
int32_t mS = ( int32_t ) ulTimerGetAge( &( pxSegment->xTransmitTimer ) );
1904+
int32_t lSum = 0;
1905+
int32_t lWeight = 0;
1906+
int32_t lDivisor = 0;
1907+
1908+
mS = mS < 0 ? ipINT32_MAX_VALUE : mS;
19041909

19051910
if( pxWindow->lSRTT >= mS )
19061911
{
19071912
/* RTT becomes smaller: adapt slowly. */
1908-
pxWindow->lSRTT = ( ( winSRTT_DECREMENT_NEW * mS ) + ( winSRTT_DECREMENT_CURRENT * pxWindow->lSRTT ) ) / ( winSRTT_DECREMENT_NEW + winSRTT_DECREMENT_CURRENT );
1913+
lWeight = winSRTT_DECREMENT_CURRENT;
1914+
lDivisor = winSRTT_DECREMENT_NEW + winSRTT_DECREMENT_CURRENT;
1915+
mS = FreeRTOS_multiply_int32( mS,
1916+
winSRTT_DECREMENT_NEW );
19091917
}
19101918
else
19111919
{
19121920
/* RTT becomes larger: adapt quicker */
1913-
pxWindow->lSRTT = ( ( winSRTT_INCREMENT_NEW * mS ) + ( winSRTT_INCREMENT_CURRENT * pxWindow->lSRTT ) ) / ( winSRTT_INCREMENT_NEW + winSRTT_INCREMENT_CURRENT );
1921+
lWeight = winSRTT_INCREMENT_CURRENT;
1922+
lDivisor = winSRTT_INCREMENT_NEW + winSRTT_INCREMENT_CURRENT;
1923+
mS = FreeRTOS_multiply_int32( mS,
1924+
winSRTT_INCREMENT_NEW );
19141925
}
19151926

1927+
lSum = FreeRTOS_multiply_int32( pxWindow->lSRTT, lWeight );
1928+
lSum = FreeRTOS_add_int32( lSum, mS );
1929+
pxWindow->lSRTT = lSum / lDivisor;
1930+
19161931
/* Cap to the minimum of 50ms. */
19171932
if( pxWindow->lSRTT < winSRTT_CAP_mS )
19181933
{
@@ -1946,7 +1961,7 @@
19461961
const ListItem_t * pxIterator;
19471962

19481963
/* MISRA Ref 11.3.1 [Misaligned access] */
1949-
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
1964+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
19501965
/* coverity[misra_c_2012_rule_11_3_violation] */
19511966
const ListItem_t * pxEnd = ( ( const ListItem_t * ) &( pxWindow->xTxSegments.xListEnd ) );
19521967
BaseType_t xDoUnlink;

source/include/FreeRTOS_IP.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@
6060
#define ipSIZE_OF_UDP_HEADER 8U
6161
#define ipSIZE_OF_TCP_HEADER 20U
6262

63+
/* The maximum of int32 value. */
64+
#define ipINT32_MAX_VALUE ( ( int32_t ) 0x7FFFFFFF )
65+
66+
/* The minimum of int32 value. */
67+
#define ipINT32_MIN_VALUE ( ( int32_t ) 0x80000000 )
6368

6469
/*
6570
* Generate a randomized TCP Initial Sequence Number per RFC.
@@ -270,6 +275,11 @@ uint32_t FreeRTOS_min_uint32( uint32_t a,
270275
size_t FreeRTOS_min_size_t( size_t a,
271276
size_t b );
272277

278+
int32_t FreeRTOS_add_int32( int32_t a,
279+
int32_t b );
280+
int32_t FreeRTOS_multiply_int32( int32_t a,
281+
int32_t b );
282+
273283
uint32_t FreeRTOS_round_up( uint32_t a,
274284
uint32_t d );
275285
uint32_t FreeRTOS_round_down( uint32_t a,

source/include/FreeRTOS_TCP_IP.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,25 +96,26 @@ typedef enum eTCP_STATE
9696
/*
9797
* A few values of the TCP options:
9898
*/
99-
#define tcpTCP_OPT_END 0U /**< End of TCP options list. */
100-
#define tcpTCP_OPT_NOOP 1U /**< "No-operation" TCP option. */
101-
#define tcpTCP_OPT_MSS 2U /**< Maximum segment size TCP option. */
102-
#define tcpTCP_OPT_WSOPT 3U /**< TCP Window Scale Option (3-byte long). */
103-
#define tcpTCP_OPT_SACK_P 4U /**< Advertise that SACK is permitted. */
104-
#define tcpTCP_OPT_SACK_A 5U /**< SACK option with first/last. */
105-
#define tcpTCP_OPT_TIMESTAMP 8U /**< Time-stamp option. */
99+
#define tcpTCP_OPT_END 0U /**< End of TCP options list. */
100+
#define tcpTCP_OPT_NOOP 1U /**< "No-operation" TCP option. */
101+
#define tcpTCP_OPT_MSS 2U /**< Maximum segment size TCP option. */
102+
#define tcpTCP_OPT_WSOPT 3U /**< TCP Window Scale Option (3-byte long). */
103+
#define tcpTCP_OPT_SACK_P 4U /**< Advertise that SACK is permitted. */
104+
#define tcpTCP_OPT_SACK_A 5U /**< SACK option with first/last. */
105+
#define tcpTCP_OPT_TIMESTAMP 8U /**< Time-stamp option. */
106106

107107

108-
#define tcpTCP_OPT_MSS_LEN 4U /**< Length of TCP MSS option. */
109-
#define tcpTCP_OPT_WSOPT_LEN 3U /**< Length of TCP WSOPT option. */
108+
#define tcpTCP_OPT_MSS_LEN 4U /**< Length of TCP MSS option. */
109+
#define tcpTCP_OPT_WSOPT_LEN 3U /**< Length of TCP WSOPT option. */
110+
#define tcpTCP_OPT_WSOPT_MAXIMUM_VALUE ( 14U ) /**< Maximum value of TCP WSOPT option. */
110111

111-
#define tcpTCP_OPT_TIMESTAMP_LEN 10 /**< fixed length of the time-stamp option. */
112+
#define tcpTCP_OPT_TIMESTAMP_LEN 10 /**< fixed length of the time-stamp option. */
112113

113114
/** @brief
114115
* Minimum segment length as outlined by RFC 791 section 3.1.
115116
* Minimum segment length ( 536 ) = Minimum MTU ( 576 ) - IP Header ( 20 ) - TCP Header ( 20 ).
116117
*/
117-
#define tcpMINIMUM_SEGMENT_LENGTH 536U
118+
#define tcpMINIMUM_SEGMENT_LENGTH 536U
118119

119120
/** @brief
120121
* The macro tcpNOW_CONNECTED() is use to determine if the connection makes a

test/Coverity/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ see the [MISRA.md](https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA
1313

1414
## Getting Started
1515
### Prerequisites
16-
You can run this on a platform supported by Coverity. The list and other details can be found [here](https://sig-docs.synopsys.com/polaris/topics/c_coverity-compatible-platforms.html).
16+
You can run this on a platform supported by Coverity. The list and other details can be found [here](https://documentation.blackduck.com/bundle/coverity-docs/page/deploy-install-guide/topics/supported_platforms_for_coverity_analysis.html).
1717
To compile and run the Coverity target successfully, you must have the following:
1818

1919
1. CMake version > 3.13.0 (You can check whether you have this by typing `cmake --version`)

0 commit comments

Comments
 (0)