Skip to content

Commit f19a643

Browse files
cfergeaupraveenkumar
authored andcommitted
Fix crash in timesync code
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.
1 parent 2a4d725 commit f19a643

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

pkg/vf/vsock.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ func ConnectVsockSync(vm *vz.VirtualMachine, port uint) (net.Conn, error) {
2525
}
2626
vsockDevice := socketDevices[0]
2727

28-
return vsockDevice.Connect(uint32(port))
28+
conn, err := vsockDevice.Connect(uint32(port))
29+
if err != nil {
30+
// we can't `return vsockDevice.Connect()` directly, see https://go.dev/doc/faq#nil_error
31+
// checking the return value for nil won't work as expected if we don't do this
32+
return nil, err
33+
}
34+
return conn, nil
2935
}
3036

3137
// connectVsock proxies connections from a host unix socket to a vsock port

0 commit comments

Comments
 (0)