Skip to content

Commit

Permalink
🐛 Fix port resource panic (#3076)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jaym authored Jan 20, 2024
1 parent 4198bb6 commit 82b8ace
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions providers/os/resources/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 82b8ace

Please sign in to comment.