Add input validation to getRuleInfo to prevent panic (#14501)

* return error from getRuleInfo if rule contains empty slice to prevent panic

* add changelog entry
This commit is contained in:
Chris Capurso 2022-03-24 16:16:37 -04:00 committed by GitHub
parent e5b614ed9b
commit 7c8e6676c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 0 deletions

3
changelog/14501.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:bug
core: Fix panic caused by parsing policies with empty slice values.
```

View File

@ -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],

View File

@ -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 {