Add check for invalid memory address or nil pointer dereference
@@ -747,6 +747,18 @@ func (s *Service) getImageSnapshotSize(imageID string) (*int64, error) {
return nil, errors.Errorf("no images returned when looking up ID %q", imageID)
}
+ if len(output.Images[0].BlockDeviceMappings) == 0 {
+ return nil, errors.Errorf("no block device mappings returned when looking up ID %q", imageID)
+ }
+
+ if output.Images[0].BlockDeviceMappings[0].Ebs == nil {
+ return nil, errors.Errorf("no EBS returned when looking up ID %q", imageID)
+ }
+
+ if output.Images[0].BlockDeviceMappings[0].Ebs.VolumeSize == nil {
+ return nil, errors.Errorf("no EBS volume size returned when looking up ID %q", imageID)
+ }
+
return output.Images[0].BlockDeviceMappings[0].Ebs.VolumeSize, nil
}
