mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
remove extra "../" when copying from pod to local
This commit is contained in:
parent
8ad67d3437
commit
dca6912c54
@ -287,9 +287,22 @@ func (o *CopyOptions) copyFromPod(src, dest fileSpec) error {
|
|||||||
}()
|
}()
|
||||||
prefix := getPrefix(src.File)
|
prefix := getPrefix(src.File)
|
||||||
prefix = path.Clean(prefix)
|
prefix = path.Clean(prefix)
|
||||||
|
// remove extraneous path shortcuts - these could occur if a path contained extra "../"
|
||||||
|
// and attempted to navigate beyond "/" in a remote filesystem
|
||||||
|
prefix = stripPathShortcuts(prefix)
|
||||||
return untarAll(reader, dest.File, prefix)
|
return untarAll(reader, dest.File, prefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// stripPathShortcuts removes any leading or trailing "../" from a given path
|
||||||
|
func stripPathShortcuts(p string) string {
|
||||||
|
newPath := path.Clean(p)
|
||||||
|
if len(newPath) > 0 && string(newPath[0]) == "/" {
|
||||||
|
return newPath[1:]
|
||||||
|
}
|
||||||
|
|
||||||
|
return newPath
|
||||||
|
}
|
||||||
|
|
||||||
func makeTar(srcPath, destPath string, writer io.Writer) error {
|
func makeTar(srcPath, destPath string, writer io.Writer) error {
|
||||||
// TODO: use compression here?
|
// TODO: use compression here?
|
||||||
tarWriter := tar.NewWriter(writer)
|
tarWriter := tar.NewWriter(writer)
|
||||||
|
Loading…
Reference in New Issue
Block a user