mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: fixes use of possibly nil RemoteAddr() and LocalAddr() return values (#21076)
fixes: https://github.com/coder/internal/issues/1143 Both gVisor and the Go standard library implementations of `net.Conn` can under certain circumstances return `nil` for `RemoteAddr()` and `LocalAddr()` calls. If we call their methods, we segfault. This PR fixes these calls and adds ruleguard rules. Note that `slog.F("remote_addr", conn.RemoteAddr())` is fine because slog detects the `nil` before attempting to stringify the type.
This commit is contained in:
@@ -153,7 +153,9 @@ func freeUDPPort(t *testing.T) uint16 {
|
||||
})
|
||||
require.NoError(t, err, "listen on random UDP port")
|
||||
|
||||
_, port, err := net.SplitHostPort(l.LocalAddr().String())
|
||||
localAddr := l.LocalAddr()
|
||||
require.NotNil(t, localAddr, "local address is nil")
|
||||
_, port, err := net.SplitHostPort(localAddr.String())
|
||||
require.NoError(t, err, "split host port")
|
||||
|
||||
portUint, err := strconv.ParseUint(port, 10, 16)
|
||||
|
||||
Reference in New Issue
Block a user