From 8d2f4cb24129d87674a13319ca48ce8636ee527a Mon Sep 17 00:00:00 2001 From: Yong Tang Date: Sun, 21 Jan 2018 00:30:26 +0000 Subject: [PATCH] Verify NetworkingConfig to make sure EndpointSettings is not nil This fix tries to address the issue raised in 35752 where container start will trigger a crash if EndpointSettings is nil. This fix adds the validation to make sure EndpointSettings != nil This fix fixes 35752. Signed-off-by: Yong Tang --- daemon/create.go | 7 +++++-- daemon/create_test.go | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 daemon/create_test.go diff --git a/daemon/create.go b/daemon/create.go index 4ba5ad9e27..0f52f3c3fb 100644 --- a/daemon/create.go +++ b/daemon/create.go @@ -322,8 +322,11 @@ func verifyNetworkingConfig(nwConfig *networktypes.NetworkingConfig) error { return nil } if len(nwConfig.EndpointsConfig) == 1 { - for _, v := range nwConfig.EndpointsConfig { - if v != nil && v.IPAMConfig != nil { + for k, v := range nwConfig.EndpointsConfig { + if v == nil { + return errdefs.InvalidParameter(errors.Errorf("no EndpointSettings for %s", k)) + } + if v.IPAMConfig != nil { if v.IPAMConfig.IPv4Address != "" && net.ParseIP(v.IPAMConfig.IPv4Address).To4() == nil { return errors.Errorf("invalid IPv4 address: %s", v.IPAMConfig.IPv4Address) } diff --git a/daemon/create_test.go b/daemon/create_test.go new file mode 100644 index 0000000000..43ac5b390a --- /dev/null +++ b/daemon/create_test.go @@ -0,0 +1,21 @@ +package daemon + +import ( + "testing" + + "github.com/docker/docker/api/types/network" + "github.com/docker/docker/errdefs" + "github.com/stretchr/testify/assert" +) + +// Test case for 35752 +func TestVerifyNetworkingConfig(t *testing.T) { + name := "mynet" + endpoints := make(map[string]*network.EndpointSettings, 1) + endpoints[name] = nil + nwConfig := &network.NetworkingConfig{ + EndpointsConfig: endpoints, + } + err := verifyNetworkingConfig(nwConfig) + assert.True(t, errdefs.IsInvalidParameter(err)) +}