Merge remote-tracking branch 'origin/mr/156'

This commit is contained in:
Nick Mathewson 2021-11-30 15:21:02 -05:00
commit 08267147ec
1 changed files with 5 additions and 2 deletions

View File

@ -95,7 +95,6 @@ pub struct TorAddr {
/// The target host.
host: Host,
/// The target port number.
// TODO: reject port 0.
port: u16,
}
@ -247,7 +246,11 @@ impl IntoTorAddr for &str {
let (host, port) = self.rsplit_once(':').ok_or(TorAddrError::NoPort)?;
let host = host.parse()?;
let port = port.parse().map_err(|_| TorAddrError::BadPort)?;
Ok(TorAddr { host, port })
if port == 0 {
Err(TorAddrError::BadPort)
} else {
Ok(TorAddr { host, port })
}
}
}
}