Skip to content

Commit

Permalink
Fix: do not panic when connect to non-ssh server; send our version st…
Browse files Browse the repository at this point in the history
…ring first after connection setup
  • Loading branch information
HsuJv committed Nov 14, 2023
1 parent 9f3528d commit ac9098a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/config/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
5 changes: 3 additions & 2 deletions src/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ac9098a

Please sign in to comment.