Skip to content

fix(socks): check for right length before parsing ProxyRes #210

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

Merged
merged 1 commit into from
Jul 7, 2025
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
9 changes: 5 additions & 4 deletions src/client/legacy/connect/proxy/socks/v5/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ impl TryFrom<&mut BytesMut> for ProxyRes {
type Error = ParsingError;

fn try_from(buf: &mut BytesMut) -> Result<Self, ParsingError> {
if buf.remaining() < 2 {
if buf.remaining() < 3 {
return Err(ParsingError::Incomplete);
}

Expand Down Expand Up @@ -248,6 +248,7 @@ impl TryFrom<&mut BytesMut> for Address {
}

Ok(match buf.get_u8() {
// IPv4
0x01 => {
let mut ip = [0; 4];

Expand All @@ -260,7 +261,7 @@ impl TryFrom<&mut BytesMut> for Address {

Self::Socket(SocketAddr::new(ip.into(), port))
}

// Domain
0x03 => {
let len = buf.get_u8();

Expand All @@ -278,11 +279,11 @@ impl TryFrom<&mut BytesMut> for Address {

Self::Domain(domain, port)
}

// IPv6
0x04 => {
let mut ip = [0; 16];

if buf.remaining() < 6 {
if buf.remaining() < 18 {
return Err(ParsingError::Incomplete);
}
buf.copy_to_slice(&mut ip);
Expand Down