You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by lg...@apache.org on 2015/12/14 10:14:07 UTC

[3/4] mina-sshd git commit: Use more conservative buffer size allocations

Use more conservative buffer size allocations


Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/fa724c2f
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/fa724c2f
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/fa724c2f

Branch: refs/heads/master
Commit: fa724c2f1406b5f834cf802f7a41b6fe5461e96e
Parents: 13818de
Author: Lyor Goldstein <lg...@vmware.com>
Authored: Mon Dec 14 10:48:05 2015 +0200
Committer: Lyor Goldstein <lg...@vmware.com>
Committed: Mon Dec 14 10:48:05 2015 +0200

----------------------------------------------------------------------
 .../client/channel/AbstractClientChannel.java   |  2 +-
 .../sshd/client/channel/ChannelDirectTcpip.java | 11 +--
 .../apache/sshd/client/channel/ChannelExec.java |  2 +-
 .../sshd/client/channel/ChannelShell.java       |  2 +-
 .../sshd/client/channel/ChannelSubsystem.java   |  5 +-
 .../channel/PtyCapableChannelSession.java       |  6 +-
 .../org/apache/sshd/client/kex/DHGClient.java   |  2 +-
 .../org/apache/sshd/client/kex/DHGEXClient.java |  2 +-
 .../client/session/AbstractClientSession.java   | 74 +++++++-------------
 .../client/session/ClientConnectionService.java |  2 +-
 .../common/forward/DefaultTcpipForwarder.java   | 17 +++--
 .../sshd/common/forward/TcpipClientChannel.java | 12 +++-
 .../sshd/server/x11/X11ForwardSupport.java      |  8 ++-
 13 files changed, 68 insertions(+), 77 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa724c2f/sshd-core/src/main/java/org/apache/sshd/client/channel/AbstractClientChannel.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/channel/AbstractClientChannel.java b/sshd-core/src/main/java/org/apache/sshd/client/channel/AbstractClientChannel.java
index 78003c9..0cc419c 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/channel/AbstractClientChannel.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/channel/AbstractClientChannel.java
@@ -285,7 +285,7 @@ public abstract class AbstractClientChannel extends AbstractChannel implements C
         log.debug("Send SSH_MSG_CHANNEL_OPEN on channel {}", this);
 
         Session session = getSession();
-        Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_OPEN);
+        Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_OPEN, type.length() + Integer.SIZE);
         buffer.putString(type);
         buffer.putInt(getId());
         buffer.putInt(localWindow.getSize());

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa724c2f/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelDirectTcpip.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelDirectTcpip.java b/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelDirectTcpip.java
index 921b419..4f1aa99 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelDirectTcpip.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelDirectTcpip.java
@@ -70,18 +70,21 @@ public class ChannelDirectTcpip extends AbstractClientChannel {
 
         openFuture = new DefaultOpenFuture(lock);
         if (log.isDebugEnabled()) {
-            log.debug("Send SSH_MSG_CHANNEL_OPEN on channel {}", getId());
+            log.debug("open({}) SSH_MSG_CHANNEL_OPEN", this);
         }
 
         Session session = getSession();
-        Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_OPEN);
+        String remoteName = remote.getHostName();
+        String localName = local.getHostName();
+        Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_OPEN,
+                            type.length() + remoteName.length() + localName.length() + Long.SIZE);
         buffer.putString(type);
         buffer.putInt(getId());
         buffer.putInt(localWindow.getSize());
         buffer.putInt(localWindow.getPacketSize());
-        buffer.putString(remote.getHostName());
+        buffer.putString(remoteName);
         buffer.putInt(remote.getPort());
-        buffer.putString(local.getHostName());
+        buffer.putString(localName);
         buffer.putInt(local.getPort());
         writePacket(buffer);
         return openFuture;

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa724c2f/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelExec.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelExec.java b/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelExec.java
index 813b292..4079cb6 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelExec.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelExec.java
@@ -48,7 +48,7 @@ public class ChannelExec extends PtyCapableChannelSession {
         }
 
         Session session = getSession();
-        Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_REQUEST);
+        Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_REQUEST, command.length() + Integer.SIZE);
         buffer.putInt(getRecipient());
         buffer.putString("exec");
         buffer.putBoolean(false);

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa724c2f/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelShell.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelShell.java b/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelShell.java
index fb7b94e..d67ac60 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelShell.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelShell.java
@@ -44,7 +44,7 @@ public class ChannelShell extends PtyCapableChannelSession {
         }
 
         Session session = getSession();
-        Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_REQUEST);
+        Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_REQUEST, Integer.SIZE);
         buffer.putInt(getRecipient());
         buffer.putString("shell");
         buffer.putBoolean(false);

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa724c2f/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelSubsystem.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelSubsystem.java b/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelSubsystem.java
index 1880990..37434da 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelSubsystem.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/channel/ChannelSubsystem.java
@@ -59,11 +59,12 @@ public class ChannelSubsystem extends ChannelSession {
         }
 
         Session session = getSession();
-        Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_REQUEST);
+        String systemName = getSubsystem();
+        Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_REQUEST, systemName.length() + Integer.SIZE);
         buffer.putInt(getRecipient());
         buffer.putString("subsystem");
         buffer.putBoolean(false);
-        buffer.putString(getSubsystem());
+        buffer.putString(systemName);
         writePacket(buffer);
 
         super.doOpen();

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa724c2f/sshd-core/src/main/java/org/apache/sshd/client/channel/PtyCapableChannelSession.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/channel/PtyCapableChannelSession.java b/sshd-core/src/main/java/org/apache/sshd/client/channel/PtyCapableChannelSession.java
index 75ce2a4..cce09af 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/channel/PtyCapableChannelSession.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/channel/PtyCapableChannelSession.java
@@ -211,7 +211,7 @@ public class PtyCapableChannelSession extends ChannelSession {
         ptyWidth = width;
 
         Session session = getSession();
-        Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_REQUEST);
+        Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_REQUEST, Long.SIZE);
         buffer.putInt(getRecipient());
         buffer.putString("window-change");
         buffer.putBoolean(false);
@@ -229,7 +229,7 @@ public class PtyCapableChannelSession extends ChannelSession {
                 log.debug("doOpenPty({}) Send agent forwarding request", this);
             }
 
-            Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_REQUEST);
+            Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_REQUEST, Long.SIZE);
             buffer.putInt(getRecipient());
             buffer.putString("auth-agent-req@openssh.com");
             buffer.putBoolean(false);
@@ -242,7 +242,7 @@ public class PtyCapableChannelSession extends ChannelSession {
                           this, ptyType, ptyColumns, ptyLines, ptyHeight, ptyWidth, ptyModes);
             }
 
-            Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_REQUEST);
+            Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_REQUEST, Byte.MAX_VALUE);
             buffer.putInt(getRecipient());
             buffer.putString("pty-req");
             buffer.putBoolean(false);

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa724c2f/sshd-core/src/main/java/org/apache/sshd/client/kex/DHGClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/kex/DHGClient.java b/sshd-core/src/main/java/org/apache/sshd/client/kex/DHGClient.java
index c676c35..1d16973 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/kex/DHGClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/kex/DHGClient.java
@@ -87,7 +87,7 @@ public class DHGClient extends AbstractDHClientKeyExchange {
         if (log.isDebugEnabled()) {
             log.debug("init({})[{}] Send SSH_MSG_KEXDH_INIT", this, s);
         }
-        Buffer buffer = s.createBuffer(SshConstants.SSH_MSG_KEXDH_INIT);
+        Buffer buffer = s.createBuffer(SshConstants.SSH_MSG_KEXDH_INIT, e.length + Integer.SIZE);
         buffer.putMPInt(e);
 
         s.writePacket(buffer);

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa724c2f/sshd-core/src/main/java/org/apache/sshd/client/kex/DHGEXClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/kex/DHGEXClient.java b/sshd-core/src/main/java/org/apache/sshd/client/kex/DHGEXClient.java
index c521749..36feac4 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/kex/DHGEXClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/kex/DHGEXClient.java
@@ -92,7 +92,7 @@ public class DHGEXClient extends AbstractDHClientKeyExchange {
         if (log.isDebugEnabled()) {
             log.debug("init({}) Send SSH_MSG_KEX_DH_GEX_REQUEST", s);
         }
-        Buffer buffer = s.createBuffer(SshConstants.SSH_MSG_KEX_DH_GEX_REQUEST);
+        Buffer buffer = s.createBuffer(SshConstants.SSH_MSG_KEX_DH_GEX_REQUEST, Integer.SIZE);
         buffer.putInt(min);
         buffer.putInt(prf);
         buffer.putInt(max);

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa724c2f/sshd-core/src/main/java/org/apache/sshd/client/session/AbstractClientSession.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/session/AbstractClientSession.java b/sshd-core/src/main/java/org/apache/sshd/client/session/AbstractClientSession.java
index 76d042b..d5b6066 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/session/AbstractClientSession.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/session/AbstractClientSession.java
@@ -22,11 +22,12 @@ package org.apache.sshd.client.session;
 import java.io.IOException;
 import java.nio.file.FileSystem;
 import java.security.KeyPair;
-import java.util.ArrayList;
-import java.util.Comparator;
 import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
 
 import org.apache.sshd.client.ClientFactoryManager;
+import org.apache.sshd.client.auth.AuthenticationIdentitiesProvider;
+import org.apache.sshd.client.auth.PasswordIdentityProvider;
 import org.apache.sshd.client.auth.UserAuth;
 import org.apache.sshd.client.auth.UserInteraction;
 import org.apache.sshd.client.channel.ChannelDirectTcpip;
@@ -58,46 +59,17 @@ import org.apache.sshd.common.util.ValidateUtils;
  * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
  */
 public abstract class AbstractClientSession extends AbstractSession implements ClientSession {
-    /**
-     * Compares 2 password identities - returns zero ONLY if <U>both</U> compared
-     * objects are {@link String}s and equal to each other
-     */
-    public static final Comparator<Object> PASSWORD_IDENTITY_COMPARATOR = new Comparator<Object>() {
-        @Override
-        public int compare(Object o1, Object o2) {
-            if (!(o1 instanceof String) || !(o2 instanceof String)) {
-                return -1;
-            } else {
-                return ((String) o1).compareTo((String) o2);
-            }
-        }
-    };
-
-    /**
-     * Compares 2 {@link KeyPair} identities - returns zero ONLY if <U>both</U> compared
-     * objects are {@link KeyPair}s and equal to each other
-     */
-    public static final Comparator<Object> KEYPAIR_IDENTITY_COMPARATOR = new Comparator<Object>() {
-        @Override
-        public int compare(Object o1, Object o2) {
-            if ((!(o1 instanceof KeyPair)) || (!(o2 instanceof KeyPair))) {
-                return -1;
-            } else if (KeyUtils.compareKeyPairs((KeyPair) o1, (KeyPair) o2)) {
-                return 0;
-            } else {
-                return 1;
-            }
-        }
-    };
-
-    private final List<Object> identities = new ArrayList<>();
+    private final List<Object> identities = new CopyOnWriteArrayList<>();
+    private final AuthenticationIdentitiesProvider identitiesProvider;
     private ServerKeyVerifier serverKeyVerifier;
     private UserInteraction userInteraction;
+    private PasswordIdentityProvider passwordIdentityProvider;
     private List<NamedFactory<UserAuth>> userAuthFactories;
     private ScpTransferEventListener scpListener;
 
     protected AbstractClientSession(ClientFactoryManager factoryManager, IoSession ioSession) {
         super(false, factoryManager, ioSession);
+        identitiesProvider = AuthenticationIdentitiesProvider.Utils.wrap(identities);
     }
 
     @Override
@@ -135,8 +107,19 @@ public abstract class AbstractClientSession extends AbstractSession implements C
         this.userAuthFactories = userAuthFactories; // OK if null/empty - inherit from parent
     }
 
-    protected List<Object> getRegisteredIdentities() {
-        return identities;
+    @Override
+    public AuthenticationIdentitiesProvider getRegisteredIdentities() {
+        return identitiesProvider;
+    }
+
+    @Override
+    public PasswordIdentityProvider getPasswordIdentityProvider() {
+        return resolveEffectiveProvider(PasswordIdentityProvider.class, passwordIdentityProvider, getFactoryManager().getPasswordIdentityProvider());
+    }
+
+    @Override
+    public void setPasswordIdentityProvider(PasswordIdentityProvider provider) {
+        passwordIdentityProvider = provider;
     }
 
     @Override
@@ -153,7 +136,8 @@ public abstract class AbstractClientSession extends AbstractSession implements C
             return null;
         }
 
-        int index = findIdentityIndex(PASSWORD_IDENTITY_COMPARATOR, password);
+        int index = AuthenticationIdentitiesProvider.Utils.findIdentityIndex(
+                identities, AuthenticationIdentitiesProvider.Utils.PASSWORD_IDENTITY_COMPARATOR, password);
         if (index >= 0) {
             return (String) identities.remove(index);
         } else {
@@ -180,7 +164,8 @@ public abstract class AbstractClientSession extends AbstractSession implements C
             return null;
         }
 
-        int index = findIdentityIndex(KEYPAIR_IDENTITY_COMPARATOR, kp);
+        int index = AuthenticationIdentitiesProvider.Utils.findIdentityIndex(
+                identities, AuthenticationIdentitiesProvider.Utils.KEYPAIR_IDENTITY_COMPARATOR, kp);
         if (index >= 0) {
             return (KeyPair) identities.remove(index);
         } else {
@@ -188,17 +173,6 @@ public abstract class AbstractClientSession extends AbstractSession implements C
         }
     }
 
-    protected int findIdentityIndex(Comparator<? super Object> comp, Object target) {
-        for (int index = 0; index < identities.size(); index++) {
-            Object value = identities.get(index);
-            if (comp.compare(value, target) == 0) {
-                return index;
-            }
-        }
-
-        return -1;
-    }
-
     @Override
     public ClientChannel createChannel(String type) throws IOException {
         return createChannel(type, null);

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa724c2f/sshd-core/src/main/java/org/apache/sshd/client/session/ClientConnectionService.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientConnectionService.java b/sshd-core/src/main/java/org/apache/sshd/client/session/ClientConnectionService.java
index db400aa..356efbf 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/session/ClientConnectionService.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/session/ClientConnectionService.java
@@ -72,7 +72,7 @@ public class ClientConnectionService extends AbstractConnectionService {
     protected void sendHeartBeat() {
         String request = PropertyResolverUtils.getStringProperty(session, ClientFactoryManager.HEARTBEAT_REQUEST, ClientFactoryManager.DEFAULT_KEEP_ALIVE_HEARTBEAT_STRING);
         try {
-            Buffer buf = session.createBuffer(SshConstants.SSH_MSG_GLOBAL_REQUEST);
+            Buffer buf = session.createBuffer(SshConstants.SSH_MSG_GLOBAL_REQUEST, request.length() + Byte.SIZE);
             buf.putString(request);
             buf.putBoolean(false);
             session.writePacket(buf);

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa724c2f/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultTcpipForwarder.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultTcpipForwarder.java b/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultTcpipForwarder.java
index f84523e..803bf1b 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultTcpipForwarder.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/forward/DefaultTcpipForwarder.java
@@ -149,16 +149,18 @@ public class DefaultTcpipForwarder extends AbstractInnerCloseable implements Tcp
         ValidateUtils.checkNotNull(local, "Local address is null");
         ValidateUtils.checkNotNull(remote, "Remote address is null");
 
-        Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_GLOBAL_REQUEST);
+        String remoteHost = remote.getHostName();
+        int remotePort = remote.getPort();
+        Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_GLOBAL_REQUEST, remoteHost.length() + Long.SIZE);
         buffer.putString("tcpip-forward");
         buffer.putBoolean(true);
-        buffer.putString(remote.getHostName());
-        buffer.putInt(remote.getPort());
+        buffer.putString(remoteHost);
+        buffer.putInt(remotePort);
         Buffer result = session.request(buffer);
         if (result == null) {
             throw new SshException("Tcpip forwarding request denied by server");
         }
-        int port = (remote.getPort() == 0) ? result.getInt() : remote.getPort();
+        int port = (remotePort == 0) ? result.getInt() : remote.getPort();
         // TODO: Is it really safe to only store the local address after the request ?
         SshdSocketAddress prev;
         synchronized (remoteToLocal) {
@@ -169,7 +171,7 @@ public class DefaultTcpipForwarder extends AbstractInnerCloseable implements Tcp
             throw new IOException("Multiple remote port forwarding bindings on port=" + port + ": current=" + remote + ", previous=" + prev);
         }
 
-        SshdSocketAddress bound = new SshdSocketAddress(remote.getHostName(), port);
+        SshdSocketAddress bound = new SshdSocketAddress(remoteHost, port);
         if (log.isDebugEnabled()) {
             log.debug("startRemotePortForwarding(" + remote + " -> " + local + "): " + bound);
         }
@@ -189,10 +191,11 @@ public class DefaultTcpipForwarder extends AbstractInnerCloseable implements Tcp
                 log.debug("stopRemotePortForwarding(" + remote + ") cancel forwarding to " + bound);
             }
 
-            Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_GLOBAL_REQUEST);
+            String remoteHost = remote.getHostName();
+            Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_GLOBAL_REQUEST, remoteHost.length() + Long.SIZE);
             buffer.putString("cancel-tcpip-forward");
             buffer.putBoolean(false);
-            buffer.putString(remote.getHostName());
+            buffer.putString(remoteHost);
             buffer.putInt(remote.getPort());
             session.writePacket(buffer);
         } else {

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa724c2f/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 a1a8f78..a5b4281 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
@@ -19,6 +19,7 @@
 package org.apache.sshd.common.forward;
 
 import java.io.IOException;
+import java.net.InetAddress;
 import java.net.InetSocketAddress;
 
 import org.apache.sshd.client.channel.AbstractClientChannel;
@@ -90,14 +91,19 @@ public class TcpipClientChannel extends AbstractClientChannel {
         }
 
         Session session = getSession();
-        Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_OPEN);
+        InetAddress srcAddress = src.getAddress();
+        String srcHost = srcAddress.getHostAddress();
+        InetAddress dstAddress = dst.getAddress();
+        String dstHost = dstAddress.getHostAddress();
+        Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_OPEN,
+                type.length() + srcHost.length() + dstHost.length() + Long.SIZE);
         buffer.putString(type);
         buffer.putInt(getId());
         buffer.putInt(localWindow.getSize());
         buffer.putInt(localWindow.getPacketSize());
-        buffer.putString(dst.getAddress().getHostAddress());
+        buffer.putString(dstHost);
         buffer.putInt(dst.getPort());
-        buffer.putString(src.getAddress().getHostAddress());
+        buffer.putString(srcHost);
         buffer.putInt(src.getPort());
         writePacket(buffer);
         return openFuture;

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/fa724c2f/sshd-core/src/main/java/org/apache/sshd/server/x11/X11ForwardSupport.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/x11/X11ForwardSupport.java b/sshd-core/src/main/java/org/apache/sshd/server/x11/X11ForwardSupport.java
index afa8735..96f0a43 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/x11/X11ForwardSupport.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/x11/X11ForwardSupport.java
@@ -21,6 +21,7 @@ package org.apache.sshd.server.x11;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.net.BindException;
+import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.util.concurrent.TimeUnit;
 
@@ -201,12 +202,15 @@ public class X11ForwardSupport extends AbstractInnerCloseable implements IoHandl
                 log.debug("open({}) SSH_MSG_CHANNEL_OPEN", this);
             }
 
-            Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_OPEN);
+            InetAddress remoteAddress = remote.getAddress();
+            String remoteHost = remoteAddress.getHostAddress();
+            Buffer buffer = session.createBuffer(SshConstants.SSH_MSG_CHANNEL_OPEN,
+                    remoteHost.length() + type.length() + Integer.SIZE);
             buffer.putString(type);
             buffer.putInt(getId());
             buffer.putInt(localWindow.getSize());
             buffer.putInt(localWindow.getPacketSize());
-            buffer.putString(remote.getAddress().getHostAddress());
+            buffer.putString(remoteHost);
             buffer.putInt(remote.getPort());
             writePacket(buffer);
             return openFuture;