Skip to content

Commit

Permalink
Backport: Fix panic if user sets custom fields starting with host
Browse files Browse the repository at this point in the history
The root cause has been fixed by elastic#10801 by accident already.  This
selectively backports the checks to 6.7, as elastic#10801 is to much of a
change.
  • Loading branch information
urso committed Feb 25, 2019
1 parent 4b21d37 commit e4cde2f
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions libbeat/publisher/pipeline/processor.go
Expand Up @@ -71,6 +71,7 @@ func newProcessorPipeline(
)

needsCopy := global.alwaysCopy || localProcessors != nil || global.processors != nil
builtin := global.builtinMeta

if !config.SkipNormalization {
// setup 1: generalize/normalize output (P)
Expand Down Expand Up @@ -102,13 +103,13 @@ func newProcessorPipeline(
// metadata will be merged into the fields.
// With dynamic fields potentially changing at any time, we need to copy,
// so we do not change shared structures be accident.
fieldsNeedsCopy := needsCopy || config.DynamicFields != nil || fields["beat"] != nil
fieldsNeedsCopy := needsCopy || config.DynamicFields != nil || hasKeyAnyOf(fields, builtin)
processors.add(makeAddFieldsProcessor("fields", fields, fieldsNeedsCopy))
}

if config.DynamicFields != nil {
checkCopy := func(m common.MapStr) bool {
return needsCopy || hasKey(m, "beat")
return needsCopy || hasKeyAnyOf(m, builtin)
}
processors.add(makeAddDynMetaProcessor("dynamicFields", config.DynamicFields, checkCopy))
}
Expand All @@ -117,8 +118,8 @@ func newProcessorPipeline(
processors.add(localProcessors)

// setup 6: add beats and host metadata
if meta := global.builtinMeta; len(meta) > 0 {
processors.add(makeAddFieldsProcessor("beatsMeta", meta, needsCopy))
if len(builtin) > 0 {
processors.add(makeAddFieldsProcessor("beatsMeta", builtin, needsCopy))
}

// setup 7: pipeline processors list
Expand Down Expand Up @@ -326,3 +327,12 @@ func hasKey(m common.MapStr, key string) bool {
_, exists := m[key]
return exists
}

func hasKeyAnyOf(m, builtin common.MapStr) bool {
for k := range builtin {
if hasKey(m, k) {
return true
}
}
return false
}

0 comments on commit e4cde2f

Please sign in to comment.