changeset 1364:389d688e6878 default tip

Merge from main OpenJDK repository
author Greg Lewis <glewis@eyesbeyond.com>
date Sat, 03 Feb 2018 14:01:48 -0800
parents 38dad5afd760 (current diff) a4ce841000ff (diff)
children
files .hgtags
diffstat 3 files changed, 118 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/.hgtags	Thu Sep 07 23:37:09 2017 -0700
+++ b/.hgtags	Sat Feb 03 14:01:48 2018 -0800
@@ -616,3 +616,5 @@
 39240de9d27767c8bad74e34f83f0a4902a9ef85 jdk7u141-b02
 d232281a177cd3f80d48eca3f1bbc3919f720a1e jdk7u151-b00
 f74af33b4963a7c484ffa605f11e41efd92966e3 jdk7u151-b01
+3b0441f9245b4f16adbaad16d9a2aef05cea734c jdk7u161-b00
+8576df4be08028c725c29490eb52a329f361c56c jdk7u161-b01
--- a/THIRD_PARTY_README	Thu Sep 07 23:37:09 2017 -0700
+++ b/THIRD_PARTY_README	Sat Feb 03 14:01:48 2018 -0800
@@ -3134,14 +3134,14 @@
 
 -------------------------------------------------------------------------------
 
-%% This notice is provided with respect to zlib v1.2.3, which is included 
+%% This notice is provided with respect to zlib v1.2.11, which may be included 
 with JRE 7, JDK 7, and OpenJDK 7
 
 --- begin of LICENSE ---
 
-  version 1.2.3, July 18th, 2005
-
-  Copyright (C) 1995-2005 Jean-loup Gailly and Mark Adler
+  version 1.2.11, January 15th, 2017
+
+  Copyright (C) 1995-2017 Jean-loup Gailly and Mark Adler
 
   This software is provided 'as-is', without any express or implied
   warranty.  In no event will the authors be held liable for any damages
--- a/src/share/classes/com/sun/corba/se/impl/io/ObjectStreamClass.java	Thu Sep 07 23:37:09 2017 -0700
+++ b/src/share/classes/com/sun/corba/se/impl/io/ObjectStreamClass.java	Sat Feb 03 14:01:48 2018 -0800
@@ -31,13 +31,17 @@
 
 package com.sun.corba.se.impl.io;
 
+import java.security.AccessControlContext;
+import java.security.AccessController;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.security.DigestOutputStream;
-import java.security.AccessController;
+import java.security.PermissionCollection;
+import java.security.Permissions;
 import java.security.PrivilegedExceptionAction;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedAction;
+import java.security.ProtectionDomain;
 
 import java.lang.reflect.Modifier;
 import java.lang.reflect.Array;
@@ -47,6 +51,7 @@
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Proxy;
 import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.UndeclaredThrowableException;
 
 import java.io.IOException;
 import java.io.DataOutputStream;
@@ -57,6 +62,9 @@
 
 import java.util.Arrays;
 import java.util.Comparator;
+import java.util.HashSet;
+import java.util.Set;
+
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 
@@ -65,6 +73,8 @@
 import org.omg.CORBA.ValueMember;
 
 import sun.corba.Bridge;
+import sun.misc.JavaSecurityAccess;
+import sun.misc.SharedSecrets;
 
 /**
  * A ObjectStreamClass describes a class that can be serialized to a stream
@@ -433,6 +443,65 @@
     private static final PersistentFieldsValue persistentFieldsValue =
         new PersistentFieldsValue();
 
+    /**
+     * Creates a PermissionDomain that grants no permission.
+     */
+    private ProtectionDomain noPermissionsDomain() {
+        PermissionCollection perms = new Permissions();
+        perms.setReadOnly();
+        return new ProtectionDomain(null, perms);
+    }
+
+    /**
+     * Aggregate the ProtectionDomains of all the classes that separate
+     * a concrete class {@code cl} from its ancestor's class declaring
+     * a constructor {@code cons}.
+     *
+     * If {@code cl} is defined by the boot loader, or the constructor
+     * {@code cons} is declared by {@code cl}, or if there is no security
+     * manager, then this method does nothing and {@code null} is returned.
+     *
+     * @param cons A constructor declared by {@code cl} or one of its
+     *             ancestors.
+     * @param cl A concrete class, which is either the class declaring
+     *           the constructor {@code cons}, or a serializable subclass
+     *           of that class.
+     * @return An array of ProtectionDomain representing the set of
+     *         ProtectionDomain that separate the concrete class {@code cl}
+     *         from its ancestor's declaring {@code cons}, or {@code null}.
+     */
+    private ProtectionDomain[] getProtectionDomains(Constructor<?> cons,
+                                                    Class<?> cl) {
+        ProtectionDomain[] domains = null;
+        if (cons != null && cl.getClassLoader() != null
+                && System.getSecurityManager() != null) {
+            Class<?> cls = cl;
+            Class<?> fnscl = cons.getDeclaringClass();
+            Set<ProtectionDomain> pds = null;
+            while (cls != fnscl) {
+                ProtectionDomain pd = cls.getProtectionDomain();
+                if (pd != null) {
+                    if (pds == null) pds = new HashSet<>();
+                    pds.add(pd);
+                }
+                cls = cls.getSuperclass();
+                if (cls == null) {
+                    // that's not supposed to happen
+                    // make a ProtectionDomain with no permission.
+                    // should we throw instead?
+                    if (pds == null) pds = new HashSet<>();
+                    else pds.clear();
+                    pds.add(noPermissionsDomain());
+                    break;
+                }
+            }
+            if (pds != null) {
+                domains = pds.toArray(new ProtectionDomain[0]);
+            }
+        }
+        return domains;
+    }
+
     /*
      * Initialize class descriptor.  This method is only invoked on class
      * descriptors created via calls to lookupInternal().  This method is kept
@@ -566,11 +635,15 @@
                 readResolveObjectMethod = ObjectStreamClass.getInheritableMethod(cl,
                     "readResolve", noTypesList, Object.class);
 
+                domains = new ProtectionDomain[] {noPermissionsDomain()};
+
                 if (externalizable)
                     cons = getExternalizableConstructor(cl) ;
                 else
                     cons = getSerializableConstructor(cl) ;
 
+                domains = getProtectionDomains(cons, cl);
+
                 if (serializable && !forProxyClass) {
                     /* Look for the writeObject method
                      * Set the accessible flag on it here. ObjectOutputStream
@@ -916,20 +989,53 @@
         throws InstantiationException, InvocationTargetException,
                UnsupportedOperationException
     {
+        if (!initialized)
+            throw new InternalError("Unexpected call when not initialized");
         if (cons != null) {
             try {
-                return cons.newInstance(new Object[0]);
+                if (domains == null || domains.length == 0) {
+                    return cons.newInstance();
+                } else {
+                    JavaSecurityAccess jsa = SharedSecrets.getJavaSecurityAccess();
+                    PrivilegedAction<?> pea = (PrivilegedAction<?>) new PrivilegedAction() {
+                        public Object run() {
+                            try {
+                                return cons.newInstance();
+                            } catch (InstantiationException
+                                     | InvocationTargetException
+                                     | IllegalAccessException x) {
+                                throw new UndeclaredThrowableException(x);
+                            }
+                        }
+                    }; // Can't use PrivilegedExceptionAction with jsa
+                    try {
+                        return jsa.doIntersectionPrivilege(pea,
+                                   AccessController.getContext(),
+                                   new AccessControlContext(domains));
+                    } catch (UndeclaredThrowableException x) {
+                        Throwable cause = x.getCause();
+                        if (cause instanceof InstantiationException)
+                            throw (InstantiationException) cause;
+                        if (cause instanceof InvocationTargetException)
+                            throw (InvocationTargetException) cause;
+                        if (cause instanceof IllegalAccessException)
+                            throw (IllegalAccessException) cause;
+                        // not supposed to happen
+                        throw x;
+                    }
+                }
             } catch (IllegalAccessException ex) {
                 // should not occur, as access checks have been suppressed
                 InternalError ie = new InternalError();
-                ie.initCause( ex ) ;
-                throw ie ;
+                ie.initCause(ex);
+                throw ie;
             }
         } else {
             throw new UnsupportedOperationException();
         }
     }
 
+
     /**
      * Returns public no-arg constructor of given class, or null if none found.
      * Access checks are disabled on the returned constructor (if any), since
@@ -1540,7 +1646,8 @@
     Method readObjectMethod;
     private transient Method writeReplaceObjectMethod;
     private transient Method readResolveObjectMethod;
-    private Constructor cons ;
+    private Constructor<?> cons;
+    private transient ProtectionDomain[] domains;
 
     /**
      * Beginning in Java to IDL ptc/02-01-12, RMI-IIOP has a