From 3b4c86bce2afb2f65fbe2a60a026c70617362355 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=A3rebe=20-=20Romain=20GERARD?= Date: Tue, 23 Jan 2024 11:50:57 +0100 Subject: [PATCH] fix(socks5 udp): correctly reserve enough space for new packets --- src/socks5_udp.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/socks5_udp.rs b/src/socks5_udp.rs index d438a24..3bdb054 100644 --- a/src/socks5_udp.rs +++ b/src/socks5_udp.rs @@ -9,7 +9,7 @@ use std::io::{Error, ErrorKind}; use std::net::SocketAddr; use crate::tunnel::to_host_port; -use bytes::{Buf, BufMut, Bytes, BytesMut}; +use bytes::{Buf, Bytes, BytesMut}; use fast_socks5::new_udp_header; use fast_socks5::util::target_addr::TargetAddr; use log::warn; @@ -229,9 +229,7 @@ pub async fn run_server( let stream = stream::unfold((udp_server, buffer), |(mut server, mut buf)| async move { loop { server.clean_dead_keys(); - if buf.remaining_mut() < MAX_PACKET_LENGTH { - buf.reserve(MAX_PACKET_LENGTH); - } + buf.reserve(MAX_PACKET_LENGTH); let peer_addr = match server.listener.recv_buf_from(&mut buf).await { Ok((_read_len, peer_addr)) => peer_addr,