Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport of Add input validation to getRuleInfo to prevent panic into release/1.10.x #14735

Merged
merged 2 commits into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/14501.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
core: Fix panic caused by parsing policies with empty slice values.
```
5 changes: 5 additions & 0 deletions helper/random/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
9 changes: 9 additions & 0 deletions helper/random/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down