Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 71141 invoked from network); 3 Mar 2011 01:27:19 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 3 Mar 2011 01:27:19 -0000 Received: (qmail 63249 invoked by uid 500); 3 Mar 2011 01:27:18 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 63196 invoked by uid 500); 3 Mar 2011 01:27:18 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 63186 invoked by uid 99); 3 Mar 2011 01:27:18 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Mar 2011 01:27:18 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Mar 2011 01:27:16 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 3DE082388A93; Thu, 3 Mar 2011 01:26:17 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@commons.apache.org From: sebb@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110303012617.3DE082388A93@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 type attribute can be add,u - + + Telnet client: not properly handling IAC bytes within subnegotiation messages: + - failing to double IACs on output + - failing to de-double IACs in input + + Telnet client: Support Client-initiated Subnegotiation Messages. 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)*/ }