Skip to content

Commit 0a5f7fb

Browse files
anordalAndreas Nordal
and
Andreas Nordal
authored
FreeRTOS_TCP_Transmission_IPv4,6(): Move deref behind nullptr check (#1137)
Fix a possible null pointer derefernce: The pointer returned by pxDuplicateNetworkBufferWithDescriptor() was being dereferenced outside its null checks. This could only happen if ipconfigZERO_COPY_TX_DRIVER was enabled. Conveniently, the statement that used the pointer could be moved into the scope of the null check. Co-authored-by: Andreas Nordal <[email protected]>
1 parent a53e71a commit 0a5f7fb

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

source/FreeRTOS_TCP_Transmission_IPv4.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,17 @@ void prvTCPReturnPacket_IPV4( FreeRTOS_Socket_t * pxSocket,
141141
}
142142
#endif /* ipconfigZERO_COPY_TX_DRIVER */
143143

144-
/* MISRA Ref 11.3.1 [Misaligned access] */
145-
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
146-
/* coverity[misra_c_2012_rule_11_3_violation] */
147-
pxIPHeader = ( ( IPHeader_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER ] ) );
148-
149144
#ifndef __COVERITY__
150145
if( pxNetworkBuffer != NULL ) /* LCOV_EXCL_BR_LINE the 2nd branch will never be reached */
151146
#endif
152147
{
153148
NetworkInterface_t * pxInterface;
154149

150+
/* MISRA Ref 11.3.1 [Misaligned access] */
151+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
152+
/* coverity[misra_c_2012_rule_11_3_violation] */
153+
pxIPHeader = ( ( IPHeader_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER ] ) );
154+
155155
/* Map the Ethernet buffer onto a TCPPacket_t struct for easy access to the fields. */
156156

157157
/* MISRA Ref 11.3.1 [Misaligned access] */

source/FreeRTOS_TCP_Transmission_IPv6.c

+8-7
Original file line numberDiff line numberDiff line change
@@ -147,19 +147,20 @@ void prvTCPReturnPacket_IPV6( FreeRTOS_Socket_t * pxSocket,
147147
}
148148
#endif /* ipconfigZERO_COPY_TX_DRIVER */
149149

150-
configASSERT( pxNetworkBuffer->pucEthernetBuffer != NULL );
151-
152-
/* MISRA Ref 11.3.1 [Misaligned access] */
153-
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
154-
/* coverity[misra_c_2012_rule_11_3_violation] */
155-
pxIPHeader = ( ( IPHeader_IPv6_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER ] ) );
156-
157150
#ifndef __COVERITY__
158151
if( pxNetworkBuffer != NULL ) /* LCOV_EXCL_BR_LINE the 2nd branch will never be reached */
159152
#endif
160153
{
161154
eARPLookupResult_t eResult;
162155
NetworkInterface_t * pxInterface;
156+
157+
configASSERT( pxNetworkBuffer->pucEthernetBuffer != NULL );
158+
159+
/* MISRA Ref 11.3.1 [Misaligned access] */
160+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
161+
/* coverity[misra_c_2012_rule_11_3_violation] */
162+
pxIPHeader = ( ( IPHeader_IPv6_t * ) &( pxNetworkBuffer->pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER ] ) );
163+
163164
/* Map the Ethernet buffer onto a TCPPacket_t struct for easy access to the fields. */
164165

165166
/* MISRA Ref 11.3.1 [Misaligned access] */

0 commit comments

Comments
 (0)