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

Nil pointer safety #408

Merged
merged 2 commits into from
Dec 14, 2024
Merged

Conversation

jacobweinstock
Copy link
Member

What does this PR implement/change/remove?

Fix bug introduced by #402. This PR handles errors properly and adds some nil checking in the bmc package. By ignoring an error and returning nil objects it causespanic: runtime error: invalid memory address or nil pointer dereference for clients.

Checklist

  • Tests added
  • Similar commits squashed

The HW vendor this change applies to (if applicable)

The HW model number, product name this change applies to (if applicable)

The BMC firmware and/or BIOS versions that this change applies to (if applicable)

What version of tooling - vendor specific or opensource does this change depend on (if applicable)

Description for changelog/release notes

Ignoring an error and returning nil objects causes
`panic: runtime error: invalid memory address or nil pointer
dereference` issues.

Signed-off-by: Jacob Weinstock <[email protected]>
A recent bug showed that a nil is still a type
so type asserting a nil will still work. We add
a nil check so that methods on interfaces don't
get called when the interface/implementation is nil.

Signed-off-by: Jacob Weinstock <[email protected]>
sc := &serviceClient{host: host, port: port, user: user, pass: pass, client: client}

if !strings.HasPrefix(host, "https://") && !strings.HasPrefix(host, "http://") {
sc.host = "https://" + host
}

// sum is only for firmware related operations. Failing the client entirely because of a sum error
Copy link
Member

Choose a reason for hiding this comment

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

The sum code can be removed entirely since bmclib was 'hard' forked (for the environment where sum was required to run remotely). I'll get round to cleaning this up sometime soon.

Copy link
Member

@joelrebel joelrebel left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this up

@mergify mergify bot merged commit adcf7f1 into bmc-toolbox:main Dec 14, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants