diff --git a/pkg/kubectl/cmd/cp/cp.go b/pkg/kubectl/cmd/cp/cp.go index 2679c6f7af..02612e0671 100644 --- a/pkg/kubectl/cmd/cp/cp.go +++ b/pkg/kubectl/cmd/cp/cp.go @@ -413,12 +413,6 @@ func recursiveTar(srcBase, srcFile, destBase, destFile string, tw *tar.Writer) e return nil } -// clean prevents path traversals by stripping them out. -// This is adapted from https://golang.org/src/net/http/fs.go#L74 -func clean(fileName string) string { - return path.Clean(string(os.PathSeparator) + fileName) -} - func (o *CopyOptions) untarAll(reader io.Reader, destDir, prefix string) error { // TODO: use compression here? tarReader := tar.NewReader(reader) diff --git a/pkg/kubectl/cmd/cp/cp_test.go b/pkg/kubectl/cmd/cp/cp_test.go index c7d75573d0..d648d82602 100644 --- a/pkg/kubectl/cmd/cp/cp_test.go +++ b/pkg/kubectl/cmd/cp/cp_test.go @@ -551,6 +551,12 @@ func TestBadTar(t *testing.T) { } } +// clean prevents path traversals by stripping them out. +// This is adapted from https://golang.org/src/net/http/fs.go#L74 +func clean(fileName string) string { + return path.Clean(string(os.PathSeparator) + fileName) +} + func TestClean(t *testing.T) { tests := []struct { input string