Skip to content

Commit

Permalink
Merge pull request #120132 from ritazh/cherry-pick-cve-2023-3676-1.25
Browse files Browse the repository at this point in the history
Cherry pick of #120127 Use env variables for passing path and subpath to Powershell
  • Loading branch information
k8s-ci-robot committed Aug 23, 2023
2 parents c16b8f4 + ae50193 commit 073f9ea
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions pkg/volume/util/subpath/subpath_windows.go
Expand Up @@ -76,8 +76,10 @@ func getUpperPath(path string) string {
// Check whether a directory/file is a link type or not
// LinkType could be SymbolicLink, Junction, or HardLink
func isLinkPath(path string) (bool, error) {
cmd := fmt.Sprintf("(Get-Item -LiteralPath %q).LinkType", path)
output, err := exec.Command("powershell", "/c", cmd).CombinedOutput()
cmd := exec.Command("powershell", "/c", "$ErrorActionPreference = 'Stop'; (Get-Item -Force -LiteralPath $env:linkpath).LinkType")
cmd.Env = append(os.Environ(), fmt.Sprintf("linkpath=%s", path))
klog.V(8).Infof("Executing command: %q", cmd.String())
output, err := cmd.CombinedOutput()
if err != nil {
return false, err
}
Expand Down Expand Up @@ -114,8 +116,11 @@ func evalSymlink(path string) (string, error) {
}
}
// This command will give the target path of a given symlink
cmd := fmt.Sprintf("(Get-Item -LiteralPath %q).Target", upperpath)
output, err := exec.Command("powershell", "/c", cmd).CombinedOutput()
// The -Force parameter will allow Get-Item to also evaluate hidden folders, like AppData.
cmd := exec.Command("powershell", "/c", "$ErrorActionPreference = 'Stop'; (Get-Item -Force -LiteralPath $env:linkpath).Target")
cmd.Env = append(os.Environ(), fmt.Sprintf("linkpath=%s", upperpath))
klog.V(8).Infof("Executing command: %q", cmd.String())
output, err := cmd.CombinedOutput()
if err != nil {
return "", err
}
Expand Down

0 comments on commit 073f9ea

Please sign in to comment.