From 82b8ace344052b854528e945d9a499e599eae887 Mon Sep 17 00:00:00 2001 From: Jay Mundrawala Date: Sat, 20 Jan 2024 06:08:22 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20port=20resource=20panic=20?= =?UTF-8?q?(#3076)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It is possible for the port resource to panic on mac and windows if the process is requested. This can happen because we query for all the processes first, then we query for ports which gets us process ids. A new process showing up between the first and second queries can cause the panic to happen. Linux has a similar check --- providers/os/resources/port.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/providers/os/resources/port.go b/providers/os/resources/port.go index 5b97638e7c..ad8c486e01 100644 --- a/providers/os/resources/port.go +++ b/providers/os/resources/port.go @@ -508,6 +508,11 @@ func (p *mqlPorts) parseWindowsPorts(r io.Reader, processes map[int64]*mqlProces return nil, err } + portObj := obj.(*mqlPort) + if process == nil { + portObj.Process.State = plugin.StateIsSet | plugin.StateIsNull + } + res = append(res, obj) } return res, nil @@ -596,6 +601,10 @@ func (p *mqlPorts) listMacos() ([]interface{}, error) { log.Error().Err(err).Send() return nil, err } + portObj := obj.(*mqlPort) + if mqlProcess == nil { + portObj.Process.State = plugin.StateIsSet | plugin.StateIsNull + } res = append(res, obj) }