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

Ignore packets with unknown dcid #48

Merged
merged 1 commit into from
Nov 23, 2023
Merged
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
29 changes: 25 additions & 4 deletions src/connection/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2745,10 +2745,8 @@ impl Connection {
info: &PacketInfo,
buf_len: usize,
) -> Result<usize> {
let (cid_seq, mut cid_pid) = self
.cids
.find_scid(dcid)
.ok_or(Error::InvalidState("unknown dcid".into()))?;
// Note: If the incoming packet carrys an unknown dcid, just ignore and drop it.
let (cid_seq, mut cid_pid) = self.cids.find_scid(dcid).ok_or(Error::Done)?;

// The incoming packet arrived on the existing path (for Client/Server).
if let Some(recv_pid) = recv_pid {
Expand Down Expand Up @@ -5500,6 +5498,29 @@ pub(crate) mod tests {
Ok(())
}

#[test]
fn recv_packet_unknown_dcid() -> Result<()> {
let mut test_pair = TestPair::new_with_test_config()?;
test_pair.handshake()?;

// Client send NEW_CONNECTION_ID
let (scid, reset_token) = (ConnectionId::random(), Some(1));
test_pair
.server
.cids
.add_scid(scid, reset_token, true, None, true)?;
let mut packets = TestPair::conn_packets_out(&mut test_pair.client)?;
assert!(!packets.is_empty());

// Tamper dcid field of the OneRTT packet
let (mut packet, info) = packets.pop().unwrap();
packet[1] = packet[1] + 1; // change first byte of dcid field

// Server drop the packet with unknown dcid
assert!(test_pair.server.recv(&mut packet, &info).is_ok());
Ok(())
}

#[test]
fn recv_packet_stream_frame() -> Result<()> {
let mut test_pair = TestPair::new_with_test_config()?;
Expand Down