From b5b91fce05de177f7d938ae67d555e8f357dec51 Mon Sep 17 00:00:00 2001 From: Maciej Hirsz Date: Tue, 5 Nov 2019 17:15:53 +0100 Subject: [PATCH] Log errors --- actix-http/src/ws/codec.rs | 12 ++++++++++-- actix-http/src/ws/frame.rs | 6 ++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/actix-http/src/ws/codec.rs b/actix-http/src/ws/codec.rs index 9891bfa6e..2e2741724 100644 --- a/actix-http/src/ws/codec.rs +++ b/actix-http/src/ws/codec.rs @@ -104,13 +104,21 @@ impl Decoder for Codec { Ok(Some((finished, opcode, payload))) => { // continuation is not supported if !finished { + error!("No continuation 1"); return Err(ProtocolError::NoContinuation); } match opcode { - OpCode::Continue => Err(ProtocolError::NoContinuation), - OpCode::Bad => Err(ProtocolError::BadOpCode), + OpCode::Continue => { + error!("No continuation 2"); + Err(ProtocolError::NoContinuation) + } + OpCode::Bad => { + error!("Bad opcode"); + Err(ProtocolError::BadOpCode) + } OpCode::Close => { + warn!("Got a close frame!"); if let Some(ref pl) = payload { let close_reason = Parser::parse_close_payload(pl); Ok(Some(Frame::Close(close_reason))) diff --git a/actix-http/src/ws/frame.rs b/actix-http/src/ws/frame.rs index 46e9f36db..c45785807 100644 --- a/actix-http/src/ws/frame.rs +++ b/actix-http/src/ws/frame.rs @@ -32,8 +32,10 @@ impl Parser { // check masking let masked = second & 0x80 != 0; if !masked && server { + error!("Protocol unmasked frame"); return Err(ProtocolError::UnmaskedFrame); } else if masked && !server { + error!("Protocol masked frame"); return Err(ProtocolError::MaskedFrame); } @@ -41,6 +43,7 @@ impl Parser { let opcode = OpCode::from(first & 0x0F); if let OpCode::Bad = opcode { + error!("Protocol invalid opcode"); return Err(ProtocolError::InvalidOpcode(first & 0x0F)); } @@ -60,6 +63,7 @@ impl Parser { } let len = u64::from_be_bytes(TryFrom::try_from(&src[idx..idx + 8]).unwrap()); if len > max_size as u64 { + error!("Protocol overflow 1"); return Err(ProtocolError::Overflow); } idx += 8; @@ -70,6 +74,7 @@ impl Parser { // check for max allowed size if length > max_size { + error!("Protocol overflow 2"); return Err(ProtocolError::Overflow); } @@ -120,6 +125,7 @@ impl Parser { // control frames must have length <= 125 match opcode { OpCode::Ping | OpCode::Pong if length > 125 => { + error!("Protocol invalid length"); return Err(ProtocolError::InvalidLength(length)); } OpCode::Close if length > 125 => {