diff options
author | jfrijters <jfrijters> | 2011-11-28 12:14:13 +0400 |
---|---|---|
committer | jfrijters <jfrijters> | 2011-11-28 12:14:13 +0400 |
commit | 36de8254587f91c6d34b66a35d54d118f4b3f30e (patch) | |
tree | 8690bcf5196f0d237192b4c338b842662844801b | |
parent | a64f51c5b4223f855a64fa593ff2e9d833444fee (diff) |
Relax class name validation for trusted class loaders.
-rw-r--r-- | openjdk/java/lang/ClassLoader.java | 10 | ||||
-rw-r--r-- | runtime/ClassFile.cs | 21 | ||||
-rw-r--r-- | runtime/ClassLoaderWrapper.cs | 14 | ||||
-rw-r--r-- | runtime/openjdk.cs | 4 |
4 files changed, 39 insertions, 10 deletions
diff --git a/openjdk/java/lang/ClassLoader.java b/openjdk/java/lang/ClassLoader.java index 9052a753..ffd944f3 100644 --- a/openjdk/java/lang/ClassLoader.java +++ b/openjdk/java/lang/ClassLoader.java @@ -2219,6 +2219,16 @@ public abstract class ClassLoader { // Retrieves the assertion directives from the VM. private static native AssertionStatusDirectives retrieveDirectives(); + + // [IKVM] equivalent of HotSpot's java_lang_ClassLoader::is_trusted_loader() + static boolean isTrustedLoader(ClassLoader loader) { + ClassLoader cl = scl; + while (cl != null) { + if (cl == loader) return true; + cl = cl.parent; + } + return false; + } } diff --git a/runtime/ClassFile.cs b/runtime/ClassFile.cs index 88d2bdee..99842eb5 100644 --- a/runtime/ClassFile.cs +++ b/runtime/ClassFile.cs @@ -51,6 +51,7 @@ namespace IKVM.Internal None = 0, LocalVariableTable = 1, LineNumberTable = 2, + RelaxedClassNameValidation = 4, } sealed class ClassFile @@ -244,7 +245,7 @@ namespace IKVM.Internal { try { - constantpool[i].Resolve(this); + constantpool[i].Resolve(this, options); } catch(ClassFormatError x) { @@ -1275,7 +1276,7 @@ namespace IKVM.Internal internal abstract class ConstantPoolItem { - internal virtual void Resolve(ClassFile classFile) + internal virtual void Resolve(ClassFile classFile, ClassFileParseOptions options) { } @@ -1301,7 +1302,7 @@ namespace IKVM.Internal name_index = br.ReadUInt16(); } - internal override void Resolve(ClassFile classFile) + internal override void Resolve(ClassFile classFile, ClassFileParseOptions options) { name = classFile.GetConstantPoolUtf8String(name_index); if(name.Length > 0) @@ -1310,7 +1311,7 @@ namespace IKVM.Internal // class names for the system (and boot) class loader. We still need to enforce the 1.5 restrictions, because we // rely on those invariants. #if !STATIC_COMPILER - if(classFile.MajorVersion < 49) + if(classFile.MajorVersion < 49 && (options & ClassFileParseOptions.RelaxedClassNameValidation) == 0) { char prev = name[0]; if(Char.IsLetter(prev) || prev == '$' || prev == '_' || prev == '[' || prev == '/') @@ -1441,7 +1442,7 @@ namespace IKVM.Internal name_and_type_index = br.ReadUInt16(); } - internal override void Resolve(ClassFile classFile) + internal override void Resolve(ClassFile classFile, ClassFileParseOptions options) { ConstantPoolItemNameAndType name_and_type = (ConstantPoolItemNameAndType)classFile.GetConstantPoolItem(name_and_type_index); clazz = (ConstantPoolItemClass)classFile.GetConstantPoolItem(class_index); @@ -1799,7 +1800,7 @@ namespace IKVM.Internal descriptor_index = br.ReadUInt16(); } - internal override void Resolve(ClassFile classFile) + internal override void Resolve(ClassFile classFile, ClassFileParseOptions options) { if(classFile.GetConstantPoolUtf8String(name_index) == null || classFile.GetConstantPoolUtf8String(descriptor_index) == null) @@ -1821,7 +1822,7 @@ namespace IKVM.Internal method_index = br.ReadUInt16(); } - internal override void Resolve(ClassFile classFile) + internal override void Resolve(ClassFile classFile, ClassFileParseOptions options) { switch ((RefKind)ref_kind) { @@ -1909,7 +1910,7 @@ namespace IKVM.Internal signature_index = br.ReadUInt16(); } - internal override void Resolve(ClassFile classFile) + internal override void Resolve(ClassFile classFile, ClassFileParseOptions options) { string descriptor = classFile.GetConstantPoolUtf8String(signature_index); if (descriptor == null || !IsValidMethodSig(descriptor)) @@ -1972,7 +1973,7 @@ namespace IKVM.Internal name_and_type_index = br.ReadUInt16(); } - internal override void Resolve(ClassFile classFile) + internal override void Resolve(ClassFile classFile, ClassFileParseOptions options) { ConstantPoolItemNameAndType name_and_type = (ConstantPoolItemNameAndType)classFile.GetConstantPoolItem(name_and_type_index); // if the constant pool items referred to were strings, GetConstantPoolItem returns null @@ -2037,7 +2038,7 @@ namespace IKVM.Internal string_index = br.ReadUInt16(); } - internal override void Resolve(ClassFile classFile) + internal override void Resolve(ClassFile classFile, ClassFileParseOptions options) { s = classFile.GetConstantPoolUtf8String(string_index); } diff --git a/runtime/ClassLoaderWrapper.cs b/runtime/ClassLoaderWrapper.cs index ea4bc8ef..8d149b65 100644 --- a/runtime/ClassLoaderWrapper.cs +++ b/runtime/ClassLoaderWrapper.cs @@ -270,6 +270,20 @@ namespace IKVM.Internal } } +#if !STATIC_COMPILER && !STUB_GENERATOR + internal bool RelaxedClassNameValidation + { + get + { +#if FIRST_PASS + return true; +#else + return javaClassLoader == null || java.lang.ClassLoader.isTrustedLoader(javaClassLoader); +#endif + } + } +#endif // !STATIC_COMPILER && !STUB_GENERATOR + internal virtual string SourcePath { get diff --git a/runtime/openjdk.cs b/runtime/openjdk.cs index b681de1f..bedfda38 100644 --- a/runtime/openjdk.cs +++ b/runtime/openjdk.cs @@ -2966,6 +2966,10 @@ namespace IKVM.NativeCode.java { cfp |= ClassFileParseOptions.LocalVariableTable; } + if (classLoaderWrapper.RelaxedClassNameValidation) + { + cfp |= ClassFileParseOptions.RelaxedClassNameValidation; + } ClassFile classFile = new ClassFile(b, off, len, name, cfp); if (name != null && classFile.Name != name) { |