Skip to content

Commit 8e59a85

Browse files
prydieowainlewis
authored andcommitted
Nil check dereferences of non-mandatory SDK fields (oracle#185)
Guard against theoretical panics when accessing non-mandatory OCI Go SDK fields.
1 parent 3adbb0c commit 8e59a85

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

pkg/oci/client/compute.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,18 @@ func (c *client) GetPrimaryVNICForInstance(ctx context.Context, compartmentID, i
111111
continue
112112
}
113113

114+
if attachment.VnicId == nil {
115+
// Should never happen but lets be extra cautious as field is non-mandatory in OCI API.
116+
glog.Errorf("VNIC attachment %q for instance %q is attached but has no VNIC ID", *attachment.Id, instanceID)
117+
continue
118+
}
119+
114120
// TODO(apryde): Cache map[instanceID]primaryVNICID.
115121
vnic, err := c.getVNIC(ctx, *attachment.VnicId)
116122
if err != nil {
117123
return nil, err
118124
}
119-
if *vnic.IsPrimary {
125+
if vnic.IsPrimary != nil && *vnic.IsPrimary {
120126
return vnic, nil
121127
}
122128
}
@@ -157,6 +163,12 @@ func (c *client) GetInstanceByNodeName(ctx context.Context, compartmentID, vcnID
157163
continue
158164
}
159165

166+
if attachment.VnicId == nil {
167+
// Should never happen but lets be extra cautious as field is non-mandatory in OCI API.
168+
glog.Errorf("VNIC attachment %q for instance %q is attached but has no VNIC ID", *attachment.Id, nodeName)
169+
continue
170+
}
171+
160172
vnic, err := c.getVNIC(ctx, *attachment.VnicId)
161173
if err != nil {
162174
return nil, err

0 commit comments

Comments
 (0)