Skip to content

Commit c292a3c

Browse files
committed
Fix and test validation of IDCID length
1 parent bb02a12 commit c292a3c

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

quinn-proto/src/endpoint.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -706,8 +706,8 @@ impl Endpoint {
706706
// length. If we ever issue non-Retry address validation tokens via `NEW_TOKEN`, then we'll
707707
// also need to validate CID length for those after decoding the token.
708708
if header.dst_cid.len() < 8
709-
&& (!header.token_pos.is_empty()
710-
&& header.dst_cid.len() != self.local_cid_generator.cid_len())
709+
&& (header.token_pos.is_empty()
710+
|| header.dst_cid.len() != self.local_cid_generator.cid_len())
711711
{
712712
debug!(
713713
"rejecting connection due to invalid DCID length {}",

quinn-proto/src/tests/mod.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::{
77
};
88

99
use assert_matches::assert_matches;
10-
use bytes::Bytes;
10+
use bytes::{Bytes, BytesMut};
1111
use hex_literal::hex;
1212
use rand::RngCore;
1313
use ring::hmac;
@@ -3143,3 +3143,24 @@ fn voluntary_ack_with_large_datagrams() {
31433143
"client should have sent some ACK-only packets"
31443144
);
31453145
}
3146+
3147+
#[test]
3148+
fn reject_short_idcid() {
3149+
let _guard = subscribe();
3150+
let client_addr = "[::2]:7890".parse().unwrap();
3151+
let mut server = Endpoint::new(
3152+
Default::default(),
3153+
Some(Arc::new(server_config())),
3154+
true,
3155+
None,
3156+
);
3157+
let now = Instant::now();
3158+
let mut buf = Vec::with_capacity(server.config().get_max_udp_payload_size() as usize);
3159+
// Initial header that has an empty DCID but is otherwise well-formed
3160+
let mut initial = BytesMut::from(hex!("c4 00000001 00 00 00 3f").as_ref());
3161+
initial.resize(MIN_INITIAL_SIZE.into(), 0);
3162+
let event = server.handle(now, client_addr, None, None, initial, &mut buf);
3163+
let Some(DatagramEvent::Response(Transmit { .. })) = event else {
3164+
panic!("expected an initial close");
3165+
};
3166+
}

0 commit comments

Comments
 (0)