Skip to content

Commit 606572e

Browse files
eleanorLYJkuba-moo
authored andcommitted
sctp: Fix undefined behavior in left shift operation
According to the C11 standard (ISO/IEC 9899:2011, 6.5.7): "If E1 has a signed type and E1 x 2^E2 is not representable in the result type, the behavior is undefined." Shifting 1 << 31 causes signed integer overflow, which leads to undefined behavior. Fix this by explicitly using '1U << 31' to ensure the shift operates on an unsigned type, avoiding undefined behavior. Signed-off-by: Yu-Chun Lin <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 5bcd3d1 commit 606572e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

net/sctp/stream.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ struct sctp_chunk *sctp_process_strreset_tsnreq(
735735
* value SHOULD be the smallest TSN not acknowledged by the
736736
* receiver of the request plus 2^31.
737737
*/
738-
init_tsn = sctp_tsnmap_get_ctsn(&asoc->peer.tsn_map) + (1 << 31);
738+
init_tsn = sctp_tsnmap_get_ctsn(&asoc->peer.tsn_map) + (1U << 31);
739739
sctp_tsnmap_init(&asoc->peer.tsn_map, SCTP_TSN_MAP_INITIAL,
740740
init_tsn, GFP_ATOMIC);
741741

0 commit comments

Comments
 (0)