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 <srust@blockbridge.com>
Upstream-commit: c358a4cd3597ac330674c9d93b6038e8f455c8f7
Component: engine
This commit is contained in:
Stephen Rust
2015-07-26 20:33:04 -04:00
parent ed5b93d380
commit dec1a0e3c4
2 changed files with 11 additions and 1 deletions
+1 -1
View File
@@ -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)
@@ -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)
}