Skip to content

Commit

Permalink
filebeat/input/{tcp,udp}: don't panic on nil addresses (#33837)
Browse files Browse the repository at this point in the history
The callback may be called with a nil RemoteAddr in the metadata
parameter, so ensure that this is not nil before attempting to deference
it.
  • Loading branch information
efd6 authored and chrisberkhout committed Jun 1, 2023
1 parent cb0eb64 commit 934130e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ https://github.com/elastic/beats/compare/v8.2.0\...main[Check the HEAD diff]
- Fix states client support for output options. {pull}33405[33405]
- Fix states client reloader under managed mode. {pull}33405[33405]
- Fix bug where states.duration_ms was incorrect type. {pull}33563[33563]
- Fix handling of long UDP messages in UDP input. {issue}33836[33836] {pull}33837[33837]

*Auditbeat*

Expand Down
17 changes: 10 additions & 7 deletions filebeat/input/tcp/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func NewInput(

cb := func(data []byte, metadata inputsource.NetworkMetadata) {
event := createEvent(data, metadata)
forwarder.Send(event)
_ = forwarder.Send(event)
}

splitFunc, err := streaming.SplitFunc(config.Framing, []byte(config.LineDelimiter))
Expand Down Expand Up @@ -128,15 +128,18 @@ func (p *Input) Wait() {
}

func createEvent(raw []byte, metadata inputsource.NetworkMetadata) beat.Event {
return beat.Event{
evt := beat.Event{
Timestamp: time.Now(),
Fields: mapstr.M{
"message": string(raw),
"log": mapstr.M{
"source": mapstr.M{
"address": metadata.RemoteAddr.String(),
},
},
},
}
if metadata.RemoteAddr != nil {
evt.Fields["log"] = mapstr.M{
"source": mapstr.M{
"address": metadata.RemoteAddr.String(),
},
}
}
return evt
}
17 changes: 10 additions & 7 deletions filebeat/input/udp/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,23 @@ func NewInput(

forwarder := harvester.NewForwarder(out)
callback := func(data []byte, metadata inputsource.NetworkMetadata) {
forwarder.Send(beat.Event{
evt := beat.Event{
Timestamp: time.Now(),
Meta: mapstr.M{
"truncated": metadata.Truncated,
},
Fields: mapstr.M{
"message": string(data),
"log": mapstr.M{
"source": mapstr.M{
"address": metadata.RemoteAddr.String(),
},
},
},
})
}
if metadata.RemoteAddr != nil {
evt.Fields["log"] = mapstr.M{
"source": mapstr.M{
"address": metadata.RemoteAddr.String(),
},
}
}
_ = forwarder.Send(evt)
}

udp := udp.New(&config.Config, callback)
Expand Down

0 comments on commit 934130e

Please sign in to comment.