mirror of
https://github.com/kemko/nomad.git
synced 2026-01-10 04:15:41 +03:00
Avoid resolving dotted segments when host path for volume is named pipe
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user