Skip to content

Commit e93d77c

Browse files
committed
Reject DATAGRAMs larger than the send buffer
1 parent 9f0a163 commit e93d77c

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

quinn-proto/src/connection/datagrams.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ impl Datagrams<'_> {
3535
if data.len() > max {
3636
return Err(SendDatagramError::TooLarge);
3737
}
38+
if data.len() > self.conn.config.datagram_send_buffer_size {
39+
return Err(SendDatagramError::TooLarge);
40+
}
3841
if drop {
3942
self.conn
4043
.datagrams

quinn-proto/src/tests/mod.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2029,6 +2029,28 @@ fn datagram_recv_buffer_overflow() {
20292029
assert_matches!(pair.server_datagrams(server_ch).recv(), None);
20302030
}
20312031

2032+
#[test]
2033+
fn datagram_larger_than_send_buffer_is_too_large() {
2034+
let _guard = subscribe();
2035+
let mut pair = Pair::default();
2036+
let mut client_config = client_config();
2037+
let mut transport_config = TransportConfig::default();
2038+
transport_config.datagram_send_buffer_size(1);
2039+
client_config.transport_config(transport_config.into());
2040+
let (client_ch, _) = pair.connect_with(client_config);
2041+
2042+
assert_matches!(
2043+
pair.client_datagrams(client_ch)
2044+
.send(Bytes::from_static(&[0; 2]), true),
2045+
Err(SendDatagramError::TooLarge)
2046+
);
2047+
assert_matches!(
2048+
pair.client_datagrams(client_ch)
2049+
.send(Bytes::from_static(&[0; 2]), false),
2050+
Err(SendDatagramError::TooLarge)
2051+
);
2052+
}
2053+
20322054
#[test]
20332055
fn datagram_unsupported() {
20342056
let _guard = subscribe();

0 commit comments

Comments
 (0)