Skip to content

Commit

Permalink
return error from getRuleInfo if rule contains empty slice to prevent…
Browse files Browse the repository at this point in the history
… panic
  • Loading branch information
ccapurso committed Mar 15, 2022
1 parent a69db1b commit 156bfc1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
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

0 comments on commit 156bfc1

Please sign in to comment.