Skip to content

Commit

Permalink
fix crash on corrupt connection + fix linux build (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdsk authored Jan 3, 2022
1 parent 3591e4d commit 24eff24
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 95 deletions.
136 changes: 46 additions & 90 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 18 additions & 4 deletions server/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use protocol::{Event, Addr};
use protocol::{Addr, Event};
use shared::tarpc::server::BaseChannel;
use std::collections::HashMap;
use std::net::{IpAddr, Ipv4Addr};
Expand Down Expand Up @@ -85,6 +85,8 @@ pub fn events_channel() -> Arc<broadcast::Sender<Event>> {
pub enum Error {
#[error("invalid header: {0:?}")]
InvalidAddressType(ppp::v2::Addresses),
#[error("could not determine address from connection: {0:?}")]
AddrExtraction(std::io::ErrorKind),
}

pub async fn extract_peer_addr(conn: &mut TcpStream) -> Result<IpAddr, Error> {
Expand All @@ -98,7 +100,11 @@ pub async fn extract_peer_addr(conn: &mut TcpStream) -> Result<IpAddr, Error> {
let (len, addr) = match HeaderResult::parse(&buf) {
HeaderResult::V1(_) => {
debug!("proxy protocol header is not supported, assuming none is present");
return Ok(conn.peer_addr().unwrap().ip());
return Ok(conn
.peer_addr()
.map_err(|e| e.kind())
.map_err(Error::AddrExtraction)?
.ip());
}
HeaderResult::V2(Ok(header)) => {
use ppp::v2::Addresses::*;
Expand All @@ -112,7 +118,13 @@ pub async fn extract_peer_addr(conn: &mut TcpStream) -> Result<IpAddr, Error> {
HeaderResult::V2(Err(e)) if e.is_incomplete() => {
panic!("header incomplete need more bytes")
}
_ => return Ok(conn.peer_addr().unwrap().ip()),
_ => {
return Ok(conn
.peer_addr()
.map_err(|e| e.kind())
.map_err(Error::AddrExtraction)?
.ip())
}
};

let mut buf = [0u8; 512];
Expand Down Expand Up @@ -180,7 +192,9 @@ pub async fn host(
}
};

let framed = codec_builder.max_frame_length(100 * 1024 * 1024).new_framed(conn);
let framed = codec_builder
.max_frame_length(100 * 1024 * 1024)
.new_framed(conn);

use tarpc::serde_transport as transport;
let transport = transport::new(framed, Bincode::default());
Expand Down
2 changes: 1 addition & 1 deletion wrapper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
util = ["reqwest"]

[dependencies]
reqwest = { version = "0.11", optional = true }
reqwest = { version = "0.11", optional = true , features= ["rustls-tls"], default-features=false }
tokio = {version = "1", features = ["process", "io-util", "macros", "rt-multi-thread", "fs", "time"]}
tracing = "0.1"
thiserror = "1"
Expand Down

0 comments on commit 24eff24

Please sign in to comment.