diff --git a/apps/i2psnark/java/src/org/klomp/snark/TrackerClient.java b/apps/i2psnark/java/src/org/klomp/snark/TrackerClient.java index fc48c6d87be8fa7b99827a06e3885071c447aefd..5397cd757bfa48982e3ef9e217c347c7fd1bc592 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/TrackerClient.java +++ b/apps/i2psnark/java/src/org/klomp/snark/TrackerClient.java @@ -907,6 +907,8 @@ public class TrackerClient implements Runnable { if (!"http".equals(url.getScheme())) return null; String host = url.getHost(); + if (host == null) + return null; if (host.endsWith(".i2p")) return ConvertToHash.getHash(host); if (host.equals("i2p")) { diff --git a/apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketEepGet.java b/apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketEepGet.java index 73ede8bb057acb4b05e333e50d700ee3b029c6c1..bd82c12f3a7eb08a74424daba45bad73aa472e3d 100644 --- a/apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketEepGet.java +++ b/apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketEepGet.java @@ -116,6 +116,8 @@ public class I2PSocketEepGet extends EepGet { URI url = new URI(_actualURL); if ("http".equals(url.getScheme())) { String host = url.getHost(); + if (host == null) + throw new MalformedURLException("no hostname: " + _actualURL); int port = url.getPort(); if (port <= 0 || port > 65535) port = 80; diff --git a/core/java/src/net/i2p/util/EepGet.java b/core/java/src/net/i2p/util/EepGet.java index 19816bb41d2b58489bb7ac815a1ef0eaf4897cac..1c2406291a1bdc18d039763bcba151d87bfda842 100644 --- a/core/java/src/net/i2p/util/EepGet.java +++ b/core/java/src/net/i2p/util/EepGet.java @@ -731,11 +731,17 @@ public class EepGet { // RFC 1945 (HTTP/1.0 1996), so it isn't clear what the point of this is. // This oddly adds a ":" even if no port, but that seems to work. URI url = new URI(_actualURL); - if (_redirectLocation.startsWith("/")) - _actualURL = "http://" + url.getHost() + ":" + url.getPort() + _redirectLocation; + String host = url.getHost(); + if (host == null) + throw new MalformedURLException("Redirected to invalid URL"); + int port = url.getPort(); + if (port < 0) + port = 80; + if (_redirectLocation.startsWith("/")) + _actualURL = "http://" + host + ":" + port + _redirectLocation; else // this blows up completely on a redirect to https://, for example - _actualURL = "http://" + url.getHost() + ":" + url.getPort() + "/" + _redirectLocation; + _actualURL = "http://" + host+ ":" + port + "/" + _redirectLocation; } } catch (URISyntaxException use) { IOException ioe = new MalformedURLException("Redirected to invalid URL"); @@ -1232,6 +1238,8 @@ public class EepGet { URI url = new URI(_actualURL); if ("http".equals(url.getScheme())) { String host = url.getHost(); + if (host == null) + throw new MalformedURLException("URL is not supported:" + _actualURL); String hostlc = host.toLowerCase(Locale.US); if (hostlc.endsWith(".i2p")) throw new UnknownHostException("I2P addresses must be proxied"); diff --git a/core/java/src/net/i2p/util/EepHead.java b/core/java/src/net/i2p/util/EepHead.java index 3c53314937885dd862a985b80e3c34f9c543fed5..c9f375e4584a31f3c6fca76d1b159e88e5dc1909 100644 --- a/core/java/src/net/i2p/util/EepHead.java +++ b/core/java/src/net/i2p/util/EepHead.java @@ -186,11 +186,17 @@ public class EepHead extends EepGet { // RFC 1945 (HTTP/1.0 1996), so it isn't clear what the point of this is. // This oddly adds a ":" even if no port, but that seems to work. URI url = new URI(_actualURL); - if (_redirectLocation.startsWith("/")) - _actualURL = "http://" + url.getHost() + ":" + url.getPort() + _redirectLocation; + String host = url.getHost(); + if (host == null) + throw new MalformedURLException("Redirected to invalid URL"); + int port = url.getPort(); + if (port < 0) + port = 80; + if (_redirectLocation.startsWith("/")) + _actualURL = "http://" + host + ":" + port + _redirectLocation; else // this blows up completely on a redirect to https://, for example - _actualURL = "http://" + url.getHost() + ":" + url.getPort() + "/" + _redirectLocation; + _actualURL = "http://" + host+ ":" + port + "/" + _redirectLocation; } } catch (URISyntaxException use) { IOException ioe = new MalformedURLException("Redirected to invalid URL"); @@ -264,6 +270,8 @@ public class EepHead extends EepGet { throw ioe; } String host = url.getHost(); + if (host == null) + throw new MalformedURLException("Bad URL"); int port = url.getPort(); String path = url.getRawPath(); String query = url.getRawQuery(); diff --git a/core/java/src/net/i2p/util/SSLEepGet.java b/core/java/src/net/i2p/util/SSLEepGet.java index c62da0c12518ca3d76396ea4a35d35fa1ef32925..35905dec210ad057adabeb82169cacbabf5eef97 100644 --- a/core/java/src/net/i2p/util/SSLEepGet.java +++ b/core/java/src/net/i2p/util/SSLEepGet.java @@ -560,6 +560,8 @@ public class SSLEepGet extends EepGet { URI url = new URI(_actualURL); if ("https".equals(url.getScheme())) { host = url.getHost(); + if (host == null) + throw new MalformedURLException("Bad URL"); if (host.toLowerCase(Locale.US).endsWith(".i2p")) throw new MalformedURLException("I2P addresses unsupported"); port = url.getPort();