mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-24 16:53:50 +02:00
Fix NPE on Telnet Disconnect and avoid printing password to stdout
This commit is contained in:
parent
2848dc80ff
commit
cc457bb0d7
1 changed files with 35 additions and 18 deletions
|
@ -98,12 +98,10 @@ public class TelnetConnectorService extends StandardConnectorService implements
|
||||||
Activator.trace("Telnet Service: Connected"); //$NON-NLS-1$
|
Activator.trace("Telnet Service: Connected"); //$NON-NLS-1$
|
||||||
}catch( SocketException se) {
|
}catch( SocketException se) {
|
||||||
Activator.trace("Telnet Service failed: "+se.toString()); //$NON-NLS-1$
|
Activator.trace("Telnet Service failed: "+se.toString()); //$NON-NLS-1$
|
||||||
if (fTelnetClient.isConnected())
|
sessionDisconnect();
|
||||||
fTelnetClient.disconnect();
|
|
||||||
}catch( IOException ioe ) {
|
}catch( IOException ioe ) {
|
||||||
Activator.trace("Telnet Service failed: "+ioe.toString()); //$NON-NLS-1$
|
Activator.trace("Telnet Service failed: "+ioe.toString()); //$NON-NLS-1$
|
||||||
if (fTelnetClient.isConnected())
|
sessionDisconnect();
|
||||||
fTelnetClient.disconnect();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fSessionLostHandler = new SessionLostHandler( this );
|
fSessionLostHandler = new SessionLostHandler( this );
|
||||||
|
@ -111,6 +109,23 @@ public class TelnetConnectorService extends StandardConnectorService implements
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disconnect the telnet session.
|
||||||
|
* Synchronized in order to avoid NPE's from commons.net when called
|
||||||
|
* quickly in succession.
|
||||||
|
*/
|
||||||
|
private synchronized void sessionDisconnect() {
|
||||||
|
Activator.trace("TelnetConnectorService.sessionDisconnect"); //$NON-NLS-1$
|
||||||
|
try {
|
||||||
|
if (fTelnetClient!=null && fTelnetClient.isConnected())
|
||||||
|
fTelnetClient.disconnect();
|
||||||
|
} catch(Exception e) {
|
||||||
|
//Avoid NPE on disconnect shown in UI
|
||||||
|
//This is a non-critical exception so print only in debug mode
|
||||||
|
if (Activator.isTracingOn()) e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public String readUntil(String pattern) {
|
public String readUntil(String pattern) {
|
||||||
try {
|
try {
|
||||||
char lastChar = pattern.charAt(pattern.length() - 1);
|
char lastChar = pattern.charAt(pattern.length() - 1);
|
||||||
|
@ -138,7 +153,12 @@ public class TelnetConnectorService extends StandardConnectorService implements
|
||||||
try {
|
try {
|
||||||
out.println( value );
|
out.println( value );
|
||||||
out.flush();
|
out.flush();
|
||||||
Activator.trace("write: "+value ); //$NON-NLS-1$
|
if (Activator.isTracingOn()) {
|
||||||
|
//Avoid printing password to stdout
|
||||||
|
//Activator.trace("write: "+value ); //$NON-NLS-1$
|
||||||
|
int len = value.length()+6;
|
||||||
|
Activator.trace("write: ******************".substring(0, len<=24 ? len : 24)); //$NON-NLS-1$
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch( Exception e ) {
|
catch( Exception e ) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -148,8 +168,6 @@ public class TelnetConnectorService extends StandardConnectorService implements
|
||||||
protected void internalDisconnect(IProgressMonitor monitor) throws Exception {
|
protected void internalDisconnect(IProgressMonitor monitor) throws Exception {
|
||||||
|
|
||||||
Activator.trace("Telnet Service: Disconnecting ....."); //$NON-NLS-1$
|
Activator.trace("Telnet Service: Disconnecting ....."); //$NON-NLS-1$
|
||||||
|
|
||||||
|
|
||||||
boolean sessionLost = (fSessionLostHandler!=null && fSessionLostHandler.isSessionLost());
|
boolean sessionLost = (fSessionLostHandler!=null && fSessionLostHandler.isSessionLost());
|
||||||
// no more interested in handling session-lost, since we are disconnecting anyway
|
// no more interested in handling session-lost, since we are disconnecting anyway
|
||||||
fSessionLostHandler = null;
|
fSessionLostHandler = null;
|
||||||
|
@ -162,9 +180,7 @@ public class TelnetConnectorService extends StandardConnectorService implements
|
||||||
fireCommunicationsEvent(CommunicationsEvent.BEFORE_DISCONNECT);
|
fireCommunicationsEvent(CommunicationsEvent.BEFORE_DISCONNECT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if( fTelnetClient.isConnected() ) {
|
sessionDisconnect();
|
||||||
fTelnetClient.disconnect();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fire comm event to signal state changed
|
// Fire comm event to signal state changed
|
||||||
notifyDisconnection();
|
notifyDisconnection();
|
||||||
|
@ -385,14 +401,15 @@ public class TelnetConnectorService extends StandardConnectorService implements
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isConnected() {
|
public boolean isConnected() {
|
||||||
if (fTelnetClient.isConnected()) {
|
boolean connected;
|
||||||
return true;
|
synchronized(this) {
|
||||||
} else if (fSessionLostHandler!=null) {
|
connected = fTelnetClient.isConnected();
|
||||||
Activator.trace("TelnetConnectorService.isConnected: false -> sessionLost"); //$NON-NLS-1$
|
|
||||||
fSessionLostHandler.sessionLost();
|
|
||||||
}
|
}
|
||||||
|
if (!connected && fSessionLostHandler!=null) {
|
||||||
return false;
|
Activator.trace("TelnetConnectorService.isConnected: false -> sessionLost"); //$NON-NLS-1$
|
||||||
|
fSessionLostHandler.sessionLost();
|
||||||
|
}
|
||||||
|
return connected;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue