From 68b3db0b458fe10a283f137ce45c22de7b78cfcd Mon Sep 17 00:00:00 2001 From: Benjamin Saunders Date: Tue, 30 Jul 2024 18:08:26 -0700 Subject: [PATCH] Fix initial destination CID leak for retry packets This could also cause other packets received before the server accepts the connection to be lost. --- quinn-proto/src/endpoint.rs | 2 +- quinn-proto/src/tests/mod.rs | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/quinn-proto/src/endpoint.rs b/quinn-proto/src/endpoint.rs index 2ee9dae569..1e0d77f958 100644 --- a/quinn-proto/src/endpoint.rs +++ b/quinn-proto/src/endpoint.rs @@ -531,7 +531,7 @@ impl Endpoint { let incoming_idx = self.incoming_buffers.insert(IncomingBuffer::default()); self.index - .insert_initial_incoming(orig_dst_cid, incoming_idx); + .insert_initial_incoming(header.dst_cid, incoming_idx); Some(DatagramEvent::NewConnection(Incoming { addresses, diff --git a/quinn-proto/src/tests/mod.rs b/quinn-proto/src/tests/mod.rs index 272bf38544..f67ab75ab2 100644 --- a/quinn-proto/src/tests/mod.rs +++ b/quinn-proto/src/tests/mod.rs @@ -172,7 +172,17 @@ fn stateless_retry() { let _guard = subscribe(); let mut pair = Pair::default(); pair.server.incoming_connection_behavior = IncomingConnectionBehavior::Validate; - pair.connect(); + let (client_ch, _server_ch) = pair.connect(); + pair.client + .connections + .get_mut(&client_ch) + .unwrap() + .close(pair.time, VarInt(42), Bytes::new()); + pair.drive(); + assert_eq!(pair.client.known_connections(), 0); + assert_eq!(pair.client.known_cids(), 0); + assert_eq!(pair.server.known_connections(), 0); + assert_eq!(pair.server.known_cids(), 0); } #[test]