harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From var...@apache.org
Subject svn commit: r598262 - in /harmony/enhanced/drlvm/trunk/vm: tests/kernel/java/lang/reflect/ tests/kernel/org/apache/harmony/test/ tests/kernel_resources/org/apache/harmony/lang/test/resource/ vmcore/src/kernel_classes/javasrc/java/lang/reflect/
Date Mon, 26 Nov 2007 13:09:24 GMT
Author: varlax
Date: Mon Nov 26 05:09:23 2007
New Revision: 598262

URL: http://svn.apache.org/viewvc?rev=598262&view=rev
Log:
Fixed HARMONY-5179 [drlvm][security] Accessing members of non-public class is allowed

Added:
    harmony/enhanced/drlvm/trunk/vm/tests/kernel_resources/org/apache/harmony/lang/test/resource/DefaultMethodInvoker.java
  (with props)
Modified:
    harmony/enhanced/drlvm/trunk/vm/tests/kernel/java/lang/reflect/MethodTestInvoke.java
    harmony/enhanced/drlvm/trunk/vm/tests/kernel/org/apache/harmony/test/TestResources.java
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/reflect/ReflectExporter.java

Modified: harmony/enhanced/drlvm/trunk/vm/tests/kernel/java/lang/reflect/MethodTestInvoke.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/kernel/java/lang/reflect/MethodTestInvoke.java?rev=598262&r1=598261&r2=598262&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/kernel/java/lang/reflect/MethodTestInvoke.java (original)
+++ harmony/enhanced/drlvm/trunk/vm/tests/kernel/java/lang/reflect/MethodTestInvoke.java Mon
Nov 26 05:09:23 2007
@@ -26,6 +26,7 @@
 import org.apache.harmony.lang.C2;
 import org.apache.harmony.lang.ProtectedMethod;
 import org.apache.harmony.lang.ProtectedSuccessor;
+import org.apache.harmony.test.TestResources;
 
 import junit.framework.TestCase;
 
@@ -36,6 +37,26 @@
     
     public static void doFail() {
         throw new MyException();
+    }
+
+    /**
+     * Regression test for HARMONY-5179.
+     */
+    public void testLoaderAccess() throws Throwable {
+        ClassLoader l1 = TestResources.createLoader();
+        ClassLoader l2 = TestResources.createLoader();
+        Class c1 = l1.loadClass("org.apache.harmony.lang.test.resource.DefaultMethodInvoker");
+        Class c2 = l2.loadClass("org.apache.harmony.lang.test.resource.DefaultMethodInvoker");
+        Method m1 = c1.getMethod("run", new Class[] {Method.class, Object.class, Object[].class});

+        Method m2 = c2.getMethod("dummy", new Class[] {});
+        try {
+            m1.setAccessible(true);
+            m1.invoke(null, new Object[] {m2, null, null});
+            fail("Access to package methods should be checked with runtime packages");
+        } catch (InvocationTargetException expected) {
+            Throwable cause = expected.getCause();
+            assertTrue("bad cause: " + cause, cause instanceof IllegalAccessException);
+        }
     }
     
     /**

Modified: harmony/enhanced/drlvm/trunk/vm/tests/kernel/org/apache/harmony/test/TestResources.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/kernel/org/apache/harmony/test/TestResources.java?rev=598262&r1=598261&r2=598262&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/kernel/org/apache/harmony/test/TestResources.java
(original)
+++ harmony/enhanced/drlvm/trunk/vm/tests/kernel/org/apache/harmony/test/TestResources.java
Mon Nov 26 05:09:23 2007
@@ -48,23 +48,27 @@
      */
     public static ClassLoader getLoader() {
         if (loader == null) {
-            URL url = null;
-            try {
-                String path = System.getProperty(RESOURCE_PATH, ".");
-                File f = new File(path);
-                if (f.exists()) {
-                    url = f.toURI().toURL();
-                } else {
-                    url = new URL(path);
-                }
-            } catch (MalformedURLException e) {
-                throw new RuntimeException(
-                        "Misconfigured path to test resources. "
-                                + "Please set correct value of system property: "
-                                + RESOURCE_PATH, e);
-            }
-            loader = URLClassLoader.newInstance(new URL[] { url });
+            loader = createLoader();
         }
         return loader;
+    }
+    
+    public static ClassLoader createLoader() {
+        URL url = null;
+        try {
+            String path = System.getProperty(RESOURCE_PATH, ".");
+            File f = new File(path);
+            if (f.exists()) {
+                url = f.toURI().toURL();
+            } else {
+                url = new URL(path);
+            }
+        } catch (MalformedURLException e) {
+            throw new RuntimeException(
+                    "Misconfigured path to test resources. "
+                            + "Please set correct value of system property: "
+                            + RESOURCE_PATH, e);
+        }
+        return URLClassLoader.newInstance(new URL[] { url });        
     }
 }

Added: harmony/enhanced/drlvm/trunk/vm/tests/kernel_resources/org/apache/harmony/lang/test/resource/DefaultMethodInvoker.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/kernel_resources/org/apache/harmony/lang/test/resource/DefaultMethodInvoker.java?rev=598262&view=auto
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/kernel_resources/org/apache/harmony/lang/test/resource/DefaultMethodInvoker.java
(added)
+++ harmony/enhanced/drlvm/trunk/vm/tests/kernel_resources/org/apache/harmony/lang/test/resource/DefaultMethodInvoker.java
Mon Nov 26 05:09:23 2007
@@ -0,0 +1,29 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.harmony.lang.test.resource;
+
+import java.lang.reflect.Method;
+
+class DefaultMethodInvoker {
+
+    public static void run(Method m, Object obj, Object ... args) 
+    throws Throwable {
+        m.invoke(obj, args);
+    }
+    
+    public static void dummy() {}
+}

Propchange: harmony/enhanced/drlvm/trunk/vm/tests/kernel_resources/org/apache/harmony/lang/test/resource/DefaultMethodInvoker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/reflect/ReflectExporter.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/reflect/ReflectExporter.java?rev=598262&r1=598261&r2=598262&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/reflect/ReflectExporter.java
(original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/reflect/ReflectExporter.java
Mon Nov 26 05:09:23 2007
@@ -183,6 +183,9 @@
     }
 
     private boolean hasSamePackage(Class<?> class1, Class<?> class2) {
+        if (class1.getClassLoader() != class2.getClassLoader()) {
+            return false;
+        }
         final String pkg1 = class1.getName();
         final String pkg2 = class2.getName();
         int i1 = pkg1.lastIndexOf('.');



Mime
View raw message