From f07afb8c85171dc5148787cf859729d0197a3279 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sun, 6 May 2018 01:06:17 +0200 Subject: [PATCH] manage invalid error code (size=1) and too long reason (size>125) --- ws/client.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/ws/client.go b/ws/client.go index 999555b..7a42604 100644 --- a/ws/client.go +++ b/ws/client.go @@ -156,12 +156,14 @@ func clientReader(c *client){ /* (4) CLOSE */ if msg.Type == CLOSE { - // fmt.Printf(" [reader] CLOSE ; size %d\n", msg.Size) - // if msg.Size >= 2 { - // errCode := binary.BigEndian.Uint16(msg.Data[0:2]) - // fmt.Printf(" ; status %d\n", errCode) - // fmt.Printf(" ; msg '%s'\n", msg.Data[2:]) - // } + // uncomplete code || too long + if msg.Size == 1 || msg.Size > 125 { + errorCode = PROTOCOL_ERR + } + // invalid utf-8 reason + if msg.Size > 2 && !utf8.Valid(msg.Data[2:]) { + errorCode = INVALID_PAYLOAD + } clientAck = false break