8208754: The fix for JDK-8194534 needs updates
authorweijun
Wed, 08 Aug 2018 08:05:43 +0800
changeset 52171 0da586f1ed05
parent 52170 2990f1e1c325
child 52172 f54dcfc5a5f8
8208754: The fix for JDK-8194534 needs updates Reviewed-by: alanb, igerasim, rhalade, mullan
src/java.base/share/classes/java/util/jar/JarFile.java
src/java.base/share/classes/java/util/jar/JavaUtilJarAccessImpl.java
src/java.base/share/classes/java/util/jar/Manifest.java
src/java.base/share/classes/jdk/internal/loader/URLClassPath.java
src/java.base/share/classes/jdk/internal/misc/JavaUtilJarAccess.java
--- a/src/java.base/share/classes/java/util/jar/JarFile.java	Mon Jul 30 13:53:30 2018 -0400
+++ b/src/java.base/share/classes/java/util/jar/JarFile.java	Wed Aug 08 08:05:43 2018 +0800
@@ -1025,7 +1025,7 @@
         }
     }
 
-    private synchronized void ensureInitialization() {
+    synchronized void ensureInitialization() {
         try {
             maybeInstantiateVerifier();
         } catch (IOException e) {
--- a/src/java.base/share/classes/java/util/jar/JavaUtilJarAccessImpl.java	Mon Jul 30 13:53:30 2018 -0400
+++ b/src/java.base/share/classes/java/util/jar/JavaUtilJarAccessImpl.java	Wed Aug 08 08:05:43 2018 +0800
@@ -65,4 +65,7 @@
         return man.getTrustedAttributes(name);
     }
 
+    public void ensureInitialization(JarFile jar) {
+        jar.ensureInitialization();
+    }
 }
--- a/src/java.base/share/classes/java/util/jar/Manifest.java	Mon Jul 30 13:53:30 2018 -0400
+++ b/src/java.base/share/classes/java/util/jar/Manifest.java	Wed Aug 08 08:05:43 2018 +0800
@@ -169,6 +169,10 @@
      *      does not exist in SF files of all signers).
      */
     Attributes getTrustedAttributes(String name) {
+        // Note: Before the verification of MANIFEST.MF/.SF/.RSA files is done,
+        // jv.isTrustedManifestEntry() isn't able to detect MANIFEST.MF change.
+        // Users of this method should call SharedSecrets.javaUtilJarAccess()
+        // .ensureInitialization() first.
         Attributes result = getAttributes(name);
         if (result != null && jv != null && ! jv.isTrustedManifestEntry(name)) {
             throw new SecurityException("Untrusted manifest entry: " + name);
--- a/src/java.base/share/classes/jdk/internal/loader/URLClassPath.java	Mon Jul 30 13:53:30 2018 -0400
+++ b/src/java.base/share/classes/jdk/internal/loader/URLClassPath.java	Wed Aug 08 08:05:43 2018 +0800
@@ -866,8 +866,10 @@
                     { return jar.getInputStream(entry); }
                 public int getContentLength()
                     { return (int)entry.getSize(); }
-                public Manifest getManifest() throws IOException
-                    { return jar.getManifest(); };
+                public Manifest getManifest() throws IOException {
+                    SharedSecrets.javaUtilJarAccess().ensureInitialization(jar);
+                    return jar.getManifest();
+                }
                 public Certificate[] getCertificates()
                     { return entry.getCertificates(); };
                 public CodeSigner[] getCodeSigners()
--- a/src/java.base/share/classes/jdk/internal/misc/JavaUtilJarAccess.java	Mon Jul 30 13:53:30 2018 -0400
+++ b/src/java.base/share/classes/jdk/internal/misc/JavaUtilJarAccess.java	Wed Aug 08 08:05:43 2018 +0800
@@ -44,4 +44,5 @@
     public void setEagerValidation(JarFile jar, boolean eager);
     public List<Object> getManifestDigests(JarFile jar);
     public Attributes getTrustedAttributes(Manifest man, String name);
+    public void ensureInitialization(JarFile jar);
 }