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

eX0-go/net.go: sendUDPPacketBytes: Investigate/confirm possible misuse of Read method. #8

Open
dmitshur opened this issue Jun 9, 2016 · 6 comments

Comments

@dmitshur
Copy link
Member

dmitshur commented Jun 9, 2016

@@ -94,6 +94,8 @@ func sendUDPPacketBytes(c *Connection, b []byte) error {
 func receiveUDPPacket(c *Connection) ([]byte, packet.UDPHeader, error) {
    var b [packet.MAX_UDP_SIZE]byte
    n, err := c.udp.Read(b[:])
+   // TODO: Use io.ReadFull or check b[n:] here? But it is UDP, so... Figure it out.
+   //       Maybe it's fine because it's Conn.Read, not io.Read?
    if err != nil {
        return nil, packet.UDPHeader{}, err
    }

Originally reported/found by @dominikh.

@dmitshur
Copy link
Member Author

I'm not seeing a check that would report this in the latest version of staticcheck or anywhere. @dominikh, do you know/remember what happened to it? Is it still valid, or did you find some evidence otherwise?

@dominikh
Copy link

Same as in 2016: you don't need ReadFull because it's UDP, which is message based. You get a message or you don't, you don't get partial messages. You do need to use n because you don't know the size of the message ahead of time.

@dmitshur
Copy link
Member Author

dmitshur commented May 13, 2017

you don't need ReadFull because it's UDP, which is message based.

Yes, that's what assumed when I wrote the code, and it seems to work without issues. But it goes through an io.Reader-like interface (a subset of net.Conn), and I don't see any guarantees in docs of net.UDPConn.Read about a 1:1 mapping between packets and Read calls, I can't completely dismiss the possibility of a non-1:1 mapping (e.g., due to internal buffering, etc.).

I might raise an issue about it in the Go issue tracker then.

To be clear, I know how UDP packets work. I don't have full confidence on what happens when they go through io.Reader interface unless I see it written in docs.

@dominikh
Copy link

It's not "going through io.Reader", io.Reader isn't some entity sitting between your connection and you, messing with your data. And UDPConn implements net.Conn, not io.Reader. That aside, if it did split up UDP messages, it would be a 100% broken implementation and still not your concern.

But really, we've had this discussion a year ago, check your logs :-)

@dmitshur
Copy link
Member Author

Is that why this never made it into a production-ready staticcheck check?

@dominikh
Copy link

Depends what you mean by "this". Not complaining about the early error check is probably because of UDP though. I don't recall all the details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants