From b935e46584b21b1f0073653b6613482615362713 Mon Sep 17 00:00:00 2001 From: Cem Mergenci Date: Mon, 23 Dec 2024 22:36:57 +0300 Subject: [PATCH] Guard against panic in cty.Value.LengthInt(). Signed-off-by: Cem Mergenci --- internal/tags/key_value_tags.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/tags/key_value_tags.go b/internal/tags/key_value_tags.go index 725eae7aee..81e26b8a32 100644 --- a/internal/tags/key_value_tags.go +++ b/internal/tags/key_value_tags.go @@ -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) }