Skip to content
Snippets Groups Projects
Commit 6c5e099b authored by Ian Jackson's avatar Ian Jackson
Browse files

handshake: Use read_exact, not read and checking len

read_exact has a loop in it, which we need.

This means we end up separating the two sites that generate the "not a
relay" error, so we need to fish out the error construction.

As per tpo/core/arti!249 (comment 2771023)
parent c4338999
No related branches found
No related tags found
1 merge request!249Fix two bugs related to incomplete read/write, and clippy tidying
......@@ -117,9 +117,13 @@ impl<T: AsyncRead + AsyncWrite + Send + Unpin + 'static> OutboundClientHandshake
let their_versions: msg::Versions = {
// TODO: this could be turned into another function, I suppose.
let mut hdr = [0_u8; 5];
let len = self.tls.read(&mut hdr).await?;
if len != hdr.len() || hdr[0..3] != [0, 0, ChanCmd::VERSIONS.into()] {
return Err(Error::ChanProto("Doesn't seem to be a tor relay".into()));
let not_relay = || Err(Error::ChanProto("Doesn't seem to be a tor relay".into()));
match self.tls.read_exact(&mut hdr).await {
Err(e) if e.kind() == std::io::ErrorKind::UnexpectedEof => return not_relay(),
otherwise => otherwise,
}?;
if hdr[0..3] != [0, 0, ChanCmd::VERSIONS.into()] {
return not_relay();
}
let msglen = u16::from_be_bytes(*array_ref![hdr, 3, 2]);
let mut msg = vec![0; msglen as usize];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment