mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
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 <yong.tang.github@outlook.com>
This commit is contained in:
parent
db5c006bc8
commit
8d2f4cb241
2 changed files with 26 additions and 2 deletions
|
@ -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)
|
||||
}
|
||||
|
|
21
daemon/create_test.go
Normal file
21
daemon/create_test.go
Normal file
|
@ -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))
|
||||
}
|
Loading…
Add table
Reference in a new issue