Skip to content

net: ip: 6lo: Fix undefined behavior reported by UBSAN #90883

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tpambor
Copy link
Contributor

@tpambor tpambor commented May 30, 2025

htonl() and htons() take uint32_t/uint16_t as argument. Add the 'u' suffix to constants in net_6lo_addr_16_bit_compressible to ensure the correct unsigned type is used and to avoid undefined behavior if these functions are implemented as macros using bit shifts.

This fixes the following errors reported by UBSAN

zephyr/subsys/net/ip/6lo.c:131:49: runtime error: left shift of 255 by 24 places cannot be represented in type 'int'
zephyr/subsys/net/ip/6lo.c:131:49: runtime error: left shift of 255 by 24 places cannot be represented in type 'int'
zephyr/subsys/net/ip/6lo.c:131:49: runtime error: left shift of 255 by 24 places cannot be represented in type 'int'
zephyr/subsys/net/ip/6lo.c:131:49: runtime error: left shift of 255 by 24 places cannot be represented in type 'int'

This is a step towards fixing #90882.

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 <tim.pambor@codewrights.de>
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants