Skip to content

Comments

etcdctl: fix slice bounds trimming single-quoted args#21307

Open
huajianxiaowanzi wants to merge 3 commits intoetcd-io:mainfrom
huajianxiaowanzi:fix/etcdctl-argify-slice-bounds
Open

etcdctl: fix slice bounds trimming single-quoted args#21307
huajianxiaowanzi wants to merge 3 commits intoetcd-io:mainfrom
huajianxiaowanzi:fix/etcdctl-argify-slice-bounds

Conversation

@huajianxiaowanzi
Copy link
Contributor

@huajianxiaowanzi huajianxiaowanzi commented Feb 13, 2026

The logic for handling single quotes erroneously used len(args) (the length of the entire slice) instead of len(args[i]) (the length of the current string). This leads to incorrect slicing logic or potential index-out-of-bounds panics.

Copilot AI review requested due to automatic review settings February 13, 2026 09:24
@k8s-ci-robot
Copy link

Hi @huajianxiaowanzi. Thanks for your PR.

I'm waiting for a etcd-io member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes an indexing bug in etcdctl argument parsing where trimming single-quoted arguments used the number of parsed args (len(args)) instead of the length of the specific argument string (len(args[i])), which could cause slice-bounds panics.

Changes:

  • Correct single-quote trimming logic in Argify to slice based on the current token length.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: huajianxiaowanzi <1695316070@qq.com>
@huajianxiaowanzi huajianxiaowanzi force-pushed the fix/etcdctl-argify-slice-bounds branch from aad1a0b to 5598893 Compare February 13, 2026 09:30
if args[i][0] == '\'' {
// 'single-quoted string'
args[i] = args[i][1 : len(args)-1]
args[i] = args[i][1 : len(args[i])-1]
Copy link
Member

Choose a reason for hiding this comment

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

Good catch.

Can you please add an unit test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unit test have been added.

Could you please take a look?

Signed-off-by: huajianxiaowanzi <1695316070@qq.com>
@ahrtr
Copy link
Member

ahrtr commented Feb 13, 2026

/ok-to-test

@codecov
Copy link

codecov bot commented Feb 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.44%. Comparing base (405a607) to head (d1d507e).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
Files with missing lines Coverage Δ
etcdctl/ctlv3/command/util.go 7.29% <100.00%> (+7.29%) ⬆️

... and 21 files with indirect coverage changes

@@            Coverage Diff             @@
##             main   #21307      +/-   ##
==========================================
+ Coverage   68.37%   68.44%   +0.06%     
==========================================
  Files         428      428              
  Lines       35262    35262              
==========================================
+ Hits        24110    24134      +24     
+ Misses       9751     9728      -23     
+ Partials     1401     1400       -1     

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 405a607...d1d507e. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: huajianxiaowanzi <1695316070@qq.com>
@huajianxiaowanzi
Copy link
Contributor Author

/retest

@k8s-ci-robot
Copy link

@huajianxiaowanzi: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-etcd-integration-1-cpu-amd64 d1d507e link true /test pull-etcd-integration-1-cpu-amd64

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@ahrtr
Copy link
Member

ahrtr commented Feb 13, 2026

The failure has nothing to do with this PR.

It's a known issue #21298

Copy link
Member

@ahrtr ahrtr left a comment

Choose a reason for hiding this comment

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

LGTM

Thanks

@k8s-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ahrtr, huajianxiaowanzi

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants