diff options
author | aph <aph@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-01-29 13:14:38 +0000 |
---|---|---|
committer | aph <aph@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-01-29 13:14:38 +0000 |
commit | abf353fb5f2cb275f93170b048ebfcccf73d9e39 (patch) | |
tree | 40df469186ef32efb4fe4cfc7ff23eb2b0c7e713 /libjava/java | |
parent | afac7ab4964e200686c4b1e79a37d5fde48d75ec (diff) | |
download | ppe42-gcc-abf353fb5f2cb275f93170b048ebfcccf73d9e39.tar.gz ppe42-gcc-abf353fb5f2cb275f93170b048ebfcccf73d9e39.zip |
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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@121285 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/java')
-rw-r--r-- | libjava/java/lang/ClassLoader.java | 8 | ||||
-rw-r--r-- | libjava/java/lang/natClass.cc | 13 | ||||
-rw-r--r-- | libjava/java/lang/natVMClassLoader.cc | 12 |
3 files changed, 33 insertions, 0 deletions
diff --git a/libjava/java/lang/ClassLoader.java b/libjava/java/lang/ClassLoader.java index 50bd26f36b5..faec9a7ebd2 100644 --- a/libjava/java/lang/ClassLoader.java +++ b/libjava/java/lang/ClassLoader.java @@ -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) == '[') diff --git a/libjava/java/lang/natClass.cc b/libjava/java/lang/natClass.cc index 8ac72a403a4..8af533b7769 100644 --- a/libjava/java/lang/natClass.cc +++ b/libjava/java/lang/natClass.cc @@ -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)) diff --git a/libjava/java/lang/natVMClassLoader.cc b/libjava/java/lang/natVMClassLoader.cc index 2db2429c927..3e5ff3ec70e 100644 --- a/libjava/java/lang/natVMClassLoader.cc +++ b/libjava/java/lang/natVMClassLoader.cc @@ -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; |