From 15f6dfd2c11957cd8fe73d686377fb1fbdf0ede9 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Fri, 25 Aug 2017 22:54:54 -0400 Subject: [PATCH] Handle invalid stream deps with RST_STREAM --- src/proto/framed_read.rs | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/proto/framed_read.rs b/src/proto/framed_read.rs index 7146a76..a58d2e5 100644 --- a/src/proto/framed_read.rs +++ b/src/proto/framed_read.rs @@ -101,7 +101,16 @@ impl FramedRead { // Parse the header frame w/o parsing the payload let (mut headers, payload) = match frame::Headers::load(head, bytes) { Ok(res) => res, - Err(_) => unimplemented!(), + Err(frame::Error::InvalidDependencyId) => { + // A stream cannot depend on itself. An endpoint MUST + // treat this as a stream error (Section 5.4.2) of type + // `PROTOCOL_ERROR`. + return Err(Stream { + id: head.stream_id(), + reason: ProtocolError, + }); + } + _ => return Err(Connection(ProtocolError)), }; if headers.is_end_headers() { @@ -141,8 +150,19 @@ impl FramedRead { res.map_err(|_| Connection(ProtocolError))?.into() } Kind::Priority => { - let res = frame::Priority::load(head, &bytes[frame::HEADER_LEN..]); - res.map_err(|_| Connection(ProtocolError))?.into() + match frame::Priority::load(head, &bytes[frame::HEADER_LEN..]) { + Ok(frame) => frame.into(), + Err(frame::Error::InvalidDependencyId) => { + // A stream cannot depend on itself. An endpoint MUST + // treat this as a stream error (Section 5.4.2) of type + // `PROTOCOL_ERROR`. + return Err(Stream { + id: head.stream_id(), + reason: ProtocolError, + }); + } + Err(_) => return Err(Connection(ProtocolError)), + } } Kind::Continuation => { // TODO: Un-hack this