Skip to content
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

fix: bit shifting for 64bit bridge port mask #56

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

Conversation

gregnr
Copy link

@gregnr gregnr commented Feb 12, 2025

Problem

During bridge input processing, there is conditional logic to check if the bridge interface itself should receive the packet (ie. forward to CPU). The existing bitwise logic fails when BRIDGEIF_MAX_PORTS >= 32 because the literal 1 is implicitly a 32-bit integer. When shifting this value by BRIDGEIF_MAX_PORTS bits (which can be up to 63), it triggers undefined behaviour due to the shift count exceeding the width of the type.

Fix

Explicitly cast 1 to bridgeif_portmask_t to ensure that the shift operation is performed on a 64-bit value when necessary. This works because when BRIDGEIF_MAX_PORTS >= 32, bridgeif_portmask_t is defined as a u64_t type:

#if (BRIDGEIF_MAX_PORTS < 0) || (BRIDGEIF_MAX_PORTS >= 64)
#error BRIDGEIF_MAX_PORTS must be [1..63]
#elif BRIDGEIF_MAX_PORTS < 8
typedef u8_t bridgeif_portmask_t;
#elif BRIDGEIF_MAX_PORTS < 16
typedef u16_t bridgeif_portmask_t;
#elif BRIDGEIF_MAX_PORTS < 32
typedef u32_t bridgeif_portmask_t;
#elif BRIDGEIF_MAX_PORTS < 64
typedef u64_t bridgeif_portmask_t;
#endif

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

Successfully merging this pull request may close these issues.

None yet

1 participant