diff --git a/src/main/java/net/schmizz/sshj/transport/TransportImpl.java b/src/main/java/net/schmizz/sshj/transport/TransportImpl.java index 12a16b291..1e3b13bcc 100644 --- a/src/main/java/net/schmizz/sshj/transport/TransportImpl.java +++ b/src/main/java/net/schmizz/sshj/transport/TransportImpl.java @@ -158,7 +158,10 @@ public void init(String remoteHost, int remotePort, InputStream in, OutputStream // Read server's ID final Buffer.PlainBuffer buf = new Buffer.PlainBuffer(); while ((serverID = readIdentification(buf)).isEmpty()) { - buf.putByte((byte) connInfo.in.read()); + int b = connInfo.in.read(); + if (b == -1) + throw new TransportException("Server closed connection during identification exchange"); + buf.putByte((byte) b); } log.info("Server identity string: {}", serverID);