bgpd: Verify if we correctly parsed BGP-LS attribute#21344
Merged
cscarpitta merged 1 commit intoFRRouting:masterfrom Mar 26, 2026
Merged
bgpd: Verify if we correctly parsed BGP-LS attribute#21344cscarpitta merged 1 commit intoFRRouting:masterfrom
cscarpitta merged 1 commit intoFRRouting:masterfrom
Conversation
The loop condition while (stream_get_getp(s) < end_pos) does not catch overshooting. If a sub-parser (e.g. parse_prefix_sid) reads length bytes but length was crafted to extend past end_pos, the stream pointer ends up beyond end_pos. The < condition then terminates the loop normally, and return 0 follows success, with the stream pointer at the wrong offset. Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
Greptile SummaryThis PR adds a post-loop bounds check to
Confidence Score: 5/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["bgp_ls_parse_attr(s, total_length, attr)"] --> B["end_pos = getp + total_length"]
B --> C{getp < end_pos?}
C -->|yes| D["stream_get_tlv_hdr → type, length"]
D -->|error| E["return -1"]
D -->|ok| F["Dispatch on type\n(parse_* sub-functions)"]
F -->|error| E
F -->|ok| C
C -->|no – loop exits| G{getp == end_pos?}
G -->|yes| H["return 0 ✓"]
G -->|no – NEW CHECK| I["flog_warn: Attribute length mismatch\nreturn -1"]
H --> J["Caller in bgp_attr.c\nchecks ret != 0 → BGP_ATTR_PARSE_ERROR"]
I --> J
Reviews (1): Last reviewed commit: "bgpd: Verify if we correctly parsed BGP-..." | Re-trigger Greptile |
cscarpitta
approved these changes
Mar 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.