Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoland Grunberg2016-08-16 14:12:00 +0000
committerXavier Coulon2016-08-16 16:48:51 +0000
commitc61be318c2dbbfe6165edf350ed299b80974fb9d (patch)
tree9e0d91989abf389ae7db7873ddbde521f89c8339
parente4b973120d7b935bf3a579119a1047c0f7fca0ed (diff)
downloadorg.eclipse.linuxtools-c61be318c2dbbfe6165edf350ed299b80974fb9d.tar.gz
org.eclipse.linuxtools-c61be318c2dbbfe6165edf350ed299b80974fb9d.tar.xz
org.eclipse.linuxtools-c61be318c2dbbfe6165edf350ed299b80974fb9d.zip
Bug 499745: Guard against bad return values in connection framework.
The connection settings framework expects a null return value when no connection settings could be provided. However it is possible to return a list of values with some potentially being null. We should ensure our providers don't do this and guard against this happening from extensions we don't control. Change-Id: Ib9473f8af075b1a811ed9a48b1bb63337b29ac21 Reviewed-on: https://git.eclipse.org/r/79130 Tested-by: Hudson CI Reviewed-by: Xavier Coulon <xcoulon@redhat.com>
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/DockerConnectionManager.java26
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DefaultDockerConnectionSettingsFinder.java2
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DefaultTCPConnectionSettingsProvider.java5
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DefaultUnixConnectionSettingsProvider.java5
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/ShellConnectionSettingsProvider.java10
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/SystemConnectionSettingsProvider.java5
-rw-r--r--containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/docker/core/DockerConnectionManagerTest.java4
7 files changed, 33 insertions, 24 deletions
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/DockerConnectionManager.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/DockerConnectionManager.java
index e8f62d9285..8ea9742cee 100644
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/DockerConnectionManager.java
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/docker/core/DockerConnectionManager.java
@@ -59,19 +59,21 @@ public class DockerConnectionManager {
List<IDockerConnectionSettings> settings = connectionSettingsFinder
.getKnownConnectionSettings();
for (IDockerConnectionSettings setting : settings) {
- IDockerConnection conn;
- if (setting.getType().equals(BindingType.UNIX_SOCKET_CONNECTION)) {
- UnixSocketConnectionSettings usetting = (UnixSocketConnectionSettings) setting;
- conn = new DockerConnection.Builder().name(usetting.getName())
- .unixSocketConnection(usetting);
- } else {
- TCPConnectionSettings tsetting = (TCPConnectionSettings) setting;
- conn = new DockerConnection.Builder().name(tsetting.getName())
- .tcpConnection(tsetting);
+ if (setting != null) {
+ IDockerConnection conn;
+ if (setting.getType().equals(BindingType.UNIX_SOCKET_CONNECTION)) {
+ UnixSocketConnectionSettings usetting = (UnixSocketConnectionSettings) setting;
+ conn = new DockerConnection.Builder().name(usetting.getName())
+ .unixSocketConnection(usetting);
+ } else {
+ TCPConnectionSettings tsetting = (TCPConnectionSettings) setting;
+ conn = new DockerConnection.Builder().name(tsetting.getName())
+ .tcpConnection(tsetting);
+ }
+ // add the connection but do not notify the listeners to avoid
+ // flickering on the Docker Explorer view for each entry
+ addConnection(conn, false);
}
- // add the connection but do not notify the listeners to avoid
- // flickering on the Docker Explorer view for each entry
- addConnection(conn, false);
}
}
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DefaultDockerConnectionSettingsFinder.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DefaultDockerConnectionSettingsFinder.java
index cd9df2826f..4412b56057 100644
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DefaultDockerConnectionSettingsFinder.java
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DefaultDockerConnectionSettingsFinder.java
@@ -263,7 +263,7 @@ public class DefaultDockerConnectionSettingsFinder
if (obj instanceof IDockerConnectionSettingsProvider) {
List<IDockerConnectionSettings> settings = ((IDockerConnectionSettingsProvider) obj)
.getConnectionSettings();
- if (settings != null) {
+ if (settings != null && !settings.isEmpty()) {
result.addAll(settings);
}
}
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DefaultTCPConnectionSettingsProvider.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DefaultTCPConnectionSettingsProvider.java
index 71670bf680..7a33e5e2e0 100644
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DefaultTCPConnectionSettingsProvider.java
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DefaultTCPConnectionSettingsProvider.java
@@ -11,6 +11,7 @@
package org.eclipse.linuxtools.internal.docker.core;
import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import org.eclipse.linuxtools.docker.core.DockerException;
@@ -29,9 +30,9 @@ public class DefaultTCPConnectionSettingsProvider implements IDockerConnectionSe
conn.open(false);
conn.close();
} catch (DockerException e) {
- return null;
+ return Collections.emptyList();
}
- return Arrays.asList(new IDockerConnectionSettings[] { tcp });
+ return Arrays.asList(tcp);
}
}
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DefaultUnixConnectionSettingsProvider.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DefaultUnixConnectionSettingsProvider.java
index f13efdc4c2..b9c010b61d 100644
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DefaultUnixConnectionSettingsProvider.java
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DefaultUnixConnectionSettingsProvider.java
@@ -13,6 +13,7 @@ package org.eclipse.linuxtools.internal.docker.core;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import org.eclipse.linuxtools.docker.core.IDockerConnectionSettings;
@@ -36,12 +37,12 @@ public class DefaultUnixConnectionSettingsProvider implements IDockerConnectionS
final UnixSocketConnectionSettings socket = new UnixSocketConnectionSettings(
DefaultDockerConnectionSettingsFinder.Defaults.DEFAULT_UNIX_SOCKET_PATH);
socket.setName(socket.getPath());
- return Arrays.asList(new IDockerConnectionSettings[] { socket });
+ return Arrays.asList(socket);
} catch (IOException e) {
// do nothing, just assume socket did not work.
}
}
- return null;
+ return Collections.emptyList();
}
}
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/ShellConnectionSettingsProvider.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/ShellConnectionSettingsProvider.java
index 4135c3fd47..04e1dee3c6 100644
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/ShellConnectionSettingsProvider.java
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/ShellConnectionSettingsProvider.java
@@ -17,6 +17,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import java.util.Properties;
@@ -37,7 +38,7 @@ public class ShellConnectionSettingsProvider implements IDockerConnectionSetting
if (connectionSettingsDetectionScriptName == null) {
Activator.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
Messages.Docker_No_Settings_Description_Script));
- return null;
+ return Collections.emptyList();
}
final File connectionSettingsDetectionScript = getConnectionSettingsDetectionScript(
connectionSettingsDetectionScriptName);
@@ -52,7 +53,10 @@ public class ShellConnectionSettingsProvider implements IDockerConnectionSetting
final Properties dockerSettings = new Properties();
dockerSettings.load(processInputStream);
IDockerConnectionSettings setting = createDockerConnectionSettings(dockerSettings);
- return Arrays.asList(new IDockerConnectionSettings [] { setting });
+ if (setting == null) {
+ return Collections.emptyList();
+ }
+ return Arrays.asList(setting);
} else {
// log what happened if the process did not end as expected
// an exit value of 1 should indicate no connection found
@@ -70,7 +74,7 @@ public class ShellConnectionSettingsProvider implements IDockerConnectionSetting
Activator.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID,
Messages.Retrieve_Default_Settings_Failure, e));
}
- return null;
+ return Collections.emptyList();
}
/**
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/SystemConnectionSettingsProvider.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/SystemConnectionSettingsProvider.java
index 95fb8f7095..69f948b69c 100644
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/SystemConnectionSettingsProvider.java
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/SystemConnectionSettingsProvider.java
@@ -11,6 +11,7 @@
package org.eclipse.linuxtools.internal.docker.core;
import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import org.eclipse.linuxtools.docker.core.IDockerConnectionSettings;
@@ -24,9 +25,9 @@ public class SystemConnectionSettingsProvider implements IDockerConnectionSettin
if (dockerHostEnv != null) {
String pathToCertificates = System.getenv(DefaultDockerConnectionSettingsFinder.DOCKER_CERT_PATH);
TCPConnectionSettings tcp = new TCPConnectionSettings(dockerHostEnv, pathToCertificates);
- return Arrays.asList(new IDockerConnectionSettings[] { tcp });
+ return Arrays.asList(tcp);
}
- return null;
+ return Collections.emptyList();
}
}
diff --git a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/docker/core/DockerConnectionManagerTest.java b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/docker/core/DockerConnectionManagerTest.java
index 1226a9f1a8..76384aa52d 100644
--- a/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/docker/core/DockerConnectionManagerTest.java
+++ b/containers/org.eclipse.linuxtools.docker.ui.tests/src/org/eclipse/linuxtools/docker/core/DockerConnectionManagerTest.java
@@ -124,7 +124,7 @@ public class DockerConnectionManagerTest {
final String socketPath = "unix:///foo/bar/baz/docker.sock";
UnixSocketConnectionSettings unix = new UnixSocketConnectionSettings(socketPath);
unix.setName(socketPath);
- return Arrays.asList(new IDockerConnectionSettings[] { unix });
+ return Arrays.asList(unix);
}
}
@@ -135,7 +135,7 @@ public class DockerConnectionManagerTest {
final String tcpCertPath = "/foo/bar/baz/certs";
TCPConnectionSettings tcp = new TCPConnectionSettings(tcpHost, tcpCertPath);
tcp.setName(tcpHost);
- return Arrays.asList(new IDockerConnectionSettings[] { tcp });
+ return Arrays.asList(tcp);
}
}
}

Back to the top