Skip to content

Fix IndexError when parsing FIB route keys without colon#22290

Open
nnelluri-cisco wants to merge 2 commits intosonic-net:masterfrom
nnelluri-cisco:fib_utils-fix
Open

Fix IndexError when parsing FIB route keys without colon#22290
nnelluri-cisco wants to merge 2 commits intosonic-net:masterfrom
nnelluri-cisco:fib_utils-fix

Conversation

@nnelluri-cisco
Copy link
Contributor

Description of PR

The FIB parsing code assumed all route keys contain a colon (:) and
attempted to split on it unconditionally:
prefix = k.split(':', 1)[1]

When a key like 'ROUTE_TABLE_DEL_SET' (without colon) is encountered,
split(':') returns a single-element list, causing IndexError when
accessing index [1].

Error:
prefix = k.split(':', 1)[1]
IndexError: list index out of range

Summary:
Added a safety check to verify colon exists before splitting:
if ":" in k:
prefix = k.split(':', 1)[1]
else:
continue

This ensures only properly formatted route keys (containing ':') are
processed, and malformed keys are skipped gracefully.
Fixes # (issue)

Type of change

  • [X ] Bug fix
  • Testbed and Framework(new/improvement)
  • New Test case
    • Skipped for non-supported platforms
  • Test case improvement

Back port request

  • 202205
  • 202305
  • 202311
  • 202405
  • 202411
  • [X ] 202505
  • [ X] 202511

Approach

What is the motivation for this PR?

Fix an IndexError crash in FIB (Forwarding Information Base) route parsing that occurs when processing route table
Error:

prefix = k.split(':', 1)[1]
IndexError: list index out of range

How did you do it?

Added a safety check to verify the presence of a colon before attempting to split route keys:

Before:

prefix = k.split(':', 1)[1]  # Assumes colon always exists

After:

if ":" in k:
    prefix = k.split(':', 1)[1]
else:
    continue  # Skip keys without proper format

This ensures only properly formatted route keys (e.g., ROUTE_TABLE:192.168.0.0/24) are processed, while malformed or special keys are gracefully skipped.

How did you verify/test it?

  1. Reproduced the issue with test_basic_fib
  2. Applied the fix and confirmed test passes
  3. Verified that normal route entries with colons still parse correctly
  4. Tested with various key formats:
    • Standard routes: ROUTE_TABLE:10.0.0.0/24
    • IPv6 routes: ROUTE_TABLE:fc00::fc/126
    • Special keys: ROUTE_TABLE_DEL_SET ✓ (now skipped gracefully)
  5. Ran full test suite to ensure no regressions

Any platform specific information?

Platform dependency: None - this is a generic parsing fix

Supported testbed topology if it's a new test case?

  • Existing topologies: t0, t1, t1-lag

Documentation

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@nnelluri-cisco
Copy link
Contributor Author

@bhavani
Can you please review and approve the PR

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

bpar9
bpar9 previously approved these changes Feb 11, 2026
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@nnelluri-cisco
Copy link
Contributor Author

@prabhataravind @xwjiang-ms
can you please review and merge the PR

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes an IndexError in FIB (Forwarding Information Base) route parsing that occurs when Redis keys without colons (e.g., ROUTE_TABLE_DEL_SET) are encountered. The code previously assumed all route keys contain a colon and attempted to split on it unconditionally, causing an IndexError when accessing the second element of a single-element list.

Changes:

  • Added safety check to verify colon presence before splitting route keys in get_fib_info function
  • Keys without colons are now skipped gracefully using continue statement

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@github-actions github-actions bot requested a review from Ryangwaite February 24, 2026 18:55
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Signed-off-by: nnelluri-cisco <nnelluri@cisco.com>
Signed-off-by: nnelluri <nnelluri@cisco.com>
…t represent route entries

Signed-off-by: nnelluri <nnelluri@cisco.com>
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

kazinator-arista pushed a commit to kazinator-arista/sonic-mgmt that referenced this pull request Mar 4, 2026
…tomatically (sonic-net#22290)

#### Why I did it
src/sonic-linux-kernel
```
* a89afbc - (HEAD -> 202411, origin/202411) [202411] Update to Linux 6.1.123 (sonic-net#459) (4 days ago) [Saikrishna Arcot]
```
#### How I did it
#### How to verify it
#### Description for the changelog
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.

4 participants