commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1076483 - in /commons/proper/net/trunk/src: changes/changes.xml main/java/org/apache/commons/net/telnet/Telnet.java main/java/org/apache/commons/net/telnet/TelnetInputStream.java
Date Thu, 03 Mar 2011 01:26:17 GMT
Author: sebb
Date: Thu Mar  3 01:26:16 2011
New Revision: 1076483

URL: http://svn.apache.org/viewvc?rev=1076483&view=rev
Log:
NET-345 Telnet client: not properly handling IAC bytes within subnegotiation messages.

Modified:
    commons/proper/net/trunk/src/changes/changes.xml
    commons/proper/net/trunk/src/main/java/org/apache/commons/net/telnet/Telnet.java
    commons/proper/net/trunk/src/main/java/org/apache/commons/net/telnet/TelnetInputStream.java

Modified: commons/proper/net/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/changes/changes.xml?rev=1076483&r1=1076482&r2=1076483&view=diff
==============================================================================
--- commons/proper/net/trunk/src/changes/changes.xml (original)
+++ commons/proper/net/trunk/src/changes/changes.xml Thu Mar  3 01:26:16 2011
@@ -54,7 +54,12 @@ The <action> type attribute can be add,u
 
     <body>
         <release version="3.0" date="TBA" description="TBA">
-            <action issue="NET-343" dev="sebb" type="add">
+            <action issue="NET-345" dev="sebb" type="fix" due-to="Archie Cobbs">
+            Telnet client: not properly handling IAC bytes within subnegotiation messages:
+            - failing to double IACs on output
+            - failing to de-double IACs in input
+            </action>
+            <action issue="NET-343" dev="sebb" type="add" due-to="Archie Cobbs">
             Telnet client: Support Client-initiated Subnegotiation Messages.
             </action>
             <action issue="NET-270" dev="sebb" type="fix">

Modified: commons/proper/net/trunk/src/main/java/org/apache/commons/net/telnet/Telnet.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/telnet/Telnet.java?rev=1076483&r1=1076482&r2=1076483&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/org/apache/commons/net/telnet/Telnet.java (original)
+++ commons/proper/net/trunk/src/main/java/org/apache/commons/net/telnet/Telnet.java Thu Mar
 3 01:26:16 2011
@@ -21,6 +21,8 @@ import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
 import java.io.OutputStream;
 import java.io.IOException;
+import java.util.Arrays;
+
 import org.apache.commons.net.SocketClient;
 
 /**
@@ -782,22 +784,21 @@ class Telnet extends SocketClient
             System.err.println("SEND SUBNEGOTIATION: ");
             if (subn != null)
             {
-                for (int ii = 0; ii < subn.length; ii++)
-                {
-                    System.err.println("subn["  + ii + "]=" + subn[ii]);
-                }
+                System.err.println(Arrays.toString(subn));
             }
         }
         if (subn != null)
         {
-            byte byteresp[] = new byte[subn.length];
+            _output_.write(_COMMAND_SB);
+            // Note _output_ is buffered, so might as well simplify by writing single bytes
             for (int ii = 0; ii < subn.length; ii++)
             {
-                byteresp[ii] = (byte) subn[ii];
+                byte b = (byte) subn[ii];
+                if (b == TelnetCommand.IAC) {
+                    _output_.write(b); // double any IAC bytes
+                }
+                _output_.write(b);
             }
-
-            _output_.write(_COMMAND_SB);
-            _output_.write(byteresp);
             _output_.write(_COMMAND_SE);
 
             /* Code Section added for sending the negotiation ASAP (start)*/

Modified: commons/proper/net/trunk/src/main/java/org/apache/commons/net/telnet/TelnetInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/telnet/TelnetInputStream.java?rev=1076483&r1=1076482&r2=1076483&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/org/apache/commons/net/telnet/TelnetInputStream.java
(original)
+++ commons/proper/net/trunk/src/main/java/org/apache/commons/net/telnet/TelnetInputStream.java
Thu Mar  3 01:26:16 2011
@@ -211,6 +211,9 @@ final class TelnetInputStream extends Bu
                 case TelnetCommand.IAC:
                     __receiveState = _STATE_DATA;
                     break; // exit to enclosing switch to return IAC from read
+                case TelnetCommand.SE: // unexpected byte! ignore it (don't send it as a
command)
+                    __receiveState = _STATE_DATA;
+                    continue;
                 default:
                     __receiveState = _STATE_DATA;
                     __client._processCommand(ch); // Notify the user
@@ -258,12 +261,13 @@ final class TelnetInputStream extends Bu
                     continue;
                 default:
                     // store suboption char
-                    __suboption[__suboption_count++] = ch;
+                    if (__suboption_count < __suboption.length)
+                        __suboption[__suboption_count++] = ch;
                     break;
                 }
                 __receiveState = _STATE_SB;
                 continue;
-            case _STATE_IAC_SB:
+            case _STATE_IAC_SB: // IAC received during SB phase
                 switch (ch)
                 {
                 case TelnetCommand.SE:
@@ -274,11 +278,14 @@ final class TelnetInputStream extends Bu
                     }
                     __receiveState = _STATE_DATA;
                     continue;
-                default:
-                    __receiveState = _STATE_SB;
+                case TelnetCommand.IAC: // De-dup the duplicated IAC
+                    if (__suboption_count < __suboption.length)
+                        __suboption[__suboption_count++] = ch;
+                    break;
+                default:            // unexpected byte! ignore it
                     break;
                 }
-                __receiveState = _STATE_DATA;
+                __receiveState = _STATE_SB;
                 continue;
             /* TERMINAL-TYPE option (end)*/
             }



Mime
View raw message