OSDN Git Service

2007-01-26 Andrew Haley <aph@redhat.com>
authoraph <aph@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 29 Jan 2007 13:14:38 +0000 (13:14 +0000)
committeraph <aph@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 29 Jan 2007 13:14:38 +0000 (13:14 +0000)
        * java/lang/natClass.cc (initializeClass): Re-throw
        SecurityExceptions.
        * java/lang/natVMClassLoader.cc (loadClass): checkPackageAccess.
        * java/lang/ClassLoader.java: (loadClass): Likewise.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@121285 138bc75d-0d04-0410-961f-82ee72b054a4

libjava/classpath/lib/java/lang/ClassLoader.class
libjava/java/lang/ClassLoader.java
libjava/java/lang/natClass.cc
libjava/java/lang/natVMClassLoader.cc

index 5cbd090..0810e6c 100644 (file)
Binary files a/libjava/classpath/lib/java/lang/ClassLoader.class and b/libjava/classpath/lib/java/lang/ClassLoader.class differ
index 50bd26f..faec9a7 100644 (file)
@@ -404,6 +404,14 @@ public abstract class ClassLoader
   protected synchronized Class loadClass(String name, boolean resolve)
     throws ClassNotFoundException
   {
+    SecurityManager sm = SecurityManager.current;
+    if (sm != null)
+      {
+       int lastDot = name.lastIndexOf('.');
+       if (lastDot != -1)
+         sm.checkPackageAccess(name.substring(0, lastDot));
+      }
+
     // Arrays are handled specially.
     Class c;
     if (name.length() > 0 && name.charAt(0) == '[')
index 8ac72a4..8af533b 100644 (file)
@@ -50,6 +50,7 @@ details.  */
 #include <java/lang/NullPointerException.h>
 #include <java/lang/RuntimePermission.h>
 #include <java/lang/System.h>
+#include <java/lang/SecurityException.h>
 #include <java/lang/SecurityManager.h>
 #include <java/lang/StringBuffer.h>
 #include <java/lang/VMClassLoader.h>
@@ -690,6 +691,10 @@ java::lang::Class::initializeClass (void)
          {
            _Jv_Linker::wait_for_state(this, JV_STATE_LINKED);
          }
+       catch (java::lang::SecurityException *x)
+         {
+           throw x;
+         }
        catch (java::lang::Throwable *x)
          {
            // Turn into a NoClassDefFoundError.
@@ -727,6 +732,10 @@ java::lang::Class::initializeClass (void)
        {
          _Jv_InitClass (superclass);
        }
+      catch (java::lang::SecurityException *x)
+       {
+         throw x;
+       }
       catch (java::lang::Throwable *except)
        {
          // Caught an exception.
@@ -745,6 +754,10 @@ java::lang::Class::initializeClass (void)
       if (meth)
        ((void (*) (void)) meth->ncode) ();
     }
+  catch (java::lang::SecurityException *x)
+    {
+      throw x;
+    }
   catch (java::lang::Throwable *except)
     {
       if (! java::lang::Error::class$.isInstance(except))
index 2db2429..3e5ff3e 100644 (file)
@@ -32,8 +32,10 @@ details.  */
 #include <java/security/ProtectionDomain.h>
 #include <java/lang/ClassFormatError.h>
 #include <java/lang/StringBuffer.h>
+#include <java/lang/SecurityManager.h>
 #include <java/lang/Runtime.h>
 #include <java/util/HashSet.h>
+#include <java/lang/SecurityException.h>
 #include <java/lang/VirtualMachineError.h>
 
 java::lang::Class *
@@ -204,6 +206,16 @@ java::lang::VMClassLoader::nativeFindClass (jstring name)
 jclass
 java::lang::VMClassLoader::loadClass(jstring name, jboolean resolve)
 {
+  using namespace ::java::lang;
+
+  SecurityManager *sm = (SecurityManager *)SecurityManager::current;
+  if (sm)
+    {
+      jint lastDot = name->lastIndexOf('.');
+      if (lastDot != -1)
+       sm->checkPackageAccess(name->substring(0, lastDot));
+    }
+
   // We try the boot loader first, so that the endorsed directory
   // overrides compiled-in classes.
   jclass klass = NULL;