Skip to content

Commit

Permalink
Nil check dereferences of non-mandatory SDK fields (oracle#185)
Browse files Browse the repository at this point in the history
Guard against theoretical panics when accessing non-mandatory OCI Go SDK fields.
  • Loading branch information
prydie authored and owainlewis committed Apr 16, 2018
1 parent 3adbb0c commit 8e59a85
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pkg/oci/client/compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,18 @@ func (c *client) GetPrimaryVNICForInstance(ctx context.Context, compartmentID, i
continue
}

if attachment.VnicId == nil {
// Should never happen but lets be extra cautious as field is non-mandatory in OCI API.
glog.Errorf("VNIC attachment %q for instance %q is attached but has no VNIC ID", *attachment.Id, instanceID)
continue
}

// TODO(apryde): Cache map[instanceID]primaryVNICID.
vnic, err := c.getVNIC(ctx, *attachment.VnicId)
if err != nil {
return nil, err
}
if *vnic.IsPrimary {
if vnic.IsPrimary != nil && *vnic.IsPrimary {
return vnic, nil
}
}
Expand Down Expand Up @@ -157,6 +163,12 @@ func (c *client) GetInstanceByNodeName(ctx context.Context, compartmentID, vcnID
continue
}

if attachment.VnicId == nil {
// Should never happen but lets be extra cautious as field is non-mandatory in OCI API.
glog.Errorf("VNIC attachment %q for instance %q is attached but has no VNIC ID", *attachment.Id, nodeName)
continue
}

vnic, err := c.getVNIC(ctx, *attachment.VnicId)
if err != nil {
return nil, err
Expand Down

0 comments on commit 8e59a85

Please sign in to comment.