You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by gn...@apache.org on 2014/01/30 09:44:20 UTC
[1/2] git commit: [SSHD-269] Random Data corruption with Remote Port
Forwarding
Updated Branches:
refs/heads/master ade49e489 -> d749a675b
[SSHD-269] Random Data corruption with Remote Port Forwarding
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/817e80ac
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/817e80ac
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/817e80ac
Branch: refs/heads/master
Commit: 817e80ac06f02a5bcc972dabfa879bf677f7a0c6
Parents: ade49e4
Author: Guillaume Nodet <gn...@apache.org>
Authored: Thu Jan 30 09:44:00 2014 +0100
Committer: Guillaume Nodet <gn...@apache.org>
Committed: Thu Jan 30 09:44:00 2014 +0100
----------------------------------------------------------------------
.../sshd/common/forward/TcpipClientChannel.java | 2 +
.../sshd/common/forward/TcpipServerChannel.java | 5 +-
.../org/apache/sshd/PortForwardingLoadTest.java | 80 ++++++++++++++++++++
3 files changed, 86 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/817e80ac/sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipClientChannel.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipClientChannel.java b/sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipClientChannel.java
index e4badbf..fa61176 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipClientChannel.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipClientChannel.java
@@ -110,7 +110,9 @@ public class TcpipClientChannel extends AbstractClientChannel {
}
protected synchronized void doWriteData(byte[] data, int off, int len) throws IOException {
+ // Make sure we copy the data as the incoming buffer may be reused
Buffer buf = new Buffer(data, off, len);
+ buf = new Buffer(buf.getCompactData());
localWindow.consumeAndCheck(len);
serverSession.write(buf);
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/817e80ac/sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipServerChannel.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipServerChannel.java b/sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipServerChannel.java
index 3ee8429..b1c756c 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipServerChannel.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/forward/TcpipServerChannel.java
@@ -183,7 +183,10 @@ public class TcpipServerChannel extends AbstractServerChannel {
}
protected void doWriteData(byte[] data, int off, int len) throws IOException {
- ioSession.write(new Buffer(data, off, len));
+ // Make sure we copy the data as the incoming buffer may be reused
+ Buffer buf = new Buffer(data, off, len);
+ buf = new Buffer(buf.getCompactData());
+ ioSession.write(buf);
}
protected void doWriteExtendedData(byte[] data, int off, int len) throws IOException {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/817e80ac/sshd-core/src/test/java/org/apache/sshd/PortForwardingLoadTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/PortForwardingLoadTest.java b/sshd-core/src/test/java/org/apache/sshd/PortForwardingLoadTest.java
index c65bd49..3ec5629 100644
--- a/sshd-core/src/test/java/org/apache/sshd/PortForwardingLoadTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/PortForwardingLoadTest.java
@@ -18,7 +18,11 @@
*/
package org.apache.sshd;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
@@ -114,6 +118,82 @@ public class PortForwardingLoadTest {
}
@Test
+ public void testLocalForwardingPayload() throws Exception {
+ final int NUM_ITERATIONS = 100;
+ final String PAYLOAD_TMP = "This is significantly longer Test Data. This is significantly "+
+ "longer Test Data. This is significantly longer Test Data. This is significantly "+
+ "longer Test Data. This is significantly longer Test Data. This is significantly "+
+ "longer Test Data. This is significantly longer Test Data. This is significantly "+
+ "longer Test Data. This is significantly longer Test Data. This is significantly "+
+ "longer Test Data. ";
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < 1000; i++) {
+ sb.append(PAYLOAD_TMP);
+ }
+ final String PAYLOAD = sb.toString();
+ Session session = createSession();
+ final ServerSocket ss = new ServerSocket(0);
+ int forwardedPort = ss.getLocalPort();
+ int sinkPort = getFreePort();
+ session.setPortForwardingL(sinkPort, "localhost", forwardedPort);
+ final AtomicInteger conCount = new AtomicInteger(0);
+
+ new Thread() {
+ public void run() {
+ try {
+ for (int i = 0; i < NUM_ITERATIONS; ++i) {
+ Socket s = ss.accept();
+ conCount.incrementAndGet();
+ InputStream is = s.getInputStream();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ byte[] buf = new byte[8192];
+ int l;
+ while (baos.size() < PAYLOAD.length() && (l = is.read(buf)) > 0) {
+ baos.write(buf, 0, l);
+ }
+ if (!PAYLOAD.equals(baos.toString())) {
+ assertEquals(PAYLOAD, baos.toString());
+ }
+ is = new ByteArrayInputStream(baos.toByteArray());
+ OutputStream os = s.getOutputStream();
+ while ((l = is.read(buf)) > 0) {
+ os.write(buf, 0, l);
+ }
+ s.close();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }.start();
+ Thread.sleep(50);
+
+ for ( int i = 0; i < NUM_ITERATIONS; i++) {
+ Socket s = null;
+ try {
+ LoggerFactory.getLogger(getClass()).info("Iteration {}", i);
+ s = new Socket("localhost", sinkPort);
+ s.getOutputStream().write(PAYLOAD.getBytes());
+ s.getOutputStream().flush();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ byte[] buf = new byte[8192];
+ int l;
+ while (baos.size() < PAYLOAD.length() && (l = s.getInputStream().read(buf)) > 0) {
+ baos.write(buf, 0, l);
+ }
+ assertEquals(PAYLOAD, baos.toString());
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ if (s != null) {
+ s.close();
+ }
+ }
+ }
+ session.delPortForwardingL(sinkPort);
+ }
+
+ @Test
public void testRemoteForwardingPayload() throws Exception {
final int NUM_ITERATIONS = 100;
final String PAYLOAD = "This is significantly longer Test Data. This is significantly "+
[2/2] git commit: Remove unneeded log statement
Posted by gn...@apache.org.
Remove unneeded log statement
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/d749a675
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/d749a675
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/d749a675
Branch: refs/heads/master
Commit: d749a675b1771629bb7cbe23f7cc0417388968e7
Parents: 817e80a
Author: Guillaume Nodet <gn...@apache.org>
Authored: Thu Jan 30 09:44:11 2014 +0100
Committer: Guillaume Nodet <gn...@apache.org>
Committed: Thu Jan 30 09:44:11 2014 +0100
----------------------------------------------------------------------
.../main/java/org/apache/sshd/common/session/AbstractSession.java | 1 -
1 file changed, 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/d749a675/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractSession.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractSession.java b/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractSession.java
index 4fa7ff8..700b18e 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractSession.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/session/AbstractSession.java
@@ -364,7 +364,6 @@ public abstract class AbstractSession implements Session {
sendEvent(SessionListener.Event.KeyEstablished);
break;
default:
- log.debug("Received {}", cmd);
if (cmd >= SshConstants.SSH_MSG_KEX_FIRST && cmd <= SshConstants.SSH_MSG_KEX_LAST) {
if (kexState != KEX_STATE_RUN) {
throw new IllegalStateException("Received kex command " + cmd + " while not in key exchange");