Skip to content

Commit

Permalink
Don't attempt to parse JSON payload if it is 0 bytes long.
Browse files Browse the repository at this point in the history
Also added a test to trigger this.
  • Loading branch information
bboreham committed Apr 5, 2016
1 parent b7d49cd commit 706c7b8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion proxy/start_container_interceptor.go
Expand Up @@ -15,7 +15,7 @@ func (i *startContainerInterceptor) InterceptRequest(r *http.Request) error {

// If the client has sent some JSON which might be a HostConfig, add our
// parameters back into it, otherwise Docker will consider them overwritten
if containerShouldAttach(container) && r.Header.Get("Content-Type") == "application/json" {
if containerShouldAttach(container) && r.Header.Get("Content-Type") == "application/json" && r.ContentLength > 0 {
params := map[string]interface{}{}
if err := unmarshalRequestBody(r, &params); err != nil {
return err
Expand Down
5 changes: 5 additions & 0 deletions test/666_abuse_of_start_test.sh
Expand Up @@ -33,6 +33,11 @@ proxy docker_on $HOST1 create --name=c4 --memory-swap -1 $SMALL_IMAGE echo foo
assert_raises "proxy docker_api_on $HOST1 POST /containers/c4/start 'null'"
assert "docker_on $HOST1 inspect -f '{{.HostConfig.MemorySwap}}' c4" "-1"

# Start c4b with an empty HostConfig (generated by Docker 1.11.0-rc2)
proxy docker_on $HOST1 create --name=c4b --memory-swap -1 $SMALL_IMAGE echo foo
assert_raises "proxy docker_api_on $HOST1 POST /containers/c4b/start ''"
assert "docker_on $HOST1 inspect -f '{{.HostConfig.MemorySwap}}' c4b" "-1"

# Start c6 with both named and unnamed HostConfig
proxy docker_on $HOST1 create --name=c6 $SMALL_IMAGE $CHECK_ETHWE_UP
proxy docker_api_on $HOST1 POST /containers/c6/start '{"NetworkMode": "container:c2", "HostConfig": {"NetworkMode": "container:c1"}}'
Expand Down

0 comments on commit 706c7b8

Please sign in to comment.