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

Fix crash in timesync code #68

Merged
merged 2 commits into from
Nov 22, 2023
Merged

Fix crash in timesync code #68

merged 2 commits into from
Nov 22, 2023

Conversation

cfergeau
Copy link
Collaborator

When ConnectVSockSync fails in watchWakeupNotifications(), the returned
net.Conn contains a nil value, but is not a nil interface
(ie checking it for == nil returns false). This means we'll try to call
Close() on the connection, which will cause a nil pointer dereference.
See https://go.dev/doc/faq#nil_error and
https://groups.google.com/g/golang-nuts/c/wnH302gBa4I for details about
this behaviour.

This bug is fixed by returning a nil interface when
vsockDevice.Connect(uint32(port)) returns an error.

When ConnectVSockSync fails in watchWakeupNotifications(),
the returned net.Conn contains a nil value, but is not a nil interface
(ie checking it for `== nil` returns false).
This means we'll try to call `Close()` on the connection, which will
cause a nil pointer dereference.
See https://go.dev/doc/faq#nil_error and https://groups.google.com/g/golang-nuts/c/wnH302gBa4I
for details about this behaviour.

This bug is fixed by returning a nil interface when
`vsockDevice.Connect(uint32(port))` returns an error.
// checking the return value for nil won't work as expected if we don't do this
return nil, err
}
return conn, nil
Copy link
Member

Choose a reason for hiding this comment

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

👍🏼

@praveenkumar
Copy link
Member

/lgtm
/approve

Copy link

openshift-ci bot commented Nov 22, 2023

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: praveenkumar
Once this PR has been reviewed and has the lgtm label, please ask for approval from cfergeau. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@praveenkumar praveenkumar merged commit 7572104 into crc-org:main Nov 22, 2023
4 of 5 checks passed
@cfergeau cfergeau deleted the nil-iface branch November 23, 2023 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants