From 8ec64b17bf68395235578cbe3400aa174d4916b7 Mon Sep 17 00:00:00 2001 From: Greg Watson Date: Fri, 26 Jun 2015 10:16:55 -0400 Subject: [PATCH 1/2] Bug 471136 - Ensure preference node path is valid Change-Id: I6e7634bcf46713ee472f7a86f40051b4db5d5a49 Signed-off-by: Greg Watson --- .../remote/internal/core/RemoteConnection.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/RemoteConnection.java b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/RemoteConnection.java index 09974fd7678..7b447540540 100644 --- a/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/RemoteConnection.java +++ b/bundles/org.eclipse.remote.core/src/org/eclipse/remote/internal/core/RemoteConnection.java @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.remote.internal.core; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; import java.util.HashMap; import java.util.Map; @@ -127,11 +129,21 @@ public class RemoteConnection implements IRemoteConnection { } Preferences getPreferences() { - return connectionType.getPreferenceNode().node(name); + try { + return connectionType.getPreferenceNode().node(URLEncoder.encode(name, "UTF-8")); //$NON-NLS-1$ + } catch (UnsupportedEncodingException e) { + // Should not happen! + throw new RuntimeException(e); + } } ISecurePreferences getSecurePreferences() { - return connectionType.getSecurePreferencesNode().node(name); + try { + return connectionType.getSecurePreferencesNode().node(URLEncoder.encode(name, "UTF-8")); //$NON-NLS-1$ + } catch (UnsupportedEncodingException e) { + // Should not happen! + throw new RuntimeException(e); + } } /* From 59d044cdfbdef03fd630c3a8efdc3e654e4a654f Mon Sep 17 00:00:00 2001 From: Greg Watson Date: Fri, 26 Jun 2015 11:02:46 -0400 Subject: [PATCH 2/2] Bug 471143 - Prevent potential NPE in disconnect Change-Id: I6a160806868048442c0e09bd8541177a650d01bb Signed-off-by: Greg Watson --- .../console/TerminalConsoleConnector.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/bundles/org.eclipse.remote.console/src/org/eclipse/remote/internal/console/TerminalConsoleConnector.java b/bundles/org.eclipse.remote.console/src/org/eclipse/remote/internal/console/TerminalConsoleConnector.java index ad8668c9f4e..282745e14d5 100644 --- a/bundles/org.eclipse.remote.console/src/org/eclipse/remote/internal/console/TerminalConsoleConnector.java +++ b/bundles/org.eclipse.remote.console/src/org/eclipse/remote/internal/console/TerminalConsoleConnector.java @@ -46,15 +46,19 @@ public class TerminalConsoleConnector { public OutThread() { super("Terminal Output"); //$NON-NLS-1$ } + + @Override public void run() { try { byte[] buff = new byte[1024]; - InputStream in = remoteProcess.getInputStream(); - for (int n = in.read(buff); n >= 0; n = in.read(buff)) { - for (PageConnector connector : pageConnectors) { - ITerminalControl control = connector.control; - if (control != null) { - control.getRemoteToTerminalOutputStream().write(buff, 0, n); + if (remoteProcess != null) { + InputStream in = remoteProcess.getInputStream(); + for (int n = in.read(buff); n >= 0; n = in.read(buff)) { + for (PageConnector connector : pageConnectors) { + ITerminalControl control = connector.control; + if (control != null) { + control.getRemoteToTerminalOutputStream().write(buff, 0, n); + } } } } @@ -67,6 +71,7 @@ public class TerminalConsoleConnector { } } } + private OutThread outThread; public TerminalConsoleConnector(IRemoteConnection connection) { @@ -76,7 +81,7 @@ public class TerminalConsoleConnector { public IRemoteConnection getConnection() { return connection; } - + public ITerminalConnector newPageConnector() { PageConnector connector = new PageConnector(); List list = new ArrayList<>(Arrays.asList(pageConnectors)); @@ -153,7 +158,7 @@ public class TerminalConsoleConnector { } public void disconnect() { - if (!remoteProcess.isCompleted()) { + if (remoteProcess != null && !remoteProcess.isCompleted()) { new Job(ConsoleMessages.DISCONNECTING) { @Override protected IStatus run(IProgressMonitor monitor) { @@ -200,7 +205,7 @@ public class TerminalConsoleConnector { @Override public OutputStream getTerminalToRemoteStream() { - return remoteProcess.getOutputStream(); + return remoteProcess != null ? remoteProcess.getOutputStream() : null; } @Override