Skip to content

Commit a760ba7

Browse files
tpambordkalowsk
authored andcommitted
net: ip: 6lo: Fix undefined behavior reported by UBSAN
htonl() and htons() take uint32_t/uint16_t as argument. Add the 'u' suffix to constants to ensure the correct unsigned type is used and to avoid undefined behavior if these functions are implemented as macros using bit shifts. Signed-off-by: Tim Pambor <[email protected]>
1 parent 1e14953 commit a760ba7

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

subsys/net/ip/6lo.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ static inline bool net_6lo_ll_prefix_padded_with_zeros(struct in6_addr *addr)
128128

129129
static inline bool net_6lo_addr_16_bit_compressible(struct in6_addr *addr)
130130
{
131-
return ((UNALIGNED_GET(&addr->s6_addr32[2]) == htonl(0xFF)) &&
132-
(UNALIGNED_GET(&addr->s6_addr16[6]) == htons(0xFE00)));
131+
return ((UNALIGNED_GET(&addr->s6_addr32[2]) == htonl(0xFFu)) &&
132+
(UNALIGNED_GET(&addr->s6_addr16[6]) == htons(0xFE00u)));
133133
}
134134

135135
static inline bool net_6lo_maddr_8_bit_compressible(struct in6_addr *addr)

0 commit comments

Comments
 (0)