Skip to content

Commit

Permalink
Add safer constraints when looping through map elements
Browse files Browse the repository at this point in the history
  • Loading branch information
jsoriano committed Mar 31, 2022
1 parent a0fdf1e commit c79194b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion internal/fields/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,11 @@ func (fds *FieldDefinitions) UnmarshalYAML(value *yaml.Node) error {
return nil
case yaml.MappingNode:
// Fields are defined as a map, this happens in ecs fields files.
if len(value.Content)%2 != 0 {
return fmt.Errorf("pairs of key-values expected in map")
}
var fields []FieldDefinition
for i := 0; i < len(value.Content); i += 2 {
for i := 0; i+1 < len(value.Content); i += 2 {
key := value.Content[i]
value := value.Content[i+1]

Expand Down

0 comments on commit c79194b

Please sign in to comment.