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:
parent
e5b614ed9b
commit
7c8e6676c0
|
@ -0,0 +1,3 @@
|
|||
```release-note:bug
|
||||
core: Fix panic caused by parsing policies with empty slice values.
|
||||
```
|
|
@ -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],
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue