Deal with ojluni files that include changes beyond OpenJDK 8u121-b13.
Base64: document a change that was integrated from beyond 8u121-b13.
JceSecurity: un-integrate a redundant change so that this file is now
based on upstream OpenJDK 8u121-b13, like most other ojluni files.
DefaultProxySelector: document generally that this file includes
changes beyond 8u121-b13.
JarURLConnection: document a change that was integrated from beyond
8u121-b13.
FtpClient: document a change that was integrated from beyond 8u121-b13.
Bug: 62368386
Test: Treehugger
Change-Id: I1605a979d9ba650346a4fcddeb102cc5644de2c1
diff --git a/ojluni/src/main/java/java/util/Base64.java b/ojluni/src/main/java/java/util/Base64.java
index 61f68d3..be98fad 100644
--- a/ojluni/src/main/java/java/util/Base64.java
+++ b/ojluni/src/main/java/java/util/Base64.java
@@ -788,6 +788,9 @@
public void write(byte[] b, int off, int len) throws IOException {
if (closed)
throw new IOException("Stream is closed");
+ // Android-changed: Upstream fix to avoid overflow.
+ // This upstream fix is from beyond OpenJDK8u121-b13. http://b/62368386
+ // if (off < 0 || len < 0 || off + len > b.length)
if (off < 0 || len < 0 || len > b.length - off)
throw new ArrayIndexOutOfBoundsException();
if (len == 0)
diff --git a/ojluni/src/main/java/javax/crypto/JceSecurity.java b/ojluni/src/main/java/javax/crypto/JceSecurity.java
index 4572627..b0ae07e 100644
--- a/ojluni/src/main/java/javax/crypto/JceSecurity.java
+++ b/ojluni/src/main/java/javax/crypto/JceSecurity.java
@@ -218,7 +218,7 @@
static {
try {
- NULL_URL = new URL("http://null.oracle.com/");
+ NULL_URL = new URL("http://null.sun.com/");
} catch (Exception e) {
throw new RuntimeException(e);
}
@@ -255,69 +255,14 @@
// BEGIN Android-removed: JCE crypto strength restrictions are never in place on Android.
/*
- * This is called from within an doPrivileged block.
- *
- * Following logic is used to decide what policy files are selected.
- *
- * If the new Security property (crypto.policy) is set in the
- * java.security file, or has been set dynamically using the
- * Security.setProperty() call before the JCE framework has
- * been initialized, that setting will be used.
- * Remember - this property is not defined by default. A conscious
- * user edit or an application call is required.
- *
- * Otherwise, if user has policy jar files installed in the legacy
- * jre/lib/security/ directory, the JDK will honor whatever
- * setting is set by those policy files. (legacy/current behavior)
- *
- * If none of the above 2 conditions are met, the JDK will default
- * to using the limited crypto policy files found in the
- * jre/lib/security/policy/limited/ directory
- *
private static void setupJurisdictionPolicies() throws Exception {
- // Sanity check the crypto.policy Security property. Single
- // directory entry, no pseudo-directories (".", "..", leading/trailing
- // path separators). normalize()/getParent() will help later.
- String javaHomeProperty = System.getProperty("java.home");
- String cryptoPolicyProperty = Security.getProperty("crypto.policy");
- Path cpPath = (cryptoPolicyProperty == null) ? null :
- Paths.get(cryptoPolicyProperty);
+ String javaHomeDir = System.getProperty("java.home");
+ String sep = File.separator;
+ String pathToPolicyJar = javaHomeDir + sep + "lib" + sep +
+ "security" + sep;
- if ((cpPath != null) && ((cpPath.getNameCount() != 1) ||
- (cpPath.compareTo(cpPath.getFileName())) != 0)) {
- throw new SecurityException(
- "Invalid policy directory name format: " +
- cryptoPolicyProperty);
- }
-
- if (cpPath == null) {
- // Security property is not set, use default path
- cpPath = Paths.get(javaHomeProperty, "lib", "security");
- } else {
- // populate with java.home
- cpPath = Paths.get(javaHomeProperty, "lib", "security",
- "policy", cryptoPolicyProperty);
- }
-
- if (debug != null) {
- debug.println("crypto policy directory: " + cpPath);
- }
-
- File exportJar = new File(cpPath.toFile(),"US_export_policy.jar");
- File importJar = new File(cpPath.toFile(),"local_policy.jar");
-
- if (cryptoPolicyProperty == null && (!exportJar.exists() ||
- !importJar.exists())) {
- // Compatibility set up. If crypto.policy is not defined.
- // check to see if legacy jars exist in lib directory. If
- // they don't exist, we default to limited policy mode.
- cpPath = Paths.get(
- javaHomeProperty, "lib", "security", "policy", "limited");
- // point to the new jar files in limited directory
- exportJar = new File(cpPath.toFile(),"US_export_policy.jar");
- importJar = new File(cpPath.toFile(),"local_policy.jar");
- }
-
+ File exportJar = new File(pathToPolicyJar, "US_export_policy.jar");
+ File importJar = new File(pathToPolicyJar, "local_policy.jar");
URL jceCipherURL = ClassLoader.getSystemResource
("javax/crypto/Cipher.class");
diff --git a/ojluni/src/main/java/sun/net/ftp/impl/FtpClient.java b/ojluni/src/main/java/sun/net/ftp/impl/FtpClient.java
index 0c117d4..da2a739 100644
--- a/ojluni/src/main/java/sun/net/ftp/impl/FtpClient.java
+++ b/ojluni/src/main/java/sun/net/ftp/impl/FtpClient.java
@@ -517,6 +517,10 @@
* @return <code>true</code> if the command was successful
* @throws IOException
*/
+ // Android-changed: Integrate upstream fix to guard against '\n'.
+ // Integrates OpenJDK's "8170222: Better transfers of files".
+ // See http://b/35784677 .
+ // private boolean issueCommand(String cmd) throws IOException {
private boolean issueCommand(String cmd) throws IOException,
sun.net.ftp.FtpProtocolException {
if (!isConnected()) {
@@ -529,12 +533,14 @@
// ignore...
}
}
+ // BEGIN Android-added: Integrate upstream fix to guard against '\n'.
if (cmd.indexOf('\n') != -1) {
sun.net.ftp.FtpProtocolException ex
= new sun.net.ftp.FtpProtocolException("Illegal FTP command");
ex.initCause(new IllegalArgumentException("Illegal carriage return"));
throw ex;
}
+ // END Android-added: Integrate upstream fix to guard against '\n'.
sendServer(cmd + "\r\n");
return readReply();
}
diff --git a/ojluni/src/main/java/sun/net/spi/DefaultProxySelector.java b/ojluni/src/main/java/sun/net/spi/DefaultProxySelector.java
index fac57e2..2fc7fd1 100644
--- a/ojluni/src/main/java/sun/net/spi/DefaultProxySelector.java
+++ b/ojluni/src/main/java/sun/net/spi/DefaultProxySelector.java
@@ -117,7 +117,9 @@
* basis, and change it only when the "source", i.e. the system property,
* did change.
*/
-
+ // Android-note: Integrated some upstream changes from beyond OpenJDK8u121-b13.
+ // This includes NonProxyInfo.pattern -> hostsPool and associated changes.
+ // See http://b/62368386
static class NonProxyInfo {
// Default value for nonProxyHosts, this provides backward compatibility
// by excluding localhost and its litteral notations.
diff --git a/ojluni/src/main/java/sun/net/www/protocol/jar/JarURLConnection.java b/ojluni/src/main/java/sun/net/www/protocol/jar/JarURLConnection.java
index d7c4424..b0aa959 100644
--- a/ojluni/src/main/java/sun/net/www/protocol/jar/JarURLConnection.java
+++ b/ojluni/src/main/java/sun/net/www/protocol/jar/JarURLConnection.java
@@ -125,8 +125,12 @@
* to get the jarFile, and set it as our permission.
*/
if (getUseCaches()) {
+ // Android-added: Upstream fix to avoid affecting useCaches setting.
+ // This line and the one further down were integrated from an
+ // upstream commit beyond OpenJDK 8u121-b13. See http://b/62368386
boolean oldUseCaches = jarFileURLConnection.getUseCaches();
jarFileURLConnection = factory.getConnection(jarFile);
+ // Android-added: Upstream fix to avoid affecting useCaches setting.
jarFileURLConnection.setUseCaches(oldUseCaches);
}