Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
KershawChang committed Mar 12, 2024
1 parent baa9b52 commit a4db844
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
5 changes: 4 additions & 1 deletion neqo-transport/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1937,8 +1937,11 @@ impl Connection {
};

let path = close.path().borrow();
// In some error cases, we will not be able to make a new, permanent path.
// For example, if we run out of connection IDs and the error results from
// a packet on a new path, we avoid sending (and the privacy risk) rather
// than reuse a connection ID.
if path.is_temporary() {
debug_assert!(false, "Path is not permanent");
return Err(Error::InternalError);
}
let (_, mut builder) = Self::build_packet_header(
Expand Down
41 changes: 41 additions & 0 deletions neqo-transport/src/connection/tests/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use std::{
cell::RefCell,
mem,
net::{IpAddr, Ipv6Addr, SocketAddr},
rc::Rc,
time::{Duration, Instant},
Expand Down Expand Up @@ -950,3 +951,43 @@ fn retire_prior_to_migration_success() {
assert_ne!(get_cid(&dgram), original_cid);
assert_ne!(get_cid(&dgram), probe_cid);
}

struct GarbageWriter {}

impl crate::connection::test_internal::FrameWriter for GarbageWriter {
fn write_frames(&mut self, builder: &mut PacketBuilder) {
builder.encode_varint(u32::MAX);
}
}

/// Test the case that we run out of connection ID and receive an invalid frame
/// from a new path.
#[test]
fn error_on_new_path_with_no_connection_id() {
let mut client = default_client();
let mut server = default_server();
connect_force_idle(&mut client, &mut server);

let dgram = send_something(&mut server, now());
let dgram = change_path(&dgram, DEFAULT_ADDR_V4);
client.process_input(&dgram, now());

let cid_gen: Rc<RefCell<dyn ConnectionIdGenerator>> =
Rc::new(RefCell::new(CountingConnectionIdGenerator::default()));
server.test_frame_writer = Some(Box::new(RetireAll { cid_gen }));
let retire_all = send_something(&mut server, now());
server.test_frame_writer = None;

client.process_input(&retire_all, now());

server.test_frame_writer = Some(Box::new(GarbageWriter {}));
let garbage = send_something(&mut server, now());
server.test_frame_writer = None;

let dgram = change_path(&garbage, DEFAULT_ADDR_V4);
client.process_input(&dgram, now());

// See issue #1697. We had a crash when the client had a temporary path and
// process_output is called.
mem::drop(client.process_output(now()));
}

0 comments on commit a4db844

Please sign in to comment.