Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and test validation of IDCID length #1976

Merged
merged 1 commit into from
Aug 31, 2024
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
4 changes: 2 additions & 2 deletions quinn-proto/src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,8 +706,8 @@ impl Endpoint {
// length. If we ever issue non-Retry address validation tokens via `NEW_TOKEN`, then we'll
// also need to validate CID length for those after decoding the token.
if header.dst_cid.len() < 8
&& (!header.token_pos.is_empty()
&& header.dst_cid.len() != self.local_cid_generator.cid_len())
&& (header.token_pos.is_empty()
|| header.dst_cid.len() != self.local_cid_generator.cid_len())
{
debug!(
"rejecting connection due to invalid DCID length {}",
Expand Down
23 changes: 22 additions & 1 deletion quinn-proto/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
};

use assert_matches::assert_matches;
use bytes::Bytes;
use bytes::{Bytes, BytesMut};
use hex_literal::hex;
use rand::RngCore;
use ring::hmac;
Expand Down Expand Up @@ -3143,3 +3143,24 @@ fn voluntary_ack_with_large_datagrams() {
"client should have sent some ACK-only packets"
);
}

#[test]
fn reject_short_idcid() {
let _guard = subscribe();
let client_addr = "[::2]:7890".parse().unwrap();
let mut server = Endpoint::new(
Default::default(),
Some(Arc::new(server_config())),
true,
None,
);
let now = Instant::now();
let mut buf = Vec::with_capacity(server.config().get_max_udp_payload_size() as usize);
// Initial header that has an empty DCID but is otherwise well-formed
let mut initial = BytesMut::from(hex!("c4 00000001 00 00 00 3f").as_ref());
initial.resize(MIN_INITIAL_SIZE.into(), 0);
let event = server.handle(now, client_addr, None, None, initial, &mut buf);
let Some(DatagramEvent::Response(Transmit { .. })) = event else {
panic!("expected an initial close");
};
}