Skip to content

Coverity cleanup some more items found - #21627

Merged
cscarpitta merged 3 commits into
FRRouting:masterfrom
donaldsharp:coverity_cleanup_some_more_more_more
Apr 18, 2026
Merged

Coverity cleanup some more items found#21627
cscarpitta merged 3 commits into
FRRouting:masterfrom
donaldsharp:coverity_cleanup_some_more_more_more

Conversation

@donaldsharp

Copy link
Copy Markdown
Member

No description provided.

Coverity was, rightly, complaining about a formatting type
that was not correct across all platforms.  Fix.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
The test for json_flags and the removal is not needed.  There is
no code path where it is ever set at this point, so remove.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
Coverity is complaining about this:

** CID 1670454:         Insecure data handling  (INTEGER_OVERFLOW)
/bgpd/bgp_ls_nlri.c: 1946             in bgp_ls_encode_link_nlri()
1940     	/* Link Descriptors */
1941     	ret = bgp_ls_encode_link_descriptor(s, &nlri->link_desc);
1942     	if (ret < 0)
1943     		return -1;
1944     	written += ret;
1945
>>>     CID 1670454:         Insecure data handling  (INTEGER_OVERFLOW)
>>>     "written", which might have overflowed, is returned from the function.
1946     	return written;
1947     }
1948
1949     /*
1950      * Encode Prefix NLRI to wire format (RFC 9552 Section 5.2)
1951      *

two things:

a) Every place that encodes data is ensuring that the data being
written already fits in the stream.
b) The stream is the source of truth, for how much data is there.

So instead of having to add up written all across the file, ask
the stream where it is and then just do a simple subtraction
at the function return to write how much was written.  This
greatly simplifies the code and removes the coverity issue.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
@frrbot frrbot Bot added bgp mgmt FRR Management Infra labels Apr 17, 2026
@donaldsharp donaldsharp changed the title Coverity cleanup some more more more Coverity cleanup some more items found Apr 17, 2026
@greptile-apps

greptile-apps Bot commented Apr 17, 2026

Copy link
Copy Markdown

Greptile Summary

This PR cleans up Coverity static analysis warnings across three files: removes dead json_flags cleanup code in bgp_evpn_vty.c (the variable is only allocated in the if (add_prefix_to_json) branch, making the else-branch free unreachable), refactors BGP-LS NLRI encoding functions in bgp_ls_nlri.c to track written bytes via stream position delta (stream_get_endp(s) - start) instead of an accumulated written counter, and fixes non-standard %Lx/%Lu format specifiers to portable PRIx64/PRIu64 in mgmt_vty_frontend.c.

Confidence Score: 5/5

Safe to merge β€” all three changes are correct Coverity cleanups with no functional regressions

The bgp_evpn_vty.c change correctly removes dead code (json_flags is only allocated where add_prefix_to_json is true, so the else-branch free was unreachable). The bgp_ls_nlri.c refactor to stream position delta is functionally equivalent to the old accumulated counter. The mgmt_vty_frontend.c format-specifier fix is a correctness improvement. No P0/P1 issues found.

No files require special attention

Important Files Changed

Filename Overview
bgpd/bgp_evpn_vty.c Removes dead json_flags free/null code in the else branch β€” json_flags is only ever allocated in the if (add_prefix_to_json) branch, so it is always NULL when the else branch is reached
bgpd/bgp_ls_nlri.c Replaces accumulated written counter with stream_get_endp(s) - start for return values across all encode functions; functionally equivalent and cleaner; minor implicit size_t to int narrowing on return is benign given BGP message size bounds
mgmtd/mgmt_vty_frontend.c Replaces non-standard %Lx/%Lu format specifiers with portable PRIx64/PRIu64 β€” correct fix for 64-bit integer formatting

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["bgp_ls_encode_nlri(s, nlri)"] --> B{Validate nlri}
    B -- invalid --> ERR[return -1]
    B -- valid --> C["start = stream_get_endp(s)"]
    C --> D["Write NLRI type + length placeholder"]
    D --> E["value_start = stream_get_endp(s)"]
    E --> F{nlri_type switch}
    F -- NODE --> G["bgp_ls_encode_node_nlri()"]
    F -- LINK --> H["bgp_ls_encode_link_nlri()"]
    F -- IPV4/IPV6_PREFIX --> I["bgp_ls_encode_prefix_nlri()"]
    F -- RESERVED --> ERR
    G & H & I -- ret < 0 --> ERR
    G & H & I -- ret >= 0 --> J["stream_putw_at(s, len_pos, endp - value_start)"]
    J --> K["return stream_get_endp(s) - start"]
Loading

Reviews (1): Last reviewed commit: "bgpd: Let the stream track how much was ..." | Re-trigger Greptile

@cscarpitta
cscarpitta merged commit 68d6821 into FRRouting:master Apr 18, 2026
25 checks passed
@donaldsharp
donaldsharp deleted the coverity_cleanup_some_more_more_more branch April 29, 2026 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bgp master mgmt FRR Management Infra size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants