Skip to content

Commit

Permalink
fix: Allow use of valid Port 0
Browse files Browse the repository at this point in the history
Port 0 is a normal but reserved port.
See: https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml
or RFC6335 Section 6
  • Loading branch information
MarcWort committed Jul 17, 2024
1 parent c00345f commit 3705d1e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
- Fix high IO and handling of a corrupted registry log file. {pull}35893[35893]
- Filebeat, when running with Elastic-Agent, reports status for Filestream input. {pull}40121[40121]
- Implement Elastic Agent status and health reporting for Winlog Filebeat input. {pull}40163[40163]
- Fix the parsing of port 0

*Heartbeat*

Expand Down
4 changes: 2 additions & 2 deletions libbeat/processors/communityid/communityid.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (p *processor) buildFlow(event *beat.Event) *flowhash.Flow {
return nil
}
sp, ok := tryToUint(v)
if !ok || sp < 1 || sp > 65535 {
if !ok || sp > 65535 {
return nil
}
flow.SourcePort = uint16(sp)
Expand All @@ -164,7 +164,7 @@ func (p *processor) buildFlow(event *beat.Event) *flowhash.Flow {
return nil
}
dp, ok := tryToUint(v)
if !ok || dp < 1 || dp > 65535 {
if !ok || dp > 65535 {
return nil
}
flow.DestinationPort = uint16(dp)
Expand Down
12 changes: 6 additions & 6 deletions libbeat/processors/communityid/communityid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@ func TestRun(t *testing.T) {
testProcessor(t, 0, e, nil)
})

t.Run("invalid source port", func(t *testing.T) {
e := evt()
e.Put("source.port", 0)
testProcessor(t, 0, e, nil)
})

t.Run("invalid source port1", func(t *testing.T) {
e := evt()
e.Put("source.port", 123456)
Expand Down Expand Up @@ -142,6 +136,12 @@ func TestRun(t *testing.T) {
testProcessor(t, 0, e, "1:D3t8Q1aFA6Ev0A/AO4i9PnU3AeI=")
})

t.Run("valid source port 0", func(t *testing.T) {
e := evt()
e.Put("source.port", 0)
testProcessor(t, 0, e, "1:yrNkRN7VyfVz1Wh12tjRHhxERxM=")
})

t.Run("iana number", func(t *testing.T) {
e := evt()
e.Delete("network.transport")
Expand Down

0 comments on commit 3705d1e

Please sign in to comment.