natClass.cc (initializeClass): Re-throw SecurityExceptions.

2007-01-26  Andrew Haley  <aph@redhat.com>

        * java/lang/natClass.cc (initializeClass): Re-throw
        SecurityExceptions.
        * java/lang/natVMClassLoader.cc (loadClass): checkPackageAccess.
        * java/lang/ClassLoader.java: (loadClass): Likewise.

From-SVN: r121285
This commit is contained in:
Andrew Haley 2007-01-29 13:14:38 +00:00
parent 2631dfddd2
commit 6b05e79165
4 changed files with 33 additions and 0 deletions

View 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) == '[')

View 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))

View 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;