cli: fix bash completion and vxlan display bugs#615
Conversation
The local VTEP address can now be IPv6. Fixes: 8999062 ("vxlan: add support for IPv6 underlay") Signed-off-by: Robin Jarry <rjarry@redhat.com>
bash_complete() frees the cmdlist node tree, but main() also frees it in its cleanup path. This became a problem when the early return was replaced with goto end. Clone the provided node before using it to construct the bash_complete_node. Fixes: 1e85ea8 ("cli: refactor bash_complete cleanup pattern") Signed-off-by: Robin Jarry <rjarry@redhat.com>
gr_strcpy() does not support partial copy. It truncates one character past the requested length which breaks next word completion. Use strcpy() and manually terminate the buffer at the completion point. Fixes: 88c63f8 ("api: replace direct memccpy with gr_strcpy for safe string copy") Signed-off-by: Robin Jarry <rjarry@redhat.com>
📝 WalkthroughWalkthroughThis PR modifies two independent subsystems. The CLI completion system now clones command nodes before processing them through the lex-expansion pipeline and adjusts how the completion buffer is populated from the input line. The VXLAN module switches from IPv4-specific output formatting to address-family-aware formatting in both the show and list-info display functions, allowing support for multiple address families in local address output. Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cli/complete.c`:
- Around line 95-96: Replace the unbounded strcpy call that copies COMP_LINE
into buf (buf, comp_line) with a bounded copy that respects BUFSIZ: compute or
check the length of comp_line and use a size-limited API (e.g., strncpy/strlcpy
or snprintf) to copy at most BUFSIZ-1 bytes and then explicitly null-terminate
buf; ensure the existing truncation logic that sets buf[i] = '\0' still cannot
write out of bounds by using the actual buffer capacity (BUFSIZ) instead of an
unchecked index i. This change should touch the code around the strcpy(buf,
comp_line) site and preserve intended truncation while eliminating the stack
overflow risk from unbounded input.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 74ee11d5-14bb-4bc9-a0fe-147459a93c5f
📒 Files selected for processing (2)
cli/complete.cmodules/l2/cli/vxlan.c
| strcpy(buf, comp_line); | ||
| buf[i] = '\0'; |
There was a problem hiding this comment.
Unbounded strcpy introduces stack overflow risk
Line 95 copies untrusted COMP_LINE into buf[BUFSIZ] without a size check. A long completion line can overflow the stack before Line 96 truncates it.
Suggested fix
- strcpy(buf, comp_line);
- buf[i] = '\0';
+ if (i >= sizeof(buf)) {
+ errorf("COMP_POINT exceeds completion buffer");
+ goto end;
+ }
+ memcpy(buf, comp_line, (size_t)i);
+ buf[i] = '\0';🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@cli/complete.c` around lines 95 - 96, Replace the unbounded strcpy call that
copies COMP_LINE into buf (buf, comp_line) with a bounded copy that respects
BUFSIZ: compute or check the length of comp_line and use a size-limited API
(e.g., strncpy/strlcpy or snprintf) to copy at most BUFSIZ-1 bytes and then
explicitly null-terminate buf; ensure the existing truncation logic that sets
buf[i] = '\0' still cannot write out of bounds by using the actual buffer
capacity (BUFSIZ) instead of an unchecked index i. This change should touch the
code around the strcpy(buf, comp_line) site and preserve intended truncation
while eliminating the stack overflow risk from unbounded input.
Fix use-after-free in bash completion mode where
bash_complete_node()was taking ownership of the caller'scmdlistnode, causing a double free whenmain()cleans up. Clone the node before passing it toEC_NODE_SEQ.Also fix a truncation issue in bash completion where
gr_strcpy()was cutting one character past the requested length, and fix the VXLAN local VTEP address display to handle IPv6 underlay.CLI bash completion fixes
Use-after-free in completion node handling:
bash_complete_node()now clones the providedcmdlistparameter usingec_node_clone(cmdlist)before passing it toEC_NODE_SEQ(). Previously, the function took ownership of the caller's node, causing a double-free when the main function later cleaned up the same reference. This aligns with the pattern already used incli/dump.candcli/interact.c.Buffer truncation in completion: The
bash_complete()function replaced thegr_strcpy(buf, i, comp_line)call withstrcpy(buf, comp_line)followed by manual null-termination atbuf[i]. Thegr_strcpy()function was copying one character past the requested length, corrupting the buffer and breaking next-word completion.VXLAN display fix
IPv6 underlay support for local VTEP address: The
vxlan_show()andvxlan_list_info()functions updated to use address-family-aware formatting macros. Both now useADDR_F(generic address format"%*p") withADDR_W(vxlan->local.af)(width parameterized by address family: 4 for IPv4, 6 for IPv6) and passvxlan->local.addrinstead of the previous IPv4-onlyIP4_F(format"%4p") withvxlan->local. This enables display of both IPv4 and IPv6 local VTEP addresses.