Skip to content

cli: fix bash completion and vxlan display bugs#615

Merged
rjarry merged 3 commits into
DPDK:mainfrom
rjarry:cli-fixes
May 20, 2026
Merged

cli: fix bash completion and vxlan display bugs#615
rjarry merged 3 commits into
DPDK:mainfrom
rjarry:cli-fixes

Conversation

@rjarry
Copy link
Copy Markdown
Collaborator

@rjarry rjarry commented May 11, 2026

Fix use-after-free in bash completion mode where bash_complete_node() was taking ownership of the caller's cmdlist node, causing a double free when main() cleans up. Clone the node before passing it to EC_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 calls ec_node_clone(cmdlist) and passes the clone into EC_NODE_SEQ/ec_node_sh_lex_expand; bash_complete() frees the cloned node with ec_node_free(cmdlist). This prevents ownership transfer of the caller's original cmdlist node and eliminates the double-free.

Buffer truncation in completion:

  • bash_complete() copies exactly i bytes from COMP_LINE into buf using memcpy(buf, comp_line, i) and then sets buf[i] = '\0' instead of using gr_strcpy(buf, i, comp_line). This stops copying one character past the requested length and preserves correct next-word completion behavior.

Control-flow on error paths:

  • Validation failures for COMP_LINE/COMP_POINT and COMP_POINT parsing now return immediately with failure (return ret) rather than falling through to the shared cleanup label; the shared cleanup remains responsible for freeing the cloned cmdlist and any allocated completion state.

VXLAN display fix

IPv6-capable local VTEP address formatting:

  • vxlan_show() and vxlan_list_info() switch from IPv4-specific formatting to address-family-aware formatting: they use ADDR_F with ADDR_W(vxlan->local.af) and pass &vxlan->local.addr (instead of IP4_F and vxlan->local). This allows correct rendering of the local VTEP address when the underlay is IPv6.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 11, 2026

📝 Walkthrough

Walkthrough

This PR updates two independent areas. The CLI completion path now clones the command-list node before lex/expansion and changes completion buffer population to memcpy plus explicit null-termination, with some error paths returning early. The VXLAN CLI output now prints the "local" address using address-family-aware macros (ADDR_F/ADDR_W(...)) and passes the specific address field instead of the previous IPv4-only formatting.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0ab251b and 398dff1.

📒 Files selected for processing (2)
  • cli/complete.c
  • modules/l2/cli/vxlan.c

Comment thread cli/complete.c Outdated
Comment on lines +95 to +96
strcpy(buf, comp_line);
buf[i] = '\0';
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

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.

@rjarry rjarry requested a review from maxime-leroy May 20, 2026 08:24
Comment thread cli/complete.c
goto end;
}

gr_strcpy(buf, i, comp_line);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

gr_strcpy(buf, i+1, comp_line) ?

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
cli/complete.c (1)

95-96: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Critical buffer overflow remains in completion-line copy path

Line 95 copies i bytes into buf[BUFSIZ] and Line 96 writes buf[i] without checking i < BUFSIZ. If COMP_LINE is longer than BUFSIZ, this is out-of-bounds write on stack memory.

Suggested minimal fix
-	memcpy(buf, comp_line, i);
-	buf[i] = '\0';
+	if (i >= sizeof(buf)) {
+		errorf("COMP_POINT exceeds completion buffer");
+		return ret;
+	}
+	memcpy(buf, comp_line, (size_t)i);
+	buf[i] = '\0';
#!/bin/bash
# Read-only verification:
# 1) confirm fixed-size stack buffer
# 2) confirm copy/terminator use site
# 3) confirm whether any bound check against sizeof(buf)/BUFSIZ exists before copy

rg -n -C3 'char buf\[BUFSIZ\]|memcpy\(buf,\s*comp_line,\s*i\)|buf\[i\]\s*=\s*'\'\''\\0'\'\''' cli/complete.c
rg -n -C3 'i\s*>=\s*sizeof\(buf\)|i\s*>=\s*BUFSIZ|BUFSIZ' cli/complete.c
🤖 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, The code copies i bytes from comp_line
into a fixed buffer buf[BUFSIZ] with memcpy(buf, comp_line, i) and then writes
buf[i] = '\0' without bounding i; fix by clamping the number of bytes copied to
at most BUFSIZ-1 and writing the terminator within bounds: compute a safe copy
length (e.g., n = (i < BUFSIZ) ? i : BUFSIZ-1), memcpy(buf, comp_line, n) and
set buf[n] = '\0' (or ensure buf[BUFSIZ-1] = '\0' after copying); update the
code paths that use i, memcpy, comp_line, and buf to use this safe length so no
out-of-bounds write occurs.
🤖 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.

Duplicate comments:
In `@cli/complete.c`:
- Around line 95-96: The code copies i bytes from comp_line into a fixed buffer
buf[BUFSIZ] with memcpy(buf, comp_line, i) and then writes buf[i] = '\0' without
bounding i; fix by clamping the number of bytes copied to at most BUFSIZ-1 and
writing the terminator within bounds: compute a safe copy length (e.g., n = (i <
BUFSIZ) ? i : BUFSIZ-1), memcpy(buf, comp_line, n) and set buf[n] = '\0' (or
ensure buf[BUFSIZ-1] = '\0' after copying); update the code paths that use i,
memcpy, comp_line, and buf to use this safe length so no out-of-bounds write
occurs.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 05ecdc8b-bf9a-4c5c-a0c9-48c73ec68b83

📥 Commits

Reviewing files that changed from the base of the PR and between 398dff1 and 86a3cb9.

📒 Files selected for processing (2)
  • cli/complete.c
  • modules/l2/cli/vxlan.c

rjarry added 3 commits May 20, 2026 15:06
The local VTEP address can now be IPv6.

Fixes: 8999062 ("vxlan: add support for IPv6 underlay")
Signed-off-by: Robin Jarry <rjarry@redhat.com>
Reviewed-by: Maxime Leroy <maxime@leroys.fr>
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.

Also use early return instead of goto if there is an error before the
cmdlist node has been cloned.

Fixes: 1e85ea8 ("cli: refactor bash_complete cleanup pattern")
Signed-off-by: Robin Jarry <rjarry@redhat.com>
Reviewed-by: Maxime Leroy <maxime@leroys.fr>
gr_strcpy() does not support partial copy. It truncates one character
past the requested length which breaks next word completion. Use
memcpy() to copy exactly the bytes before the completion point and
manually terminate the buffer.

Fixes: 88c63f8 ("api: replace direct memccpy with gr_strcpy for safe string copy")
Signed-off-by: Robin Jarry <rjarry@redhat.com>
Reviewed-by: Maxime Leroy <maxime@leroys.fr>
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
cli/complete.c (1)

95-96: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Stack buffer overflow: i is unbounded relative to buf[BUFSIZ]

i is validated against strlen(comp_line) (line 90) but not against sizeof(buf). If COMP_LINE exceeds BUFSIZ, both the memcpy and the null-termination write past the end of buf.

Suggested fix
+	if (i >= sizeof(buf)) {
+		errorf("COMP_POINT exceeds completion buffer");
+		return ret;
+	}
 	memcpy(buf, comp_line, 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, The code copies comp_line into buf
using memcpy(buf, comp_line, i) and then sets buf[i] = '\0' but never bounds i
against sizeof(buf) (buf is BUFSIZ), so COMP_LINE can overflow buf; fix by
clamping the copy length to at most sizeof(buf)-1 before the memcpy and use that
clamped length for the terminating NUL. In other words, compute a safe length
(e.g., min(i, sizeof buf - 1)), use that length for the memcpy from comp_line to
buf, and write the NUL at that safe index (use the same clamped variable instead
of i). Ensure variables referenced: buf, comp_line, i, BUFSIZ/sizeof(buf), and
the null-termination are updated accordingly.
🤖 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.

Duplicate comments:
In `@cli/complete.c`:
- Around line 95-96: The code copies comp_line into buf using memcpy(buf,
comp_line, i) and then sets buf[i] = '\0' but never bounds i against sizeof(buf)
(buf is BUFSIZ), so COMP_LINE can overflow buf; fix by clamping the copy length
to at most sizeof(buf)-1 before the memcpy and use that clamped length for the
terminating NUL. In other words, compute a safe length (e.g., min(i, sizeof buf
- 1)), use that length for the memcpy from comp_line to buf, and write the NUL
at that safe index (use the same clamped variable instead of i). Ensure
variables referenced: buf, comp_line, i, BUFSIZ/sizeof(buf), and the
null-termination are updated accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 75bfc21d-7205-490e-ba47-09728bc35451

📥 Commits

Reviewing files that changed from the base of the PR and between 86a3cb9 and 80ea33f.

📒 Files selected for processing (2)
  • cli/complete.c
  • modules/l2/cli/vxlan.c
✅ Files skipped from review due to trivial changes (1)
  • modules/l2/cli/vxlan.c

@rjarry rjarry merged commit ee3b837 into DPDK:main May 20, 2026
6 checks passed
@rjarry rjarry deleted the cli-fixes branch May 20, 2026 15:42
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.

2 participants