golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.21k stars 17.57k forks source link

x/net/websocket: protocol implementation fails to respond to PingFrame without payload #7825

Closed gopherbot closed 9 years ago

gopherbot commented 10 years ago

by opennota:

RFC 6455 states, that Ping frame payload is optional:

    https://tools.ietf.org/html/rfc6455#section-5.5.2:

    A Ping frame MAY include "Application data".

However, the protocol implementation reads a frame using io.ReadFull, that returns
io.EOF error, if no bytes are read, and this io.EOF is treated as an error on the next
line.

The following patch solves this issue:

--- hybi.go.backup      2014-04-20 17:03:27.811047258 +0700
+++ hybi.go     2014-04-20 17:30:58.371147981 +0700
@@ -291,7 +291,7 @@
        case PingFrame:
                pingMsg := make([]byte, maxControlFramePayloadLength)
                n, err := io.ReadFull(frame, pingMsg)
-               if err != nil && err != io.ErrUnexpectedEOF {
+               if err != nil && err != io.ErrUnexpectedEOF && err !=
io.EOF {
                        return nil, err
                }                                                                                                    
                io.Copy(ioutil.Discard, frame)
ianlancetaylor commented 10 years ago

Comment 1:

Please submit patches using the procedure documented in
http://golang.org/doc/contribute.html .  Thanks.

Labels changed: added repo-net, release-none.

gopherbot commented 9 years ago

CL https://golang.org/cl/13054 mentions this issue.