Skip to content

Commit

Permalink
feat(shadowsocks): check local_addr is an IPv4-mapped-IPv6 address
Browse files Browse the repository at this point in the history
  • Loading branch information
zonyitoo committed Jun 16, 2024
1 parent 2f2d3cd commit 285a72d
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions crates/shadowsocks/src/net/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,25 @@ fn check_ipv4_mapped_ipv6_capability() -> io::Result<()> {
socket1.listen(128)?;

let socket1_address = socket1.local_addr()?;
match socket1_address.as_socket() {
None => return Err(io::Error::new(ErrorKind::Other, "invalid local_addr")),
Some(socket_addr) => match socket_addr {
SocketAddr::V4(..) => {
return Err(io::Error::new(
ErrorKind::Other,
"local_addr shouldn't be an IPv4 address",
))
}
SocketAddr::V6(ref v6) => {
if let None = v6.ip().to_ipv4_mapped() {

Check warning on line 198 in crates/shadowsocks/src/net/sys/mod.rs

View workflow job for this annotation

GitHub Actions / clippy ubuntu-latest

redundant pattern matching, consider using `is_none()`

warning: redundant pattern matching, consider using `is_none()` --> crates/shadowsocks/src/net/sys/mod.rs:198:24 | 198 | if let None = v6.ip().to_ipv4_mapped() { | -------^^^^--------------------------- help: try: `if v6.ip().to_ipv4_mapped().is_none()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern_matching

Check warning on line 198 in crates/shadowsocks/src/net/sys/mod.rs

View workflow job for this annotation

GitHub Actions / clippy macos-latest

redundant pattern matching, consider using `is_none()`

warning: redundant pattern matching, consider using `is_none()` --> crates/shadowsocks/src/net/sys/mod.rs:198:24 | 198 | if let None = v6.ip().to_ipv4_mapped() { | -------^^^^--------------------------- help: try: `if v6.ip().to_ipv4_mapped().is_none()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern_matching
return Err(io::Error::new(
ErrorKind::Other,
"local_addr is not an IPv4-mapped-IPv6 address",
));
}
}
},
}

let socket2 = Socket::new(Domain::IPV6, Type::STREAM, Some(Protocol::TCP))?;
socket2.set_only_v6(false)?;
Expand Down

0 comments on commit 285a72d

Please sign in to comment.