diff options
| author | Shulhan <ms@kilabit.info> | 2019-03-15 17:52:45 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2019-03-17 02:06:21 +0700 |
| commit | 3847b56ed8a02be6197362fa378b66829e926f04 (patch) | |
| tree | f1ce91d0ae9b5084aa086f58c889fa3279e0e594 | |
| parent | 7f5f3d32944d0cc997120e9ff010f4166fcb3530 (diff) | |
| download | pakakeh.go-3847b56ed8a02be6197362fa378b66829e926f04.tar.xz | |
websocket: do not cut the close code bytes from frame's payload
For control CLOSE frame, the frame's length, close code, and payload are
all related. For example, the length of 2 indicate that there is a close
code in payload.
This change only affect test when unpacking close frame, and does not
affect the result of autobahn test.
| -rw-r--r-- | lib/websocket/frame.go | 1 | ||||
| -rw-r--r-- | lib/websocket/frame_test.go | 4 | ||||
| -rw-r--r-- | lib/websocket/server.go | 4 |
3 files changed, 5 insertions, 4 deletions
diff --git a/lib/websocket/frame.go b/lib/websocket/frame.go index eb52f61c..2bff7335 100644 --- a/lib/websocket/frame.go +++ b/lib/websocket/frame.go @@ -317,7 +317,6 @@ func frameUnpack(in []byte) (f *Frame, rest []byte) { default: f.codes = []byte{f.payload[0], f.payload[1]} f.closeCode = CloseCode(binary.BigEndian.Uint16(f.payload[:2])) - f.payload = f.payload[2:] } } diff --git a/lib/websocket/frame_test.go b/lib/websocket/frame_test.go index ea6ae0f8..4cca0beb 100644 --- a/lib/websocket/frame_test.go +++ b/lib/websocket/frame_test.go @@ -64,7 +64,7 @@ func TestNewFrameClose(t *testing.T) { opcode: OpcodeClose, closeCode: StatusBadRequest, masked: frameIsMasked, - payload: []byte("Hello!"), + payload: libbytes.Concat([]byte{0x03, 0xEA}, []byte("Hello!")), }, }, { desc: "With overflow payload", @@ -74,7 +74,7 @@ func TestNewFrameClose(t *testing.T) { opcode: OpcodeClose, closeCode: StatusBadRequest, masked: frameIsMasked, - payload: _dummyPayload256[:123], + payload: libbytes.Concat([]byte{0x03, 0xEA}, _dummyPayload256[:123]), }, }} diff --git a/lib/websocket/server.go b/lib/websocket/server.go index 4b3715e4..988a24c5 100644 --- a/lib/websocket/server.go +++ b/lib/websocket/server.go @@ -609,7 +609,9 @@ func (serv *Server) handleClose(conn int, req *Frame) { // The interpretation of these codes is undefined by this // protocol. } - if len(req.payload) > 0 { + if len(req.payload) >= 2 { + // Cut the close code from actual payload. + req.payload = req.payload[2:] if !utf8.Valid(req.payload) { req.closeCode = StatusBadRequest } |
