From a33526a976148bfaab7695247d567c8d301874ff Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 28 Jul 2023 16:50:35 +0200 Subject: [PATCH] Fix handling of connections without process --- network/clean.go | 9 ++++++--- network/connection.go | 13 ++++++++++--- process/database.go | 3 ++- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/network/clean.go b/network/clean.go index f3103142..87e66574 100644 --- a/network/clean.go +++ b/network/clean.go @@ -69,13 +69,16 @@ func cleanConnections() (activePIDs map[int]struct{}) { PID: process.UndefinedProcessID, }, now) - activePIDs[conn.process.Pid] = struct{}{} - + // Step 2: mark as ended if !exists { - // Step 2: mark end conn.Ended = nowUnix conn.Save() } + + // If the connection has an associated process, add its PID to the active PID list. + if conn.process != nil { + activePIDs[conn.process.Pid] = struct{}{} + } case conn.Ended < deleteOlderThan: // Step 3: delete // DEBUG: diff --git a/network/connection.go b/network/connection.go index 972a5c5b..78462bb2 100644 --- a/network/connection.go +++ b/network/connection.go @@ -656,14 +656,21 @@ func (conn *Connection) Failed(reason, reasonOptionKey string) { func (conn *Connection) SetVerdict(newVerdict Verdict, reason, reasonOptionKey string, reasonCtx interface{}) (ok bool) { conn.SetVerdictDirectly(newVerdict) + // Set reason and context. conn.Reason.Msg = reason conn.Reason.Context = reasonCtx + // Reset option key. conn.Reason.OptionKey = "" conn.Reason.Profile = "" - if reasonOptionKey != "" && conn.Process() != nil { - conn.Reason.OptionKey = reasonOptionKey - conn.Reason.Profile = conn.Process().Profile().GetProfileSource(conn.Reason.OptionKey) + + // Set option key if data is available. + if reasonOptionKey != "" { + lp := conn.Process().Profile() + if lp != nil { + conn.Reason.OptionKey = reasonOptionKey + conn.Reason.Profile = lp.GetProfileSource(conn.Reason.OptionKey) + } } return true // TODO: remove diff --git a/process/database.go b/process/database.go index 8ddffa14..08a7f225 100644 --- a/process/database.go +++ b/process/database.go @@ -111,7 +111,8 @@ func CleanProcessStorage(activePIDs map[int]struct{}) { // The PID of a process does not change. // Check if this is a special process. - if p.Pid == UnidentifiedProcessID || p.Pid == SystemProcessID { + switch p.Pid { + case UnidentifiedProcessID, UnsolicitedProcessID, SystemProcessID: p.profile.MarkStillActive() continue }