[SSHD-240] Possible data loss in the server channel if data is received before the channel command is set up
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/4e75e8f5 Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/4e75e8f5 Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/4e75e8f5 Branch: refs/heads/master Commit: 4e75e8f5632fbd0d17dc9181cf05fd716db38f37 Parents: 58ae166 Author: Guillaume Nodet <[email protected]> Authored: Tue Jul 23 11:49:01 2013 +0200 Committer: Guillaume Nodet <[email protected]> Committed: Tue Jul 23 11:49:01 2013 +0200 ---------------------------------------------------------------------- .../sshd/server/channel/ChannelSession.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/4e75e8f5/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelSession.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelSession.java b/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelSession.java index d337247..a357305 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelSession.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/channel/ChannelSession.java @@ -170,6 +170,7 @@ public class ChannelSession extends AbstractServerChannel { protected Command command; protected ChannelDataReceiver receiver; protected StandardEnvironment env = new StandardEnvironment(); + protected Buffer tempBuffer; public ChannelSession() { } @@ -205,12 +206,17 @@ public class ChannelSession extends AbstractServerChannel { } protected void doWriteData(byte[] data, int off, int len) throws IOException { - int r = len; if (receiver != null) { - r = receiver.data(this, data, off, len); + int r = receiver.data(this, data, off, len); + if (r > 0) { + localWindow.consumeAndCheck(r); + } + } else { + if (tempBuffer == null) { + tempBuffer = new Buffer(len); + } + tempBuffer.putRawBytes(data, off, len); } - if (r > 0) - localWindow.consumeAndCheck(r); } protected void doWriteExtendedData(byte[] data, int off, int len) throws IOException { @@ -463,6 +469,11 @@ public class ChannelSession extends AbstractServerChannel { setDataReceiver(recv); command.setInputStream(recv.getIn()); } + if (tempBuffer != null) { + Buffer buffer = tempBuffer; + tempBuffer = null; + doWriteData(buffer.array(), buffer.rpos(), buffer.available()); + } command.setExitCallback(new ExitCallback() { public void onExit(int exitValue) { try {
