Merge pull request #7257 from bbckr/avoid-resolving-dot-in-named-pipe

Avoid resolving dotted segments when host path for volume is named pipe
This commit is contained in:
Mahmood Ali
2020-03-26 16:59:29 -04:00
committed by GitHub
2 changed files with 21 additions and 0 deletions

View File

@@ -6,6 +6,8 @@ import (
"os"
"os/exec"
"path/filepath"
"regexp"
"runtime"
"strings"
"github.com/docker/cli/cli/config/configfile"
@@ -206,6 +208,16 @@ func validateCgroupPermission(s string) bool {
// expandPath returns the absolute path of dir, relative to base if dir is relative path.
// base is expected to be an absolute path
func expandPath(base, dir string) string {
if runtime.GOOS == "windows" {
pipeExp := regexp.MustCompile(`^` + rxPipe + `$`)
match := pipeExp.FindStringSubmatch(strings.ToLower(dir))
if len(match) == 1 {
// avoid resolving dot-segment in named pipe
return dir
}
}
if filepath.IsAbs(dir) {
return filepath.Clean(dir)
}

View File

@@ -24,6 +24,8 @@ func TestExpandPath(t *testing.T) {
{"/tmp/alloc/task", "c:/home/user", "c:/home/user"},
{"/tmp/alloc/task", "c:/home/user/..", "c:/home"},
{"/tmp/alloc/task", `//./pipe/named_pipe`, `//./pipe/named_pipe`},
}
for _, c := range cases {
@@ -55,6 +57,13 @@ func TestParseVolumeSpec_Windows(t *testing.T) {
`e:\containerpath`,
"",
},
{
"named pipe",
`//./pipe/named_pipe://./pipe/named_pipe`,
`\\.\pipe\named_pipe`,
`//./pipe/named_pipe`,
"",
},
}
for _, c := range validCases {