Skip to content

Commit a3db5c5

Browse files
committed
Fix bug on trojan domain name dump that misses the length data; Fix bug on socks protocol read domain name utility.
1 parent d2d7c37 commit a3db5c5

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

src/protocol/common/addr.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,16 @@ impl Into<std::io::Result<SocketAddr>> for IpAddrPort {
4343
match self.ip {
4444
IpAddress::IpAddr(addr) => Ok(SocketAddr::new(addr, self.port)),
4545
IpAddress::Domain(domain) => {
46-
let name = std::str::from_utf8(&domain.inner).unwrap_or("127.0.0.1");
46+
let name = match std::str::from_utf8(&domain.inner) {
47+
Ok(name) => name,
48+
Err(_) => {
49+
return Err(Error::new(
50+
ErrorKind::InvalidData,
51+
"request domain name contains non-utf8 character",
52+
))
53+
}
54+
};
55+
4756
// to_socket_addrs function implicitly runs a DNS query to resolve the DomainName
4857
let addrs = match (name, self.port).to_socket_addrs() {
4958
Ok(a) => a,

src/protocol/socks5/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub async fn parse<T: AsyncRead + AsyncWrite + Unpin>(mut stream: T) -> Result<R
4242
Atype::DomainName => {
4343
// Read address size
4444
let size = stream.read_u8().await? as usize;
45-
let mut buf = Vec::with_capacity(size);
45+
let mut buf = vec![0u8; size];
4646

4747
// Read address data
4848
stream.read_exact(&mut buf).await?;

src/protocol/trojan/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ pub async fn handshake<T: AsyncWrite + Unpin>(
5252
stream.write_all(&ipv6.octets()).await?;
5353
}
5454
IpAddress::Domain(domain) => {
55+
stream.write_u8(domain.as_bytes().len() as u8).await?;
5556
stream.write_all(&domain.as_bytes()).await?;
5657
}
5758
}

0 commit comments

Comments
 (0)