Skip to content

Commit

Permalink
Regression: Fix assigning to nil map in DeepMerge (#18143)
Browse files Browse the repository at this point in the history
  • Loading branch information
Steffen Siering authored May 4, 2020
1 parent c81adcc commit 68fc3c4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Fix goroutine leak and Elasticsearch output file descriptor leak when output reloading is in use. {issue}10491[10491] {pull}17381[17381]
- Fix `setup.dashboards.index` setting not working. {pull}17749[17749]
- Fix Elasticsearch license endpoint URL referenced in error message. {issue}17880[17880] {pull}18030[18030]
- Fix panic when assigning a key to a `nil` value in an event. {pull}18143[18143]

*Auditbeat*

Expand Down
16 changes: 11 additions & 5 deletions libbeat/common/mapstr.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,26 @@ func (m MapStr) deepUpdateMap(d MapStr, overwrite bool) {
}

func deepUpdateValue(old interface{}, val MapStr, overwrite bool) interface{} {
if old == nil {
return val
}

switch sub := old.(type) {
case MapStr:
if sub == nil {
return val
}

sub.deepUpdateMap(val, overwrite)
return sub
case map[string]interface{}:
if sub == nil {
return val
}

tmp := MapStr(sub)
tmp.deepUpdateMap(val, overwrite)
return tmp
default:
// This should never happen
// We reach the default branch if old is no map or if old == nil.
// In either case we return `val`, such that the old value is completely
// replaced when merging.
return val
}
}
Expand Down
5 changes: 5 additions & 0 deletions libbeat/common/mapstr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ func TestMapStrDeepUpdate(t *testing.T) {
MapStr{"a.b": 1},
MapStr{"a": 1, "a.b": 1},
},
{
MapStr{"a": (MapStr)(nil)},
MapStr{"a": MapStr{"b": 1}},
MapStr{"a": MapStr{"b": 1}},
},
}

for i, test := range tests {
Expand Down

0 comments on commit 68fc3c4

Please sign in to comment.