Avoid resolving dotted segments when host path for volume is named pipe

This commit is contained in:
bckr
2020-03-03 14:00:19 +01:00
parent e70221216d
commit 2a2bb0430e
4 changed files with 23 additions and 2 deletions

View File

@@ -636,7 +636,7 @@ func (d *Driver) containerBinds(task *drivers.TaskConfig, driverConfig *TaskConf
// Otherwise, we assume we receive a relative path binding in the format
// relative/to/task:/also/in/container
if taskLocalBindVolume {
src = expandPath(task.TaskDir().Dir, src)
src = expandPath(task.TaskDir().Dir, src, runtime.GOOS)
} else {
// Resolve dotted path segments
src = filepath.Clean(src)

View File

@@ -6,6 +6,7 @@ import (
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"
"github.com/docker/cli/cli/config/configfile"
@@ -206,6 +207,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 os == "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

@@ -4,6 +4,7 @@ package docker
import (
"path/filepath"
"runtime"
"testing"
"github.com/stretchr/testify/require"
@@ -57,7 +58,7 @@ func TestExpandPath(t *testing.T) {
for _, c := range cases {
t.Run(c.expected, func(t *testing.T) {
require.Equal(t, c.expected, filepath.ToSlash(expandPath(c.base, c.target)))
require.Equal(t, c.expected, filepath.ToSlash(expandPath(c.base, c.target, runtime.GOOS)))
})
}
}

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 {