Skip to content

Commit c00ad8a

Browse files
authored
Merge branch 'main' into main
2 parents ba81b61 + 96c6f3a commit c00ad8a

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.
@@ -881,7 +881,7 @@
881881
configASSERT( xSocketValid( xDHCPv4Socket ) == pdTRUE );
882882

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

source/FreeRTOS_DHCPv6.c

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

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

9090
/** @brief A reference count makes sure that the UDP socket will be deleted when it
9191
* is not used anymore. */
92-
static BaseType_t xDHCPv6SocketUserCount;
92+
_static BaseType_t xDHCPv6SocketUserCount;
9393

9494
static BaseType_t prvIsOptionLengthValid( uint16_t usOption,
9595
size_t uxOptionLength,
@@ -151,7 +151,7 @@ static BaseType_t prvDHCPv6_handleOption( struct xNetworkEndPoint * pxEndPoint,
151151
/**
152152
* @brief DHCP IPv6 message object
153153
*/
154-
static DHCPMessage_IPv6_t xDHCPMessage;
154+
_static DHCPMessage_IPv6_t xDHCPMessage;
155155

156156
/**
157157
* @brief Get the DHCP state from a given endpoint.
@@ -1500,7 +1500,13 @@ static BaseType_t prvDHCPv6Analyse( struct xNetworkEndPoint * pxEndPoint,
15001500
}
15011501
else
15021502
{
1503-
ulOptionsReceived |= ( ( ( uint32_t ) 1U ) << usOption );
1503+
/* ulOptionsReceived has only 32-bits, it's not allowed to shift more than 32-bits on it. */
1504+
if( usOption < 32 )
1505+
{
1506+
/* Store the option by bit-map only if it's less than 32. */
1507+
ulOptionsReceived |= ( ( ( uint32_t ) 1U ) << usOption );
1508+
}
1509+
15041510
xReady = prvDHCPv6_handleOption( pxEndPoint, usOption, &( xSet ), pxDHCPMessage, &( xMessage ) );
15051511
}
15061512

source/FreeRTOS_DNS_Parser.c

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

1099-
ucByte = ( uint8_t ) ( ( ( pucSource[ 0 ] - ucCharA ) << 4 ) |
1099+
ucByte = ( uint8_t ) ( ( ( ( pucSource[ 0 ] - ucCharA ) & 0x0F ) << 4 ) |
11001100
( pucSource[ 1 ] - ucCharA ) );
11011101

11021102
/* 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
@@ -1694,6 +1694,81 @@ size_t FreeRTOS_min_size_t( size_t a,
16941694
}
16951695
/*-----------------------------------------------------------*/
16961696

1697+
/**
1698+
* @brief Performs a safe addition of two 32-bit integers, preventing overflow and underflow.
1699+
* @param[in] a the first value.
1700+
* @param[in] b the second value.
1701+
* @return The result of a + b if no overflow/underflow occurs, or INT32_MAX/INT32_MIN if overflow/underflow would occur.
1702+
*/
1703+
int32_t FreeRTOS_add_int32( int32_t a,
1704+
int32_t b )
1705+
{
1706+
int32_t ret;
1707+
1708+
if( ( a > 0 ) && ( b > ipINT32_MAX_VALUE - a ) )
1709+
{
1710+
ret = ipINT32_MAX_VALUE; /* Positive overflow */
1711+
}
1712+
else if( ( a < 0 ) && ( b < ipINT32_MIN_VALUE - a ) )
1713+
{
1714+
ret = ipINT32_MIN_VALUE; /* Negative underflow */
1715+
}
1716+
else
1717+
{
1718+
ret = a + b;
1719+
}
1720+
1721+
return ret;
1722+
}
1723+
/*-----------------------------------------------------------*/
1724+
1725+
/**
1726+
* @brief Performs a safe multiplication of two 32-bit integers, preventing overflow and underflow.
1727+
* @param[in] a the first value.
1728+
* @param[in] b the second value.
1729+
* @return The result of a * b if no overflow occurs, or ipINT32_MAX_VALUE if an overflow would occur.
1730+
*/
1731+
int32_t FreeRTOS_multiply_int32( int32_t a,
1732+
int32_t b )
1733+
{
1734+
int32_t ret;
1735+
1736+
/* Check for overflow/underflow */
1737+
if( a > 0 )
1738+
{
1739+
if( ( b > 0 ) && ( a > ipINT32_MAX_VALUE / b ) )
1740+
{
1741+
ret = ipINT32_MAX_VALUE; /* Positive overflow */
1742+
}
1743+
else if( ( b < 0 ) && ( b < ipINT32_MIN_VALUE / a ) )
1744+
{
1745+
ret = ipINT32_MIN_VALUE; /* Negative underflow */
1746+
}
1747+
else
1748+
{
1749+
ret = a * b;
1750+
}
1751+
}
1752+
else
1753+
{
1754+
if( ( b > 0 ) && ( a < ipINT32_MIN_VALUE / b ) )
1755+
{
1756+
ret = ipINT32_MIN_VALUE; /* Negative underflow */
1757+
}
1758+
else if( ( b < 0 ) && ( a < ipINT32_MAX_VALUE / b ) )
1759+
{
1760+
ret = ipINT32_MAX_VALUE; /* Positive overflow */
1761+
}
1762+
else
1763+
{
1764+
ret = a * b;
1765+
}
1766+
}
1767+
1768+
return ret;
1769+
}
1770+
/*-----------------------------------------------------------*/
1771+
16971772
/**
16981773
* @brief Round-up a number to a multiple of 'd'.
16991774
* @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
@@ -99,7 +99,7 @@
9999
size_t uxTCPHeaderOffset = ipSIZE_OF_ETH_HEADER + uxIPHeaderSizePacket( pxNetworkBuffer );
100100

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

@@ -430,7 +440,7 @@
430440
/* Map the ethernet buffer onto the ProtocolHeader_t struct for easy access to the fields. */
431441

432442
/* MISRA Ref 11.3.1 [Misaligned access] */
433-
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
443+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
434444
/* coverity[misra_c_2012_rule_11_3_violation] */
435445
const ProtocolHeaders_t * pxProtocolHeaders = ( ( ProtocolHeaders_t * )
436446
&( 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)