Coverity cleanup some more items found - #21627
Conversation
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>
Greptile SummaryThis PR cleans up Coverity static analysis warnings across three files: removes dead Confidence Score: 5/5Safe 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
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"]
Reviews (1): Last reviewed commit: "bgpd: Let the stream track how much was ..." | Re-trigger Greptile |
No description provided.