Signed-off-by: John Howard <jhoward@microsoft.com>
| ... | ... |
@@ -407,6 +407,8 @@ func cmd(b *Builder, args []string, attributes map[string]bool, original string) |
| 407 | 407 |
} |
| 408 | 408 |
|
| 409 | 409 |
b.runConfig.Cmd = strslice.StrSlice(cmdSlice) |
| 410 |
+ // set config as already being escaped, this prevents double escaping on windows |
|
| 411 |
+ b.runConfig.ArgsEscaped = true |
|
| 410 | 412 |
|
| 411 | 413 |
if err := b.commit("", b.runConfig.Cmd, fmt.Sprintf("CMD %q", cmdSlice)); err != nil {
|
| 412 | 414 |
return err |
| ... | ... |
@@ -74,6 +74,7 @@ func merge(userConf, imageConf *containertypes.Config) error {
|
| 74 | 74 |
if len(userConf.Entrypoint) == 0 {
|
| 75 | 75 |
if len(userConf.Cmd) == 0 {
|
| 76 | 76 |
userConf.Cmd = imageConf.Cmd |
| 77 |
+ userConf.ArgsEscaped = imageConf.ArgsEscaped |
|
| 77 | 78 |
} |
| 78 | 79 |
|
| 79 | 80 |
if userConf.Entrypoint == nil {
|
| ... | ... |
@@ -6952,3 +6952,28 @@ func (s *DockerSuite) TestBuildShellWindowsPowershell(c *check.C) {
|
| 6952 | 6952 |
c.Fatalf("Line with 'John' not found in output %q", out)
|
| 6953 | 6953 |
} |
| 6954 | 6954 |
} |
| 6955 |
+ |
|
| 6956 |
+// #22868. Make sure shell-form CMD is marked as escaped in the config of the image |
|
| 6957 |
+func (s *DockerSuite) TestBuildCmdShellArgsEscaped(c *check.C) {
|
|
| 6958 |
+ testRequires(c, DaemonIsWindows) |
|
| 6959 |
+ name := "testbuildcmdshellescaped" |
|
| 6960 |
+ |
|
| 6961 |
+ _, err := buildImage(name, ` |
|
| 6962 |
+ FROM `+minimalBaseImage()+` |
|
| 6963 |
+ CMD "tasklist" |
|
| 6964 |
+ `, true) |
|
| 6965 |
+ if err != nil {
|
|
| 6966 |
+ c.Fatal(err) |
|
| 6967 |
+ } |
|
| 6968 |
+ res := inspectFieldJSON(c, name, "Config.ArgsEscaped") |
|
| 6969 |
+ if res != "true" {
|
|
| 6970 |
+ c.Fatalf("CMD did not update Config.ArgsEscaped on image: %v", res)
|
|
| 6971 |
+ } |
|
| 6972 |
+ dockerCmd(c, "run", "--name", "inspectme", name) |
|
| 6973 |
+ dockerCmd(c, "wait", "inspectme") |
|
| 6974 |
+ res = inspectFieldJSON(c, name, "Config.Cmd") |
|
| 6975 |
+ |
|
| 6976 |
+ if res != `["cmd","/S","/C","\"tasklist\""]` {
|
|
| 6977 |
+ c.Fatalf("CMD was not escaped Config.Cmd: got %v", res)
|
|
| 6978 |
+ } |
|
| 6979 |
+} |