Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/codec/framed_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ fn decode_frame(
.into()
}
Kind::GoAway => {
let res = frame::GoAway::load(&bytes[frame::HEADER_LEN..]);
let res = frame::GoAway::load(head, &bytes[frame::HEADER_LEN..]);
res.map_err(|e| {
proto_err!(conn: "failed to load GO_AWAY frame; err={:?}", e);
Error::library_go_away(Reason::PROTOCOL_ERROR)
Expand Down
12 changes: 11 additions & 1 deletion src/frame/go_away.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,17 @@ impl GoAway {
&self.debug_data
}

pub fn load(payload: &[u8]) -> Result<GoAway, Error> {
pub fn load(head: Head, payload: &[u8]) -> Result<GoAway, Error> {
debug_assert_eq!(head.kind(), crate::frame::Kind::GoAway);

// The GOAWAY frame applies to the connection, not a specific stream.
// An endpoint MUST treat a GOAWAY frame with a stream identifier
// other than 0x00 as a connection error (Section 5.4.1) of type
// PROTOCOL_ERROR.
if !head.stream_id().is_zero() {
return Err(Error::InvalidStreamId);
}

if payload.len() < 8 {
return Err(Error::BadFrameSize);
}
Expand Down
4 changes: 2 additions & 2 deletions src/frame/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ pub enum Error {

/// An invalid stream identifier was provided.
///
/// This is returned if a SETTINGS or PING frame is received with a stream
/// identifier other than zero.
/// This is returned if a SETTINGS, PING or GOAWAY frame is received with a
/// stream identifier other than zero.
InvalidStreamId,

/// A request or response is malformed.
Expand Down
16 changes: 16 additions & 0 deletions tests/h2-tests/tests/codec_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,19 @@ async fn read_goaway_with_debug_data() {

assert_closed!(codec);
}

#[tokio::test]
async fn read_goaway_stream_id_not_zero() {
let mut codec = raw_codec! {
read => [
// head, stream id 1
0, 0, 8, 7, 0, 0, 0, 0, 1,
// last_stream_id
0, 0, 0, 0,
// error_code
0, 0, 0, 0,
];
};

poll_err!(codec);
}