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>
This commit is contained in:
parent
c051ed7953
commit
c358a4cd35
2 changed files with 11 additions and 1 deletions
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue