From 68bac01fb175db4b5329facc76dfd0fde509f8b1 Mon Sep 17 00:00:00 2001 From: thekuwayama Date: Thu, 1 Sep 2022 06:13:07 +0900 Subject: [PATCH 1/2] Check QUIC Bit that Short Header Packet set too --- quinn-proto/src/packet.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/quinn-proto/src/packet.rs b/quinn-proto/src/packet.rs index 81486e14d..e537887f5 100644 --- a/quinn-proto/src/packet.rs +++ b/quinn-proto/src/packet.rs @@ -536,6 +536,9 @@ impl PlainHeader { grease_quic_bit: bool, ) -> Result { let first = buf.get::()?; + if !grease_quic_bit && first & FIXED_BIT == 0 { + return Err(PacketDecodeError::InvalidHeader("fixed bit unset")); + } if first & LONG_HEADER_FORM == 0 { let spin = first & SPIN_BIT != 0; if buf.remaining() < local_cid_len { @@ -721,9 +724,6 @@ pub(crate) enum LongHeaderType { impl LongHeaderType { fn from_byte(b: u8, grease_quic_bit: bool) -> Result { use self::{LongHeaderType::*, LongType::*}; - if !grease_quic_bit && b & FIXED_BIT == 0 { - return Err(PacketDecodeError::InvalidHeader("fixed bit unset")); - } debug_assert!(b & LONG_HEADER_FORM != 0, "not a long packet"); Ok(match (b & 0x30) >> 4 { 0x0 => Initial, From 22404d7bc6ce38f359e20c793e8e82c78d977a96 Mon Sep 17 00:00:00 2001 From: thekuwayama Date: Thu, 1 Sep 2022 06:51:19 +0900 Subject: [PATCH 2/2] rm unnecessary arguments --- quinn-proto/src/packet.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/quinn-proto/src/packet.rs b/quinn-proto/src/packet.rs index e537887f5..6ab361f2c 100644 --- a/quinn-proto/src/packet.rs +++ b/quinn-proto/src/packet.rs @@ -575,7 +575,7 @@ impl PlainHeader { }); } - match LongHeaderType::from_byte(first, grease_quic_bit)? { + match LongHeaderType::from_byte(first)? { LongHeaderType::Initial => { let token_len = buf.get_var()? as usize; let token_start = buf.position() as usize; @@ -722,7 +722,7 @@ pub(crate) enum LongHeaderType { } impl LongHeaderType { - fn from_byte(b: u8, grease_quic_bit: bool) -> Result { + fn from_byte(b: u8) -> Result { use self::{LongHeaderType::*, LongType::*}; debug_assert!(b & LONG_HEADER_FORM != 0, "not a long packet"); Ok(match (b & 0x30) >> 4 {