From dec1a0e3c4b024b2f08099f60864e9e6a840e578 Mon Sep 17 00:00:00 2001 From: Stephen Rust Date: Sat, 25 Jul 2015 07:39:13 -0400 Subject: [PATCH] Check for nil before using HostConfig to adjustCpuShares Fix #14915. Add unit test for #14915. Thanks @runcom for the test case: when the client calls 1.18 api version w/o hostconfig it results in a nil pointer dereference. Signed-off-by: Stephen Rust Upstream-commit: c358a4cd3597ac330674c9d93b6038e8f455c8f7 Component: engine --- components/engine/api/server/server_linux.go | 2 +- .../integration-cli/docker_api_containers_test.go | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/components/engine/api/server/server_linux.go b/components/engine/api/server/server_linux.go index 2ab186e972..f6ad26a9bf 100644 --- a/components/engine/api/server/server_linux.go +++ b/components/engine/api/server/server_linux.go @@ -109,7 +109,7 @@ func allocateDaemonPort(addr string) error { func adjustCpuShares(version version.Version, hostConfig *runconfig.HostConfig) { if version.LessThan("1.19") { - if hostConfig.CpuShares > 0 { + if hostConfig != nil && hostConfig.CpuShares > 0 { // Handle unsupported CpuShares if hostConfig.CpuShares < linuxMinCpuShares { logrus.Warnf("Changing requested CpuShares of %d to minimum allowed of %d", hostConfig.CpuShares, linuxMinCpuShares) diff --git a/components/engine/integration-cli/docker_api_containers_test.go b/components/engine/integration-cli/docker_api_containers_test.go index b0e9b0eed7..c9d5d96453 100644 --- a/components/engine/integration-cli/docker_api_containers_test.go +++ b/components/engine/integration-cli/docker_api_containers_test.go @@ -1687,3 +1687,13 @@ func (s *DockerSuite) TestPostContainersStartWithLinksInHostConfigIdLinked(c *ch c.Assert(res.StatusCode, check.Equals, http.StatusNoContent) b.Close() } + +// #14915 +func (s *DockerSuite) TestContainersApiCreateNoHostConfig118(c *check.C) { + config := struct { + Image string + }{"busybox"} + status, _, err := sockRequest("POST", "/v1.18/containers/create", config) + c.Assert(err, check.IsNil) + c.Assert(status, check.Equals, http.StatusCreated) +}