Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Ensure asset platform is not nil in sysinfo. #3974

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion providers-sdk/v1/sysinfo/sysinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
package sysinfo

import (
"errors"

"github.com/rs/zerolog/log"

"go.mondoo.com/cnquery/v11"
"go.mondoo.com/cnquery/v11/cli/execruntime"
"go.mondoo.com/cnquery/v11/providers-sdk/v1/inventory"
"go.mondoo.com/cnquery/v11/providers/os/connection/local"
"go.mondoo.com/cnquery/v11/providers/os/detector"
"go.mondoo.com/cnquery/v11/providers/os/id"
"go.mondoo.com/cnquery/v11/providers/os/id/hostname"
"go.mondoo.com/cnquery/v11/providers/os/resources/networkinterface"
Expand Down Expand Up @@ -51,8 +54,17 @@ func Get() (*SystemInfo, error) {
}
}

sysInfo.Platform = platform
// FIXME: if IdentifyPlatform returns an err, we get a nil platform this will cause a nil pointer dereference in the next step (hostname)
// FIXME: we should ensure IdentifyPlatform's error is handled properly
if platform == nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to gracefully handle the case that we cannot retrieve the sys info. While not optimal, we should not stop execution when we cannot determine the host platform.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am closing this PR as it's not needed anymore for the use case it was trying to fix

var ok bool
platform, ok = detector.DetectOS(conn)
if !ok {
return nil, errors.New("failed to detect the OS")
}
}

sysInfo.Platform = platform
sysInfo.Hostname, _ = hostname.Hostname(conn, sysInfo.Platform)

// determine ip address
Expand Down
Loading