forked from I2P_Developers/i2p.i2p
i2psnark: Fix NPE caused by URL-to-URI conversion in -2 (ticket #1715)
Fix some other similar places
This commit is contained in:
@ -907,6 +907,8 @@ public class TrackerClient implements Runnable {
|
|||||||
if (!"http".equals(url.getScheme()))
|
if (!"http".equals(url.getScheme()))
|
||||||
return null;
|
return null;
|
||||||
String host = url.getHost();
|
String host = url.getHost();
|
||||||
|
if (host == null)
|
||||||
|
return null;
|
||||||
if (host.endsWith(".i2p"))
|
if (host.endsWith(".i2p"))
|
||||||
return ConvertToHash.getHash(host);
|
return ConvertToHash.getHash(host);
|
||||||
if (host.equals("i2p")) {
|
if (host.equals("i2p")) {
|
||||||
|
@ -116,6 +116,8 @@ public class I2PSocketEepGet extends EepGet {
|
|||||||
URI url = new URI(_actualURL);
|
URI url = new URI(_actualURL);
|
||||||
if ("http".equals(url.getScheme())) {
|
if ("http".equals(url.getScheme())) {
|
||||||
String host = url.getHost();
|
String host = url.getHost();
|
||||||
|
if (host == null)
|
||||||
|
throw new MalformedURLException("no hostname: " + _actualURL);
|
||||||
int port = url.getPort();
|
int port = url.getPort();
|
||||||
if (port <= 0 || port > 65535)
|
if (port <= 0 || port > 65535)
|
||||||
port = 80;
|
port = 80;
|
||||||
|
@ -731,11 +731,17 @@ public class EepGet {
|
|||||||
// RFC 1945 (HTTP/1.0 1996), so it isn't clear what the point of this is.
|
// 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.
|
// This oddly adds a ":" even if no port, but that seems to work.
|
||||||
URI url = new URI(_actualURL);
|
URI url = new URI(_actualURL);
|
||||||
if (_redirectLocation.startsWith("/"))
|
String host = url.getHost();
|
||||||
_actualURL = "http://" + url.getHost() + ":" + url.getPort() + _redirectLocation;
|
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
|
else
|
||||||
// this blows up completely on a redirect to https://, for example
|
// 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) {
|
} catch (URISyntaxException use) {
|
||||||
IOException ioe = new MalformedURLException("Redirected to invalid URL");
|
IOException ioe = new MalformedURLException("Redirected to invalid URL");
|
||||||
@ -1232,6 +1238,8 @@ public class EepGet {
|
|||||||
URI url = new URI(_actualURL);
|
URI url = new URI(_actualURL);
|
||||||
if ("http".equals(url.getScheme())) {
|
if ("http".equals(url.getScheme())) {
|
||||||
String host = url.getHost();
|
String host = url.getHost();
|
||||||
|
if (host == null)
|
||||||
|
throw new MalformedURLException("URL is not supported:" + _actualURL);
|
||||||
String hostlc = host.toLowerCase(Locale.US);
|
String hostlc = host.toLowerCase(Locale.US);
|
||||||
if (hostlc.endsWith(".i2p"))
|
if (hostlc.endsWith(".i2p"))
|
||||||
throw new UnknownHostException("I2P addresses must be proxied");
|
throw new UnknownHostException("I2P addresses must be proxied");
|
||||||
|
@ -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.
|
// 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.
|
// This oddly adds a ":" even if no port, but that seems to work.
|
||||||
URI url = new URI(_actualURL);
|
URI url = new URI(_actualURL);
|
||||||
if (_redirectLocation.startsWith("/"))
|
String host = url.getHost();
|
||||||
_actualURL = "http://" + url.getHost() + ":" + url.getPort() + _redirectLocation;
|
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
|
else
|
||||||
// this blows up completely on a redirect to https://, for example
|
// 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) {
|
} catch (URISyntaxException use) {
|
||||||
IOException ioe = new MalformedURLException("Redirected to invalid URL");
|
IOException ioe = new MalformedURLException("Redirected to invalid URL");
|
||||||
@ -264,6 +270,8 @@ public class EepHead extends EepGet {
|
|||||||
throw ioe;
|
throw ioe;
|
||||||
}
|
}
|
||||||
String host = url.getHost();
|
String host = url.getHost();
|
||||||
|
if (host == null)
|
||||||
|
throw new MalformedURLException("Bad URL");
|
||||||
int port = url.getPort();
|
int port = url.getPort();
|
||||||
String path = url.getRawPath();
|
String path = url.getRawPath();
|
||||||
String query = url.getRawQuery();
|
String query = url.getRawQuery();
|
||||||
|
@ -560,6 +560,8 @@ public class SSLEepGet extends EepGet {
|
|||||||
URI url = new URI(_actualURL);
|
URI url = new URI(_actualURL);
|
||||||
if ("https".equals(url.getScheme())) {
|
if ("https".equals(url.getScheme())) {
|
||||||
host = url.getHost();
|
host = url.getHost();
|
||||||
|
if (host == null)
|
||||||
|
throw new MalformedURLException("Bad URL");
|
||||||
if (host.toLowerCase(Locale.US).endsWith(".i2p"))
|
if (host.toLowerCase(Locale.US).endsWith(".i2p"))
|
||||||
throw new MalformedURLException("I2P addresses unsupported");
|
throw new MalformedURLException("I2P addresses unsupported");
|
||||||
port = url.getPort();
|
port = url.getPort();
|
||||||
|
Reference in New Issue
Block a user