fixed length too short bug

This commit is contained in:
Y. T. Chung
2014-11-02 21:16:03 +08:00
parent 56429baf8e
commit cbed245486
3 changed files with 18 additions and 23 deletions
+17 -17
View File
@@ -137,27 +137,27 @@ impl TcpRelayLocal {
(header_buf.slice_to(header_len), addr)
};
let mut remote_stream = TcpStream::connect(server_addr.ip.to_string().as_slice(),
server_addr.port).unwrap_or_else(|err| {
match err.kind {
ConnectionAborted | ConnectionReset | ConnectionRefused | ConnectionFailed => {
send_error_reply(&mut stream, SOCKS5_REPLY_HOST_UNREACHABLE);
},
_ => {
send_error_reply(&mut stream, SOCKS5_REPLY_NETWORK_UNREACHABLE);
}
}
panic!("Failed to connect remote server: {}", err);
});
let mut cipher = cipher::with_name(encrypt_method.as_slice(),
password.as_slice().as_bytes())
.expect("Unsupported cipher");
match cmd {
SOCKS5_CMD_TCP_CONNECT => {
info!("CONNECT {}", addr);
let mut remote_stream = TcpStream::connect(server_addr.ip.to_string().as_slice(),
server_addr.port).unwrap_or_else(|err| {
match err.kind {
ConnectionAborted | ConnectionReset | ConnectionRefused | ConnectionFailed => {
send_error_reply(&mut stream, SOCKS5_REPLY_HOST_UNREACHABLE);
},
_ => {
send_error_reply(&mut stream, SOCKS5_REPLY_NETWORK_UNREACHABLE);
}
}
panic!("Failed to connect remote server: {}", err);
});
let mut cipher = cipher::with_name(encrypt_method.as_slice(),
password.as_slice().as_bytes())
.expect("Unsupported cipher");
{
let reply_header = [SOCKS5_VERSION, SOCKS5_REPLY_SUCCEEDED, 0x00];
stream.write(reply_header)
+1 -1
View File
@@ -185,7 +185,7 @@ fn handle_request(mut socket: UdpSocket,
(data.slice_to(header_len), addr)
};
info!("UDP ASSOCIATE {}", from_addr);
info!("UDP ASSOCIATE {}", addr);
debug!("UDP associate {} <-> {}", addr, from_addr);
client_map.lock().put(addr, from_addr);
-5
View File
@@ -59,11 +59,6 @@ impl UdpRelayServer {
loop {
match socket.recv_from(buf) {
Ok((len, src)) => {
if len < 4 {
error!("UDP request is too short");
continue;
}
let data = buf.slice_to(len).to_vec();
let client_map = client_map_arc.clone();
let remote_map = remote_map_arc.clone();