@@ -95,10 +95,7 @@ impl Socks5 {
95
95
Ok ( out)
96
96
}
97
97
Socks5 :: Connected ( addr) => {
98
- if input. len ( ) != 2 {
99
- * self = Socks5 :: Failed ( Error :: InvalidReply ) ;
100
- return Err ( Error :: InvalidReply ) ;
101
- }
98
+ debug_assert_eq ! ( input. len( ) , 5 ) ;
102
99
if input[ 0 ] != 0x05 {
103
100
* self = Socks5 :: Failed ( Error :: VersionNotSupported ( input[ 0 ] ) ) ;
104
101
return Err ( Error :: VersionNotSupported ( input[ 0 ] ) ) ;
@@ -114,13 +111,17 @@ impl Socks5 {
114
111
Ok ( out)
115
112
}
116
113
Socks5 :: Awaiting => {
117
- debug_assert_eq ! ( input. len( ) , 3 ) ;
118
- if input[ 0 ] != 0x00 {
114
+ debug_assert_eq ! ( input. len( ) , 5 ) ;
115
+ if input[ 0 ] != 0x05 {
116
+ * self = Socks5 :: Failed ( Error :: VersionNotSupported ( input[ 0 ] ) ) ;
117
+ return Err ( Error :: VersionNotSupported ( input[ 0 ] ) ) ;
118
+ }
119
+ if input[ 1 ] != 0x00 {
119
120
let err = ServerError :: from ( input[ 1 ] ) ;
120
121
* self = Socks5 :: Rejected ( err) ;
121
122
return Err ( Error :: Closed ) ;
122
123
}
123
- * self = Socks5 :: Reading ( input[ 1 ] , input[ 2 ] ) ;
124
+ * self = Socks5 :: Reading ( input[ 3 ] , input[ 4 ] ) ;
124
125
Ok ( vec ! [ ] )
125
126
}
126
127
Socks5 :: Reading ( code1, code2) => {
@@ -141,10 +142,10 @@ impl Socks5 {
141
142
match self {
142
143
Socks5 :: Initial ( _, _) => 0 ,
143
144
Socks5 :: Connected ( _) => 2 ,
144
- Socks5 :: Awaiting => 3 ,
145
- Socks5 :: Reading ( ty, _) if * ty == IPV4 => 4 ,
146
- Socks5 :: Reading ( ty, _) if * ty == IPV6 => 16 ,
147
- Socks5 :: Reading ( ty, len) if * ty == DOMAIN => * len as usize ,
145
+ Socks5 :: Awaiting => 5 ,
146
+ Socks5 :: Reading ( ty, _) if * ty == IPV4 => 5 ,
147
+ Socks5 :: Reading ( ty, _) if * ty == IPV6 => 17 ,
148
+ Socks5 :: Reading ( ty, len) if * ty == DOMAIN => * len as usize + 1 ,
148
149
Socks5 :: Reading ( _, _) => 1 ,
149
150
Socks5 :: Active ( _) | Socks5 :: Rejected ( _) | Socks5 :: Failed ( _) => 0 ,
150
151
}
0 commit comments