Skip to content

Commit

Permalink
Detect end-of-stream in TransportImpl#init
Browse files Browse the repository at this point in the history
OpenSSH will drop connections based on the value of MaxStartups when
there are too many unauthenticated connection. When this happens, reads
on the client socket return -1, which was previously inserted into the
identification buffer, leading to the error in hierynomus#118.
  • Loading branch information
bluekeyes committed Mar 13, 2015
1 parent b3ea908 commit 734c05f
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/main/java/net/schmizz/sshj/transport/TransportImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,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);
Expand Down

0 comments on commit 734c05f

Please sign in to comment.