Browse Source

Do not handle zero command code as a closed connection.

drieseng 9 years ago
parent
commit
e8d249c9d9
1 changed files with 6 additions and 1 deletions
  1. 6 1
      src/Renci.SshNet/ForwardedPortDynamic.NET.cs

+ 6 - 1
src/Renci.SshNet/ForwardedPortDynamic.NET.cs

@@ -348,7 +348,7 @@ namespace Renci.SshNet
         private bool HandleSocks4(Socket socket, IChannelDirectTcpip channel, TimeSpan timeout)
         {
             var commandCode = SocketAbstraction.ReadByte(socket, timeout);
-            if (commandCode == 0)
+            if (commandCode == -1)
             {
                 // SOCKS client closed connection
                 return false;
@@ -508,6 +508,11 @@ namespace Renci.SshNet
                 case 0x03:
                     {
                         var length = SocketAbstraction.ReadByte(socket, timeout);
+                        if (length == -1)
+                        {
+                            // SOCKS client closed connection
+                            return false;
+                        }
                         addressBuffer = new byte[length];
                         if (SocketAbstraction.Read(socket, addressBuffer, 0, addressBuffer.Length, timeout) == 0)
                         {