From 5528cf62f05397087ba3140206f9f418556e565d Mon Sep 17 00:00:00 2001 From: Nathan Fox Date: Fri, 20 Apr 2018 21:30:18 -0400 Subject: [PATCH] check if close code exists before reading it --- src/ws/mod.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/ws/mod.rs b/src/ws/mod.rs index 97162b19a..f79f3f77a 100644 --- a/src/ws/mod.rs +++ b/src/ws/mod.rs @@ -310,10 +310,14 @@ where } OpCode::Close => { self.closed = true; - let code = NetworkEndian::read_uint(payload.as_ref(), 2) as u16; - Ok(Async::Ready(Some(Message::Close(CloseCode::from( - code, - ))))) + let close_code = if payload.len() >= 2{ + let raw_code = NetworkEndian::read_uint(payload.as_ref(), 2) as u16; + CloseCode::from(raw_code) + }else{ + CloseCode::Status + }; + + Ok(Async::Ready(Some(Message::Close(close_code)))) } OpCode::Ping => Ok(Async::Ready(Some(Message::Ping( String::from_utf8_lossy(payload.as_ref()).into(),