diff --git a/changelog/14501.txt b/changelog/14501.txt new file mode 100644 index 000000000000..5ed687e28ad7 --- /dev/null +++ b/changelog/14501.txt @@ -0,0 +1,3 @@ +```release-note:bug +core: Fix panic caused by parsing policies with empty slice values. +``` diff --git a/helper/random/parser.go b/helper/random/parser.go index 572767263e3b..3184db8aa5c6 100644 --- a/helper/random/parser.go +++ b/helper/random/parser.go @@ -126,6 +126,11 @@ func getRuleInfo(rule map[string]interface{}) (data ruleInfo, err error) { if err != nil { return data, fmt.Errorf("unable to get rule data: %w", err) } + + if len(slice) == 0 { + return data, fmt.Errorf("rule info cannot be empty") + } + data = ruleInfo{ ruleType: key, data: slice[0], diff --git a/helper/random/parser_test.go b/helper/random/parser_test.go index 2ce1fde521e4..59cdb8143043 100644 --- a/helper/random/parser_test.go +++ b/helper/random/parser_test.go @@ -297,6 +297,15 @@ func TestParser_ParsePolicy(t *testing.T) { expected: StringGenerator{}, expectErr: true, }, + "config value with empty slice": { + registry: defaultRuleNameMapping, + rawConfig: ` + rule { + n = [] + }`, + expected: StringGenerator{}, + expectErr: true, + }, } for name, test := range tests {