Skip to content

Commit

Permalink
Guard against panic in cty.Value.LengthInt().
Browse files Browse the repository at this point in the history
Signed-off-by: Cem Mergenci <[email protected]>
  • Loading branch information
mergenci committed Dec 23, 2024
1 parent 997a60e commit b935e46
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/tags/key_value_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,10 @@ func GetAnyAttr(value cty.Value, attr string, shouldReturnSetElement func(string
return cty.NilVal, fmt.Errorf("invalid index: %s", indexStr)
}

if value.Type().IsListType() && (value.IsNull() || !value.IsKnown()) {
return cty.NilVal, fmt.Errorf("list attribute %s is unknown or null", attrName)
}

if index >= value.LengthInt() {
return cty.NilVal, fmt.Errorf("index %d out of range for attribute %s", index, attrName)
}
Expand Down

0 comments on commit b935e46

Please sign in to comment.