Skip to content

Commit bfa1cf1

Browse files
authored
fix(socks): check for right length before parsing ProxyRes (#210)
1 parent 0ea2613 commit bfa1cf1

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/client/legacy/connect/proxy/socks/v5/messages.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl TryFrom<&mut BytesMut> for ProxyRes {
172172
type Error = ParsingError;
173173

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

@@ -248,6 +248,7 @@ impl TryFrom<&mut BytesMut> for Address {
248248
}
249249

250250
Ok(match buf.get_u8() {
251+
// IPv4
251252
0x01 => {
252253
let mut ip = [0; 4];
253254

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

261262
Self::Socket(SocketAddr::new(ip.into(), port))
262263
}
263-
264+
// Domain
264265
0x03 => {
265266
let len = buf.get_u8();
266267

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

279280
Self::Domain(domain, port)
280281
}
281-
282+
// IPv6
282283
0x04 => {
283284
let mut ip = [0; 16];
284285

285-
if buf.remaining() < 6 {
286+
if buf.remaining() < 18 {
286287
return Err(ParsingError::Incomplete);
287288
}
288289
buf.copy_to_slice(&mut ip);

0 commit comments

Comments
 (0)