Skip to content

fix off-by-one error in LAG index validation (re-opening #1440) - #1444

Open
Devansh-567 wants to merge 1 commit into
p4lang:mainfrom
Devansh-567:fix-lag-index-boundary
Open

fix off-by-one error in LAG index validation (re-opening #1440)#1444
Devansh-567 wants to merge 1 commit into
p4lang:mainfrom
Devansh-567:fix-lag-index-boundary

Conversation

@Devansh-567

Copy link
Copy Markdown
Contributor

Summary

fixes an off-by-one error in McSimplePreLAG::mc_set_lag_membership where lag_index validation used > instead of >=.

This replaces and re-opens the changes from closed PR #1440 onto a clean branch.

Context & Solution

In C++, 0-based indexing for fixed-size structures means that for LAG_MAX_ENTRIES, valid indices are 0 through LAG_MAX_ENTRIES - 1. Passing lag_index == LAG_MAX_ENTRIES bypassed the previous lag_index > LAG_MAX_ENTRIES boundary check, leading to potential out-of-bounds access.

Updating the check to lag_index >= LAG_MAX_ENTRIES correctly catches this edge case and returns ERROR.

Changes Made

  • Modified src/bm_sim/simple_pre_lag.cpp: Updated lag_index > LAG_MAX_ENTRIES check to >=.

Signed-off-by: Devansh-567 <devansh.jay.singh@gmail.com>
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.

1 participant