Verified Commit cd4897e6 authored by akwizgran's avatar akwizgran
Browse files

Check whether getNetworkInterfaces() returns null.

parent d84e176b
...@@ -24,7 +24,7 @@ import java.net.SocketException; ...@@ -24,7 +24,7 @@ import java.net.SocketException;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Enumeration;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
...@@ -35,6 +35,9 @@ import java.util.regex.Pattern; ...@@ -35,6 +35,9 @@ import java.util.regex.Pattern;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import static java.net.NetworkInterface.getNetworkInterfaces;
import static java.util.Collections.emptyList;
import static java.util.Collections.list;
import static java.util.logging.Level.INFO; import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING; import static java.util.logging.Level.WARNING;
import static org.briarproject.bramble.util.LogUtils.logException; import static org.briarproject.bramble.util.LogUtils.logException;
...@@ -303,16 +306,16 @@ abstract class TcpPlugin implements DuplexPlugin { ...@@ -303,16 +306,16 @@ abstract class TcpPlugin implements DuplexPlugin {
} }
Collection<InetAddress> getLocalIpAddresses() { Collection<InetAddress> getLocalIpAddresses() {
List<NetworkInterface> ifaces;
try { try {
ifaces = Collections.list(NetworkInterface.getNetworkInterfaces()); Enumeration<NetworkInterface> ifaces = getNetworkInterfaces();
if (ifaces == null) return emptyList();
List<InetAddress> addrs = new ArrayList<>();
for (NetworkInterface iface : list(ifaces))
addrs.addAll(list(iface.getInetAddresses()));
return addrs;
} catch (SocketException e) { } catch (SocketException e) {
logException(LOG, WARNING, e); logException(LOG, WARNING, e);
return Collections.emptyList(); return emptyList();
} }
List<InetAddress> addrs = new ArrayList<>();
for (NetworkInterface iface : ifaces)
addrs.addAll(Collections.list(iface.getInetAddresses()));
return addrs;
} }
} }
...@@ -7,13 +7,15 @@ import java.io.DataOutputStream; ...@@ -7,13 +7,15 @@ import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.NetworkInterface; import java.net.NetworkInterface;
import java.util.Collections; import java.util.Enumeration;
import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Properties; import java.util.Properties;
import javax.annotation.concurrent.Immutable; import javax.annotation.concurrent.Immutable;
import static java.net.NetworkInterface.getNetworkInterfaces;
import static java.util.Collections.list;
@Immutable @Immutable
@NotNullByDefault @NotNullByDefault
abstract class AbstractSecureRandomProvider implements SecureRandomProvider { abstract class AbstractSecureRandomProvider implements SecureRandomProvider {
...@@ -23,13 +25,14 @@ abstract class AbstractSecureRandomProvider implements SecureRandomProvider { ...@@ -23,13 +25,14 @@ abstract class AbstractSecureRandomProvider implements SecureRandomProvider {
out.writeLong(System.currentTimeMillis()); out.writeLong(System.currentTimeMillis());
out.writeLong(System.nanoTime()); out.writeLong(System.nanoTime());
out.writeLong(Runtime.getRuntime().freeMemory()); out.writeLong(Runtime.getRuntime().freeMemory());
List<NetworkInterface> ifaces = Enumeration<NetworkInterface> ifaces = getNetworkInterfaces();
Collections.list(NetworkInterface.getNetworkInterfaces()); if (ifaces != null) {
for (NetworkInterface i : ifaces) { for (NetworkInterface i : list(ifaces)) {
List<InetAddress> addrs = Collections.list(i.getInetAddresses()); for (InetAddress a : list(i.getInetAddresses()))
for (InetAddress a : addrs) out.write(a.getAddress()); out.write(a.getAddress());
byte[] hardware = i.getHardwareAddress(); byte[] hardware = i.getHardwareAddress();
if (hardware != null) out.write(hardware); if (hardware != null) out.write(hardware);
}
} }
for (Entry<String, String> e : System.getenv().entrySet()) { for (Entry<String, String> e : System.getenv().entrySet()) {
out.writeUTF(e.getKey()); out.writeUTF(e.getKey());
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment