Skip to content

Commit 45dc57f

Browse files
committed
Check the content type is json when calling exec start.
Signed-off-by: David Calavera <david.calavera@gmail.com>
1 parent 841205e commit 45dc57f

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

api/client/exec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (cli *DockerCli) CmdExec(args ...string) error {
9292
}
9393
}
9494
errCh = promise.Go(func() error {
95-
return cli.hijack("POST", "/exec/"+execID+"/start", execConfig.Tty, in, out, stderr, hijacked, execConfig)
95+
return cli.hijackWithContentType("POST", "/exec/"+execID+"/start", "application/json", execConfig.Tty, in, out, stderr, hijacked, execConfig)
9696
})
9797

9898
// Acknowledge the hijack before starting

api/client/hijack.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ func (cli *DockerCli) dial() (net.Conn, error) {
127127
}
128128

129129
func (cli *DockerCli) hijack(method, path string, setRawTerminal bool, in io.ReadCloser, stdout, stderr io.Writer, started chan io.Closer, data interface{}) error {
130+
return cli.hijackWithContentType(method, path, "text/plain", setRawTerminal, in, stdout, stderr, started, data)
131+
}
132+
133+
func (cli *DockerCli) hijackWithContentType(method, path, contentType string, setRawTerminal bool, in io.ReadCloser, stdout, stderr io.Writer, started chan io.Closer, data interface{}) error {
130134
defer func() {
131135
if started != nil {
132136
close(started)
@@ -149,7 +153,7 @@ func (cli *DockerCli) hijack(method, path string, setRawTerminal bool, in io.Rea
149153
}
150154

151155
req.Header.Set("User-Agent", "Docker-Client/"+dockerversion.VERSION+" ("+runtime.GOOS+")")
152-
req.Header.Set("Content-Type", "text/plain")
156+
req.Header.Set("Content-Type", contentType)
153157
req.Header.Set("Connection", "Upgrade")
154158
req.Header.Set("Upgrade", "tcp")
155159
req.Host = cli.addr

api/server/router/local/exec.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ func (s *router) postContainerExecStart(ctx context.Context, w http.ResponseWrit
6060
if err := httputils.ParseForm(r); err != nil {
6161
return err
6262
}
63+
if err := httputils.CheckForJSON(r); err != nil {
64+
return err
65+
}
6366
var (
6467
execName = vars["name"]
6568
stdin, inStream io.ReadCloser

0 commit comments

Comments
 (0)