File tree Expand file tree Collapse file tree 3 files changed +12
-2
lines changed Expand file tree Collapse file tree 3 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -43,7 +43,16 @@ impl Into<std::io::Result<SocketAddr>> for IpAddrPort {
43
43
match self . ip {
44
44
IpAddress :: IpAddr ( addr) => Ok ( SocketAddr :: new ( addr, self . port ) ) ,
45
45
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
+
47
56
// to_socket_addrs function implicitly runs a DNS query to resolve the DomainName
48
57
let addrs = match ( name, self . port ) . to_socket_addrs ( ) {
49
58
Ok ( a) => a,
Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ pub async fn parse<T: AsyncRead + AsyncWrite + Unpin>(mut stream: T) -> Result<R
42
42
Atype :: DomainName => {
43
43
// Read address size
44
44
let size = stream. read_u8 ( ) . await ? as usize ;
45
- let mut buf = Vec :: with_capacity ( size) ;
45
+ let mut buf = vec ! [ 0u8 ; size] ;
46
46
47
47
// Read address data
48
48
stream. read_exact ( & mut buf) . await ?;
Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ pub async fn handshake<T: AsyncWrite + Unpin>(
52
52
stream. write_all ( & ipv6. octets ( ) ) . await ?;
53
53
}
54
54
IpAddress :: Domain ( domain) => {
55
+ stream. write_u8 ( domain. as_bytes ( ) . len ( ) as u8 ) . await ?;
55
56
stream. write_all ( & domain. as_bytes ( ) ) . await ?;
56
57
}
57
58
}
You can’t perform that action at this time.
0 commit comments