Преглед изворни кода

addressed possible nil dereferences

Signed-off-by: nickcurie <nick.curie64@gmail.com>
nickcurie пре 3 година
родитељ
комит
0fb0ecd240
3 измењених фајлова са 14 додато и 2 уклоњено
  1. 10 1
      pkg/cloud/awsprovider.go
  2. 3 0
      pkg/cloud/azureprovider.go
  3. 1 1
      pkg/cloud/gcpprovider.go

+ 10 - 1
pkg/cloud/awsprovider.go

@@ -1706,7 +1706,10 @@ func (aws *AWS) GetOrphanedResources() ([]OrphanedResource, error) {
 			}
 
 			// This is turning us-east-1a into us-east-1
-			zone := *volume.AvailabilityZone
+			var zone string
+			if volume.AvailabilityZone != nil {
+				zone = *volume.AvailabilityZone
+			}
 			var region, url string
 			region = regionRx.FindString(zone)
 			if region != "" {
@@ -1734,6 +1737,12 @@ func (aws *AWS) GetOrphanedResources() ([]OrphanedResource, error) {
 
 			desc := map[string]string{}
 			for _, tag := range address.Tags {
+				if tag.Key == nil {
+					continue
+				}
+				if tag.Value == nil {
+					continue
+				}
 				desc[*tag.Key] = *tag.Value
 			}
 

+ 3 - 0
pkg/cloud/azureprovider.go

@@ -1284,6 +1284,9 @@ func (az *Azure) GetOrphanedResources() ([]OrphanedResource, error) {
 
 			desc := map[string]string{}
 			for k, v := range d.Tags {
+				if v == nil {
+					continue
+				}
 				desc[k] = *v
 			}
 

+ 1 - 1
pkg/cloud/gcpprovider.go

@@ -472,7 +472,7 @@ func (gcp *GCP) GetOrphanedResources() ([]OrphanedResource, error) {
 				// deconstruct it back into a map[string]string to match the OR struct
 				desc := map[string]string{}
 				if err := json.Unmarshal([]byte(disk.Description), &desc); err != nil {
-					return nil, err
+					return nil, fmt.Errorf("error converting string to map: %s", err)
 				}
 
 				or := OrphanedResource{