# HG changeset patch # User msheppar # Date 1467820411 -3600 # Node ID ec09e1a100e39c51a8209d093cf53cc6e5b7c61c # Parent 70009cc2ecb382e270b49d2460476918b3a063e9 8079718: IIOP Input Stream Hooking Reviewed-by: rriggs, ahgross, coffeys, skoivu diff -r 70009cc2ecb3 -r ec09e1a100e3 src/share/classes/com/sun/corba/se/impl/orbutil/ORBUtility.java --- a/src/share/classes/com/sun/corba/se/impl/orbutil/ORBUtility.java Mon Apr 18 04:46:01 2016 +0100 +++ b/src/share/classes/com/sun/corba/se/impl/orbutil/ORBUtility.java Wed Jul 06 16:53:31 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -34,21 +34,13 @@ import java.security.Policy; import java.security.PrivilegedAction; import java.security.ProtectionDomain; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Map; -import java.util.List; -import java.util.ListIterator; -import java.util.Set; -import java.util.Map.Entry; -import java.util.Collection; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; import java.util.HashMap; import java.util.HashSet; import java.util.Hashtable; import java.util.Iterator; import java.util.Enumeration; -import java.util.Properties; -import java.util.IdentityHashMap; import java.util.StringTokenizer; import java.util.NoSuchElementException; @@ -165,8 +157,18 @@ * Return default ValueHandler */ public static ValueHandler createValueHandler() { + ValueHandler vh; + try { + vh = AccessController.doPrivileged(new PrivilegedExceptionAction() { + public ValueHandler run() throws Exception { return Util.createValueHandler(); } + }); + } catch (PrivilegedActionException e) { + throw new InternalError(e.getMessage()); + } + return vh; + } /** * Returns true if it was accurately determined that the remote ORB is @@ -664,7 +666,16 @@ * ValueHandler. */ public static byte getMaxStreamFormatVersion() { - ValueHandler vh = Util.createValueHandler(); + ValueHandler vh; + try { + vh = AccessController.doPrivileged(new PrivilegedExceptionAction() { + public ValueHandler run() throws Exception { + return Util.createValueHandler(); + } + }); + } catch (PrivilegedActionException e) { + throw new InternalError(e.getMessage()); + } if (!(vh instanceof javax.rmi.CORBA.ValueHandlerMultiFormat)) return ORBConstants.STREAM_FORMAT_VERSION_1; diff -r 70009cc2ecb3 -r ec09e1a100e3 src/share/classes/javax/rmi/CORBA/Util.java --- a/src/share/classes/javax/rmi/CORBA/Util.java Mon Apr 18 04:46:01 2016 +0100 +++ b/src/share/classes/javax/rmi/CORBA/Util.java Wed Jul 06 16:53:31 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -45,6 +45,7 @@ import java.rmi.Remote; import java.io.File; import java.io.FileInputStream; +import java.io.SerializablePermission; import java.net.MalformedURLException ; import java.security.AccessController; import java.security.PrivilegedAction; @@ -63,8 +64,22 @@ private static final javax.rmi.CORBA.UtilDelegate utilDelegate; private static final String UtilClassKey = "javax.rmi.CORBA.UtilClass"; + private static final String ALLOW_CREATEVALUEHANDLER_PROP = "jdk.rmi.CORBA.allowCustomValueHandler"; + private static boolean allowCustomValueHandler; + static { utilDelegate = (javax.rmi.CORBA.UtilDelegate)createDelegate(UtilClassKey); + allowCustomValueHandler = readAllowCustomValueHandlerProperty(); + } + + private static boolean readAllowCustomValueHandlerProperty () { + return AccessController + .doPrivileged(new PrivilegedAction() { + @Override + public Boolean run() { + return Boolean.getBoolean(ALLOW_CREATEVALUEHANDLER_PROP); + } + }); } private Util(){} @@ -111,7 +126,7 @@ * Writes a java.lang.Object as a CORBA Object. If obj is * an exported RMI-IIOP server object, the tie is found * and wired to obj, then written to -out.write_Object(org.omg.CORBA.Object). + * out.write_Object(org.omg.CORBA.Object). * If obj is a CORBA Object, it is written to * out.write_Object(org.omg.CORBA.Object). * @param out the stream in which to write the object. @@ -196,6 +211,8 @@ */ public static ValueHandler createValueHandler() { + isCustomSerializationPermitted(); + if (utilDelegate != null) { return utilDelegate.createValueHandler(); } @@ -336,6 +353,7 @@ // security reasons. If you know a better solution how to share this code // then remove it from PortableRemoteObject. Also in Stub.java private static Object createDelegate(String classKey) { + String className = (String) AccessController.doPrivileged(new GetPropertyAction(classKey)); if (className == null) { @@ -388,4 +406,16 @@ new GetORBPropertiesFileAction()); } + private static void isCustomSerializationPermitted() { + SecurityManager sm = System.getSecurityManager(); + if (!allowCustomValueHandler) { + if ( sm != null) { + // check that a serialization permission has been + // set to allow the loading of the Util delegate + // which provides access to custom ValueHandler + sm.checkPermission(new SerializablePermission( + "enableCustomValueHandler")); + } + } + } }