Merge pull request #21600 from Microsoft/jstarks/escape_entrypoint

Windows: escape entrypoint before passing to libcontainerd
This commit is contained in:
Brian Goff 2016-03-30 18:00:32 -07:00
commit 81d9eaa27e
3 changed files with 14 additions and 25 deletions

View File

@ -8,7 +8,6 @@ import (
func execSetPlatformOpt(c *container.Container, ec *exec.Config, p *libcontainerd.Process) error { func execSetPlatformOpt(c *container.Container, ec *exec.Config, p *libcontainerd.Process) error {
// Process arguments need to be escaped before sending to OCI. // Process arguments need to be escaped before sending to OCI.
// TODO (jstarks): escape the entrypoint too once the tests are fixed to not rely on this behavior p.Args = escapeArgs(p.Args)
p.Args = append([]string{p.Args[0]}, escapeArgs(p.Args[1:])...)
return nil return nil
} }

View File

@ -63,11 +63,9 @@ func (daemon *Daemon) createSpec(c *container.Container) (*libcontainerd.Spec, e
} }
// In s.Process // In s.Process
if c.Config.ArgsEscaped { s.Process.Args = append([]string{c.Path}, c.Args...)
s.Process.Args = append([]string{c.Path}, c.Args...) if !c.Config.ArgsEscaped {
} else { s.Process.Args = escapeArgs(s.Process.Args)
// TODO (jstarks): escape the entrypoint too once the tests are fixed to not rely on this behavior
s.Process.Args = append([]string{c.Path}, escapeArgs(c.Args)...)
} }
s.Process.Cwd = c.Config.WorkingDir s.Process.Cwd = c.Config.WorkingDir
s.Process.Env = c.CreateDaemonEnvironment(linkedEnv) s.Process.Env = c.CreateDaemonEnvironment(linkedEnv)

View File

@ -331,7 +331,7 @@ func (s *DockerSuite) TestRunWithVolumesFromExited(c *check.C) {
// Create a file in a volume // Create a file in a volume
if daemonPlatform == "windows" { if daemonPlatform == "windows" {
out, exitCode = dockerCmd(c, "run", "--name", "test-data", "--volume", `c:\some\dir`, WindowsBaseImage, `cmd /c echo hello > c:\some\dir\file`) out, exitCode = dockerCmd(c, "run", "--name", "test-data", "--volume", `c:\some\dir`, WindowsBaseImage, "cmd", "/c", `echo hello > c:\some\dir\file`)
} else { } else {
out, exitCode = dockerCmd(c, "run", "--name", "test-data", "--volume", "/some/dir", "busybox", "touch", "/some/dir/file") out, exitCode = dockerCmd(c, "run", "--name", "test-data", "--volume", "/some/dir", "busybox", "touch", "/some/dir/file")
} }
@ -341,7 +341,7 @@ func (s *DockerSuite) TestRunWithVolumesFromExited(c *check.C) {
// Read the file from another container using --volumes-from to access the volume in the second container // Read the file from another container using --volumes-from to access the volume in the second container
if daemonPlatform == "windows" { if daemonPlatform == "windows" {
out, exitCode = dockerCmd(c, "run", "--volumes-from", "test-data", WindowsBaseImage, `cmd /c type c:\some\dir\file`) out, exitCode = dockerCmd(c, "run", "--volumes-from", "test-data", WindowsBaseImage, "cmd", "/c", `type c:\some\dir\file`)
} else { } else {
out, exitCode = dockerCmd(c, "run", "--volumes-from", "test-data", "busybox", "cat", "/some/dir/file") out, exitCode = dockerCmd(c, "run", "--volumes-from", "test-data", "busybox", "cat", "/some/dir/file")
} }
@ -1901,15 +1901,8 @@ func (s *DockerSuite) TestRunWithBadDevice(c *check.C) {
func (s *DockerSuite) TestRunEntrypoint(c *check.C) { func (s *DockerSuite) TestRunEntrypoint(c *check.C) {
name := "entrypoint" name := "entrypoint"
// Note Windows does not have an echo.exe built in. out, _ := dockerCmd(c, "run", "--name", name, "--entrypoint", "echo", "busybox", "-n", "foobar")
var out, expected string expected := "foobar"
if daemonPlatform == "windows" {
out, _ = dockerCmd(c, "run", "--name", name, "--entrypoint", "cmd /s /c echo", "busybox", "foobar")
expected = "foobar\r\n"
} else {
out, _ = dockerCmd(c, "run", "--name", name, "--entrypoint", "/bin/echo", "busybox", "-n", "foobar")
expected = "foobar"
}
if out != expected { if out != expected {
c.Fatalf("Output should be %q, actual out: %q", expected, out) c.Fatalf("Output should be %q, actual out: %q", expected, out)
@ -2623,18 +2616,17 @@ func (s *DockerSuite) TestRunTTYWithPipe(c *check.C) {
func (s *DockerSuite) TestRunNonLocalMacAddress(c *check.C) { func (s *DockerSuite) TestRunNonLocalMacAddress(c *check.C) {
addr := "00:16:3E:08:00:50" addr := "00:16:3E:08:00:50"
cmd := "ifconfig" args := []string{"run", "--mac-address", addr}
image := "busybox"
expected := addr expected := addr
if daemonPlatform == "windows" { if daemonPlatform != "windows" {
cmd = "ipconfig /all" args = append(args, "busybox", "ifconfig")
image = WindowsBaseImage } else {
args = append(args, WindowsBaseImage, "ipconfig", "/all")
expected = strings.Replace(strings.ToUpper(addr), ":", "-", -1) expected = strings.Replace(strings.ToUpper(addr), ":", "-", -1)
} }
if out, _ := dockerCmd(c, "run", "--mac-address", addr, image, cmd); !strings.Contains(out, expected) { if out, _ := dockerCmd(c, args...); !strings.Contains(out, expected) {
c.Fatalf("Output should have contained %q: %s", expected, out) c.Fatalf("Output should have contained %q: %s", expected, out)
} }
} }