From 00d88d7fbf5b547c5f4692cf5fa5c27f3430b814 Mon Sep 17 00:00:00 2001 From: Toby Date: Sun, 21 Jan 2024 12:26:23 -0800 Subject: [PATCH] fix: incorrect prop update logic --- engine/tcp.go | 8 +++++--- engine/udp.go | 8 +++++--- engine/utils.go | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/engine/tcp.go b/engine/tcp.go index 067702b..f153f15 100644 --- a/engine/tcp.go +++ b/engine/tcp.go @@ -133,8 +133,9 @@ func (s *tcpStream) ReassembledSG(sg reassembly.ScatterGather, ac reassembly.Ass // Important: reverse order so we can remove entries entry := s.activeEntries[i] update, closeUpdate, done := s.feedEntry(entry, rev, start, end, skip, data) - updated = updated || processPropUpdate(s.info.Props, entry.Name, update) - updated = updated || processPropUpdate(s.info.Props, entry.Name, closeUpdate) + up1 := processPropUpdate(s.info.Props, entry.Name, update) + up2 := processPropUpdate(s.info.Props, entry.Name, closeUpdate) + updated = updated || up1 || up2 if done { s.activeEntries = append(s.activeEntries[:i], s.activeEntries[i+1:]...) s.doneEntries = append(s.doneEntries, entry) @@ -174,7 +175,8 @@ func (s *tcpStream) closeActiveEntries() { updated := false for _, entry := range s.activeEntries { update := entry.Stream.Close(false) - updated = updated || processPropUpdate(s.info.Props, entry.Name, update) + up := processPropUpdate(s.info.Props, entry.Name, update) + updated = updated || up } if updated { s.logger.TCPStreamPropUpdate(s.info, true) diff --git a/engine/udp.go b/engine/udp.go index a5bf7d3..227413b 100644 --- a/engine/udp.go +++ b/engine/udp.go @@ -187,8 +187,9 @@ func (s *udpStream) Feed(udp *layers.UDP, rev bool, uc *udpContext) { // Important: reverse order so we can remove entries entry := s.activeEntries[i] update, closeUpdate, done := s.feedEntry(entry, rev, udp.Payload) - updated = updated || processPropUpdate(s.info.Props, entry.Name, update) - updated = updated || processPropUpdate(s.info.Props, entry.Name, closeUpdate) + up1 := processPropUpdate(s.info.Props, entry.Name, update) + up2 := processPropUpdate(s.info.Props, entry.Name, closeUpdate) + updated = updated || up1 || up2 if done { s.activeEntries = append(s.activeEntries[:i], s.activeEntries[i+1:]...) s.doneEntries = append(s.doneEntries, entry) @@ -244,7 +245,8 @@ func (s *udpStream) closeActiveEntries() { updated := false for _, entry := range s.activeEntries { update := entry.Stream.Close(false) - updated = updated || processPropUpdate(s.info.Props, entry.Name, update) + up := processPropUpdate(s.info.Props, entry.Name, update) + updated = updated || up } if updated { s.logger.UDPStreamPropUpdate(s.info, true) diff --git a/engine/utils.go b/engine/utils.go index 41098ac..9b86ade 100644 --- a/engine/utils.go +++ b/engine/utils.go @@ -30,7 +30,7 @@ func processPropUpdate(cpm analyzer.CombinedPropMap, name string, update *analyz case analyzer.PropUpdateMerge: m := cpm[name] if m == nil { - m = make(analyzer.PropMap) + m = make(analyzer.PropMap, len(update.M)) cpm[name] = m } for k, v := range update.M {