Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed crash in kubectl cp when path has multiple leading slashes #58144

Merged
merged 1 commit into from
Jan 23, 2018

Conversation

tomerf
Copy link
Contributor

@tomerf tomerf commented Jan 11, 2018

What this PR does / why we need it: Fixed crash in kubectl cp when path has multiple leading slashes
For example:

$ kubectl cp pod://path/to/somewhere localfile
tar: Removing leading `//' from member names
panic: runtime error: slice bounds out of range

goroutine 1 [running]:
k8s.io/kubernetes/pkg/kubectl/cmd.untarAll(0x363e840, 0xc420198120, 0x7fff5fbffc13, 0x1, 0x7fff5fbffbfa, 0x18, 0x0, 0x0)
	/go/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes/pkg/kubectl/cmd/cp.go:329 +0x7b4
k8s.io/kubernetes/pkg/kubectl/cmd.copyFromPod(0x3671940, 0xc420261dd0, 0xc4202f9200, 0x3644480, 0xc42000c020, 0x0, 0x0, 0x7fff5fbffbed, 0xb, 0x7fff5fbffbf9, ...)
	/go/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes/pkg/kubectl/cmd/cp.go:237 +0x375
k8s.io/kubernetes/pkg/kubectl/cmd.runCopy(0x3671940, 0xc420261dd0, 0xc4202f9200, 0x3644480, 0xc42000c018, 0x3644480, 0xc42000c020, 0xc4203490a0, 0x2, 0x2, ...)
	/go/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes/pkg/kubectl/cmd/cp.go:134 +0x35b
k8s.io/kubernetes/pkg/kubectl/cmd.NewCmdCp.func1(0xc4202f9200, 0xc4203490a0, 0x2, 0x2)
	/go/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes/pkg/kubectl/cmd/cp.go:72 +0x89
k8s.io/kubernetes/vendor/github.com/spf13/cobra.(*Command).execute(0xc4202f9200, 0xc420348ee0, 0x2, 0x2, 0xc4202f9200, 0xc420348ee0)
	/go/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes/vendor/github.com/spf13/cobra/command.go:603 +0x234
k8s.io/kubernetes/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0xc42038d440, 0x8000104, 0x0, 0xffffffffffffffff)
	/go/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes/vendor/github.com/spf13/cobra/command.go:689 +0x2fe
k8s.io/kubernetes/vendor/github.com/spf13/cobra.(*Command).Execute(0xc42038d440, 0xc420261dd0, 0x3644440)
	/go/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes/vendor/github.com/spf13/cobra/command.go:648 +0x2b
k8s.io/kubernetes/cmd/kubectl/app.Run(0x0, 0x0)
	/go/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes/cmd/kubectl/app/kubectl.go:41 +0xd5
main.main()
	/go/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes/cmd/kubectl/kubectl.go:27 +0x26

Which issue(s) this PR fixes None

Special notes for your reviewer: None

Release note:

Fixed crash in kubectl cp when path has multiple leading slashes

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jan 11, 2018
@tomerf
Copy link
Contributor Author

tomerf commented Jan 11, 2018

/assign @smarterclayton

@jianglingxia
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jan 11, 2018
@tomerf
Copy link
Contributor Author

tomerf commented Jan 11, 2018

/retest

@dixudx
Copy link
Member

dixudx commented Jan 11, 2018

/lgtm
/retest

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 11, 2018
@tomerf
Copy link
Contributor Author

tomerf commented Jan 15, 2018

@rootfs @sttts Approve?

}
return file
// tar strips the leading '/' if it's there, so we will too
return strings.TrimLeft(file, "/")
Copy link
Contributor

Choose a reason for hiding this comment

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

isn't there a "clean" func in os/path ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, and it is used after calling this function (https://github.com/tomerf/kubernetes/blob/52f02c42e6a84a551b0f7eade38be62dd6c37cf2/pkg/kubectl/cmd/cp.go#L236).
But it only make the path canonical, it doesn't remove prefix slash.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sttts Is that okay?

@sttts
Copy link
Contributor

sttts commented Jan 17, 2018

/lgtm
/assign @pwittrock

@tomerf
Copy link
Contributor Author

tomerf commented Jan 22, 2018

@pwittrock Approve?

@pwittrock
Copy link
Member

/approve

@pwittrock
Copy link
Member

/approve no-issue

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dixudx, pwittrock, sttts, tomerf

Associated issue requirement bypassed by: pwittrock

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

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 22, 2018
@tomerf
Copy link
Contributor Author

tomerf commented Jan 22, 2018

What else is needed for merge?

@dixudx
Copy link
Member

dixudx commented Jan 23, 2018

/retest

@k8s-github-robot
Copy link

/test all

Tests are more than 96 hours old. Re-running tests.

@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 58144, 57149). If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-github-robot k8s-github-robot merged commit 2a04c09 into kubernetes:master Jan 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants