Skip to content

Commit c213950

Browse files
nhindsyuyangbj
authored andcommitted
Avoid panic for invalid container network name (#8577)
Avoids a nil pointer dereference in vic-machine when an invalid or ambiguous container network name is passed.
1 parent 85b5f80 commit c213950

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

lib/install/validate/network.go

+1
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ func (v *Validator) network(op trace.Operation, input *data.Data, conf *config.V
393393
v.suggestNetwork(op, "--container-network", true)
394394
suggestedMapped = true
395395
}
396+
continue
396397
}
397398
mappedNet := &executor.ContainerNetwork{
398399
Common: executor.Common{

lib/install/validate/validator_test.go

+13-8
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func TestValidator(t *testing.T) {
5757
for i, model := range []*simulator.Model{simulator.ESX(), simulator.VPX()} {
5858
t.Logf("%d", i)
5959
model.Datastore = 3
60-
model.Portgroup = 1
60+
model.Portgroup = 2
6161
defer model.Remove()
6262
err := model.Create()
6363
if err != nil {
@@ -807,18 +807,23 @@ func TestValidateWithFolders(t *testing.T) {
807807
func testNetwork(ctx context.Context, v *Validator, input *data.Data, conf *config.VirtualContainerHostConfigSpec, t *testing.T) {
808808
op := trace.FromContext(ctx, "testNetwork")
809809
tests := []struct {
810-
path string
811-
vc bool
812-
hasErr bool
810+
bridgePath string
811+
mappedNetworks map[string]string
812+
hasErr bool
813813
}{
814-
{"/DC0/network/DC0_DVPG0", true, false},
815-
{"DC0_DVPG0", true, false},
816-
{"bridge", true, true},
814+
{"/DC0/network/DC0_DVPG0", map[string]string{}, false},
815+
{"DC0_DVPG0", map[string]string{}, false},
816+
{"DC0_DVPG0", map[string]string{"containernet1": "DC0_DVPG1"}, false},
817+
{"DC0_DVPG0", map[string]string{"containernet1": "noexist"}, true},
818+
{"DC0_DVPG0", map[string]string{"containernet1": "DC0_DVPG0"}, true},
819+
{"DC0_DVPG0", map[string]string{"bridge": "DC0_DVPG1"}, true},
820+
{"bridge", map[string]string{}, true},
817821
}
818822
// Throw exception if there is no network
819823
for _, test := range tests {
820824
t.Logf("%+v", test)
821-
input.BridgeNetworkName = test.path
825+
input.BridgeNetworkName = test.bridgePath
826+
input.MappedNetworks = test.mappedNetworks
822827
v.network(op, input, conf)
823828
v.ListIssues(op)
824829
if !test.hasErr {

0 commit comments

Comments
 (0)