Skip to content

Commit 9335259

Browse files
committed
socks5: read remanining data from stream upon failure
1 parent f49d780 commit 9335259

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

socks5-client/src/lib.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub enum Socks5 {
7171
Awaiting,
7272
Reading(u8, u8),
7373
Active(NetAddr<HostName>),
74-
Rejected(ServerError),
74+
Rejected(ServerError, u8, u8),
7575
Failed(Error),
7676
}
7777

@@ -116,10 +116,10 @@ impl Socks5 {
116116
}
117117
if input[1] != 0x00 {
118118
let err = ServerError::from(input[1]);
119-
*self = Socks5::Rejected(err);
120-
return Err(Error::Closed);
119+
*self = Socks5::Rejected(err, input[3], input[4]);
120+
} else {
121+
*self = Socks5::Reading(input[3], input[4]);
121122
}
122-
*self = Socks5::Reading(input[3], input[4]);
123123
Ok(vec![])
124124
}
125125
Socks5::Reading(code1, code2) => {
@@ -132,7 +132,7 @@ impl Socks5 {
132132
Ok(vec![])
133133
}
134134
Socks5::Active(_) => Err(Error::Completed),
135-
Socks5::Rejected(_) | Socks5::Failed(_) => Err(Error::Closed),
135+
Socks5::Rejected(_, _, _) | Socks5::Failed(_) => Err(Error::Closed),
136136
}
137137
}
138138

@@ -141,11 +141,13 @@ impl Socks5 {
141141
Socks5::Initial(_, _) => 0,
142142
Socks5::Connected(_) => 2,
143143
Socks5::Awaiting => 5,
144-
Socks5::Reading(ty, _) if *ty == IPV4 => 5,
145-
Socks5::Reading(ty, _) if *ty == IPV6 => 17,
146-
Socks5::Reading(ty, len) if *ty == DOMAIN => *len as usize + 1,
147-
Socks5::Reading(_, _) => 1,
148-
Socks5::Active(_) | Socks5::Rejected(_) | Socks5::Failed(_) => 0,
144+
Socks5::Reading(ty, _) | Socks5::Rejected(_, ty, _) if *ty == IPV4 => 5,
145+
Socks5::Reading(ty, _) | Socks5::Rejected(_, ty, _) if *ty == IPV6 => 17,
146+
Socks5::Reading(ty, len) | Socks5::Rejected(_, ty, len) if *ty == DOMAIN => {
147+
*len as usize + 1
148+
}
149+
Socks5::Reading(_, _) | Socks5::Rejected(_, _, _) => 1,
150+
Socks5::Active(_) | Socks5::Failed(_) => 0,
149151
}
150152
}
151153
}

0 commit comments

Comments
 (0)