1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 14:12:10 +02:00

Bug 470114 - Unable to connect using telnet: ArrayOutOfBoundsException

Change-Id: I0089b5a0ad3d3bb894f5fd0aa0e280b700a3e22e
Signed-off-by: Anton Leherbauer <anton.leherbauer@windriver.com>
This commit is contained in:
Anton Leherbauer 2015-06-18 09:47:24 +02:00
parent f48e9c35f2
commit e40082b64a
2 changed files with 19 additions and 24 deletions

View file

@ -270,7 +270,7 @@ public class TelnetConnection extends Thread implements TelnetCodes {
height = newHeight; height = newHeight;
if (sizeChanged && remoteIsTelnetServer && localOptions[TELNET_OPTION_NAWS].isEnabled()) { if (sizeChanged && remoteIsTelnetServer && localOptions[TELNET_OPTION_NAWS].isEnabled()) {
Integer[] sizeData = { new Integer(width), new Integer(height) }; Integer[] sizeData = { Integer.valueOf(width), Integer.valueOf(height) };
localOptions[TELNET_OPTION_NAWS].sendSubnegotiation(sizeData); localOptions[TELNET_OPTION_NAWS].sendSubnegotiation(sizeData);
} }
@ -418,6 +418,7 @@ public class TelnetConnection extends Thread implements TelnetCodes {
// TELNET protocol data. // TELNET protocol data.
byte inputByte = rawBytes[byteIndex]; byte inputByte = rawBytes[byteIndex];
int ubyte = inputByte & 0xFF;
switch (telnetState) { switch (telnetState) {
case STATE_INITIAL: case STATE_INITIAL:
@ -427,7 +428,7 @@ public class TelnetConnection extends Thread implements TelnetCodes {
// It's not an IAC code, so just append it to // It's not an IAC code, so just append it to
// processedBytes. // processedBytes.
processedBytes[nextProcessedByte++] = rawBytes[byteIndex]; processedBytes[nextProcessedByte++] = inputByte;
} }
break; break;
@ -489,7 +490,7 @@ public class TelnetConnection extends Thread implements TelnetCodes {
default: default:
// Unrecognized command! This should never happen. // Unrecognized command! This should never happen.
Logger.log("processTelnetProtocol: UNRECOGNIZED TELNET PROTOCOL COMMAND: " + //$NON-NLS-1$ Logger.log("processTelnetProtocol: UNRECOGNIZED TELNET PROTOCOL COMMAND: " + //$NON-NLS-1$
inputByte); ubyte);
telnetState = STATE_INITIAL; telnetState = STATE_INITIAL;
break; break;
} }
@ -500,36 +501,36 @@ public class TelnetConnection extends Thread implements TelnetCodes {
// local options. // local options.
case STATE_WILL_RECEIVED: case STATE_WILL_RECEIVED:
Logger.log("Received WILL " + localOptions[inputByte].optionName() + "."); //$NON-NLS-1$ //$NON-NLS-2$ Logger.log("Received WILL " + localOptions[ubyte].optionName() + "."); //$NON-NLS-1$ //$NON-NLS-2$
remoteOptions[inputByte].handleWill(); remoteOptions[ubyte].handleWill();
telnetState = STATE_INITIAL; telnetState = STATE_INITIAL;
telnetServerDetected(); telnetServerDetected();
break; break;
case STATE_WONT_RECEIVED: case STATE_WONT_RECEIVED:
Logger.log("Received WONT " + localOptions[inputByte].optionName() + "."); //$NON-NLS-1$ //$NON-NLS-2$ Logger.log("Received WONT " + localOptions[ubyte].optionName() + "."); //$NON-NLS-1$ //$NON-NLS-2$
remoteOptions[inputByte].handleWont(); remoteOptions[ubyte].handleWont();
telnetState = STATE_INITIAL; telnetState = STATE_INITIAL;
telnetServerDetected(); telnetServerDetected();
break; break;
case STATE_DO_RECEIVED: case STATE_DO_RECEIVED:
Logger.log("Received DO " + localOptions[inputByte].optionName() + "."); //$NON-NLS-1$ //$NON-NLS-2$ Logger.log("Received DO " + localOptions[ubyte].optionName() + "."); //$NON-NLS-1$ //$NON-NLS-2$
localOptions[inputByte].handleDo(); localOptions[ubyte].handleDo();
telnetState = STATE_INITIAL; telnetState = STATE_INITIAL;
telnetServerDetected(); telnetServerDetected();
break; break;
case STATE_DONT_RECEIVED: case STATE_DONT_RECEIVED:
Logger.log("Received DONT " + localOptions[inputByte].optionName() + "."); //$NON-NLS-1$ //$NON-NLS-2$ Logger.log("Received DONT " + localOptions[ubyte].optionName() + "."); //$NON-NLS-1$ //$NON-NLS-2$
localOptions[inputByte].handleDont(); localOptions[ubyte].handleDont();
telnetState = STATE_INITIAL; telnetState = STATE_INITIAL;
telnetServerDetected(); telnetServerDetected();
break; break;
case STATE_SUBNEGOTIATION_STARTED: case STATE_SUBNEGOTIATION_STARTED:
Logger.log("Starting subnegotiation for option " + //$NON-NLS-1$ Logger.log("Starting subnegotiation for option " + //$NON-NLS-1$
localOptions[inputByte].optionName() + "."); //$NON-NLS-1$ localOptions[ubyte].optionName() + "."); //$NON-NLS-1$
// First, zero out the array of received subnegotiation butes. // First, zero out the array of received subnegotiation butes.
@ -608,7 +609,7 @@ public class TelnetConnection extends Thread implements TelnetCodes {
receivedSubnegotiation[nextSubnegotiationByteIndex - 1] = 0; receivedSubnegotiation[nextSubnegotiationByteIndex - 1] = 0;
int subnegotiatedOption = receivedSubnegotiation[0]; int subnegotiatedOption = receivedSubnegotiation[0] & 0xFF;
localOptions[subnegotiatedOption].handleSubnegotiation(receivedSubnegotiation, localOptions[subnegotiatedOption].handleSubnegotiation(receivedSubnegotiation,
nextSubnegotiationByteIndex); nextSubnegotiationByteIndex);
@ -636,7 +637,7 @@ public class TelnetConnection extends Thread implements TelnetCodes {
Logger.log("SUBNEGOTIATION BUFFER FULL!"); //$NON-NLS-1$ Logger.log("SUBNEGOTIATION BUFFER FULL!"); //$NON-NLS-1$
ignoreSubnegotiation = true; ignoreSubnegotiation = true;
} else { } else {
Logger.log("Recording subnegotiation byte " + (inputByte & 0xff)); //$NON-NLS-1$ Logger.log("Recording subnegotiation byte " + ubyte); //$NON-NLS-1$
receivedSubnegotiation[nextSubnegotiationByteIndex++] = inputByte; receivedSubnegotiation[nextSubnegotiationByteIndex++] = inputByte;
} }

View file

@ -262,7 +262,7 @@ class TelnetOption implements TelnetCodes
* parameter <i>option</i>. * parameter <i>option</i>.
*/ */
public String optionName() { public String optionName() {
return optionNames[option]; return optionNames[option & 0xFF];
} }
/** /**
@ -524,7 +524,7 @@ class TelnetOption implements TelnetCodes
break; break;
} }
// Tell the remote endpoint our terminal type is "ansi" using this sequence // Tell the remote endpoint our terminal type is "xterm" using this sequence
// of TELNET protocol bytes: // of TELNET protocol bytes:
// //
// IAC SB TERMINAL-TYPE IS x t e r m IAC SE // IAC SB TERMINAL-TYPE IS x t e r m IAC SE
@ -565,7 +565,7 @@ class TelnetOption implements TelnetCodes
// IAC SB NAWS <width-highbyte> <width-lowbyte> <height-highbyte> // IAC SB NAWS <width-highbyte> <width-lowbyte> <height-highbyte>
// <height-lowbyte> IAC SE // <height-lowbyte> IAC SE
byte[] NAWSData = { TELNET_IAC, TELNET_SB, TELNET_OPTION_NAWS, 0, final byte[] NAWSData = { TELNET_IAC, TELNET_SB, TELNET_OPTION_NAWS, 0,
0, 0, 0, TELNET_IAC, TELNET_SE }; 0, 0, 0, TELNET_IAC, TELNET_SE };
int width = ((Integer) subnegotiationData[0]).intValue(); int width = ((Integer) subnegotiationData[0]).intValue();
int height = ((Integer) subnegotiationData[1]).intValue(); int height = ((Integer) subnegotiationData[1]).intValue();
@ -579,12 +579,6 @@ class TelnetOption implements TelnetCodes
.log("sending terminal size to remote endpoint: width = " + width + //$NON-NLS-1$ .log("sending terminal size to remote endpoint: width = " + width + //$NON-NLS-1$
", height = " + height + "."); //$NON-NLS-1$ //$NON-NLS-2$ ", height = " + height + "."); //$NON-NLS-1$ //$NON-NLS-2$
// This final local variable is a hack to get around the fact that inner
// classes cannot reference a non-final local variable in a lexically
// enclosing scope.
final byte[] NAWSDataFinal = NAWSData;
// Send the NAWS data in a new thread. The current thread is the display // Send the NAWS data in a new thread. The current thread is the display
// thread, and calls to write() can block, but blocking the display thread // thread, and calls to write() can block, but blocking the display thread
// is _bad_ (it hangs the GUI). // is _bad_ (it hangs the GUI).
@ -593,7 +587,7 @@ class TelnetOption implements TelnetCodes
@Override @Override
public void run() { public void run() {
try { try {
outputStream.write(NAWSDataFinal); outputStream.write(NAWSData);
} catch (IOException ex) { } catch (IOException ex) {
Logger.log("IOException sending NAWS subnegotiation!"); //$NON-NLS-1$ Logger.log("IOException sending NAWS subnegotiation!"); //$NON-NLS-1$
Logger.logException(ex); Logger.logException(ex);