-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Description
What version of Go are you using (go version)?
tip
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env)?
GOOS=windows
GOARCH=amd64
What did you do?
Called ipv4.NewPacketConn with something that satisfies net.PacketConn but not net.Conn.
The code in NewPacketConn does a type assertion to net.Conn, without checking if the type satisfies it.
It's not documented that the parameter also needs to satisfy net.Conn.
See: https://github.com/golang/net/blob/master/ipv4/endpoint.go#L102-L110
Ideally NewPacketConn would return a conn, err, but that would be a breaking change, in which case the second best option would be for it to return a connection that fails the ok() checks of the genericOpt, dgramOpt and payloadHandler so that the connection returned would just return errInvalidConn for any operation.
Alternative would be to document that ipv4.NewPacketConn also needs to satisfy net.Conn.
What did you expect to see?
A connection returned, potentially one that returns an error on every operation.
What did you see instead?
A panic