Skip to content

Update simple_pre_lag.cpp - #1440

Closed
Devansh-567 wants to merge 0 commit into
p4lang:mainfrom
Devansh-567:main
Closed

Update simple_pre_lag.cpp#1440
Devansh-567 wants to merge 0 commit into
p4lang:mainfrom
Devansh-567:main

Conversation

@Devansh-567

Copy link
Copy Markdown
Contributor

Fix off-by-one error in LAG index validation

Change the index boundary check in mc_set_lag_membership from > to >=. Previously, passing lag_index == LAG_MAX_ENTRIES bypassed the error check and resulted in out-of-bounds access.

@jafingerhut jafingerhut left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable to me, although it is not easy for me to find other references in the code to what the range of values is expected to be.

@Devansh-567

Copy link
Copy Markdown
Contributor Author

Looks reasonable to me, although it is not easy for me to find other references in the code to what the range of values is expected to be.

Because C++ uses 0-based indexing for fixed-size structures, a size/count of LAG_MAX_ENTRIES means valid index values are 0 through LAG_MAX_ENTRIES - 1. Passing lag_index == LAG_MAX_ENTRIES was hitting array boundary limits, so changing > to >= catches that edge case and prevents out-of-bounds access.

@jafingerhut

Copy link
Copy Markdown
Contributor

Is there a reason you wanted to close this PR without merging it?

@Devansh-567

Devansh-567 commented Aug 21, 2026

Copy link
Copy Markdown
Contributor Author

Is there a reason you wanted to close this PR without merging it?

Apologies for the confusion, it was accidentally closed during a branch cleanup. I have reopened this fix in PR #1444 on a clean branch.

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.

2 participants