Skip to content

Commit

Permalink
Avoid panic for invalid container network name (#8577)
Browse files Browse the repository at this point in the history
Avoids a nil pointer dereference in vic-machine when an invalid or
ambiguous container network name is passed.
  • Loading branch information
nhinds authored and yuyangbj committed Sep 3, 2019
1 parent 85b5f80 commit c213950
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions lib/install/validate/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ func (v *Validator) network(op trace.Operation, input *data.Data, conf *config.V
v.suggestNetwork(op, "--container-network", true)
suggestedMapped = true
}
continue
}
mappedNet := &executor.ContainerNetwork{
Common: executor.Common{
Expand Down
21 changes: 13 additions & 8 deletions lib/install/validate/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestValidator(t *testing.T) {
for i, model := range []*simulator.Model{simulator.ESX(), simulator.VPX()} {
t.Logf("%d", i)
model.Datastore = 3
model.Portgroup = 1
model.Portgroup = 2
defer model.Remove()
err := model.Create()
if err != nil {
Expand Down Expand Up @@ -807,18 +807,23 @@ func TestValidateWithFolders(t *testing.T) {
func testNetwork(ctx context.Context, v *Validator, input *data.Data, conf *config.VirtualContainerHostConfigSpec, t *testing.T) {
op := trace.FromContext(ctx, "testNetwork")
tests := []struct {
path string
vc bool
hasErr bool
bridgePath string
mappedNetworks map[string]string
hasErr bool
}{
{"/DC0/network/DC0_DVPG0", true, false},
{"DC0_DVPG0", true, false},
{"bridge", true, true},
{"/DC0/network/DC0_DVPG0", map[string]string{}, false},
{"DC0_DVPG0", map[string]string{}, false},
{"DC0_DVPG0", map[string]string{"containernet1": "DC0_DVPG1"}, false},
{"DC0_DVPG0", map[string]string{"containernet1": "noexist"}, true},
{"DC0_DVPG0", map[string]string{"containernet1": "DC0_DVPG0"}, true},
{"DC0_DVPG0", map[string]string{"bridge": "DC0_DVPG1"}, true},
{"bridge", map[string]string{}, true},
}
// Throw exception if there is no network
for _, test := range tests {
t.Logf("%+v", test)
input.BridgeNetworkName = test.path
input.BridgeNetworkName = test.bridgePath
input.MappedNetworks = test.mappedNetworks
v.network(op, input, conf)
v.ListIssues(op)
if !test.hasErr {
Expand Down

0 comments on commit c213950

Please sign in to comment.