Procházet zdrojové kódy

Nil check on Asset labels before accessing. (#2953)

Signed-off-by: thomasvn <thomasnguyen96@gmail.com>
Thomas Nguyen před 1 rokem
rodič
revize
4aae776a84
1 změnil soubory, kde provedl 6 přidání a 2 odebrání
  1. 6 2
      core/pkg/opencost/asset_json.go

+ 6 - 2
core/pkg/opencost/asset_json.go

@@ -531,8 +531,12 @@ func (n *Node) InterfaceToNode(itf interface{}) error {
 
 	// parse labels map to AssetLabels
 	labels := make(map[string]string)
-	for k, v := range fmap["labels"].(map[string]interface{}) {
-		labels[k] = v.(string)
+	if labelsInterface, ok := fmap["labels"].(map[string]interface{}); ok {
+		for k, v := range labelsInterface {
+			if strValue, ok := v.(string); ok {
+				labels[k] = strValue
+			}
+		}
 	}
 
 	// parse start and end strings to time.Time