diff --git a/src/config/version.rs b/src/config/version.rs index 32ca679..dd253d0 100644 --- a/src/config/version.rs +++ b/src/config/version.rs @@ -58,7 +58,7 @@ impl SshVersion { S: Read, { let buf = read_version(stream, timeout)?; - if &buf[0..4] != SSH_MAGIC { + if buf.len() < 4 || &buf[0..4] != SSH_MAGIC { error!("SSH version magic doesn't match"); error!("Probably not an ssh server"); } diff --git a/src/session/mod.rs b/src/session/mod.rs index 29a0e55..28a2341 100644 --- a/src/session/mod.rs +++ b/src/session/mod.rs @@ -50,14 +50,15 @@ where .connect(), SessionState::Version(mut config, mut stream) => { info!("start for version negotiation."); + // Send Client version + config.ver.send_our_version(&mut stream)?; + // Receive the server version config .ver .read_server_version(&mut stream, config.timeout)?; // Version validate config.ver.validate()?; - // Send Client version - config.ver.send_our_version(&mut stream)?; // from now on // each step of the interaction is subject to the ssh constraints on the packet