This commit is contained in:
Alan Bateman 2016-12-16 08:18:00 +00:00
commit 6b87f1990b
6 changed files with 46 additions and 51 deletions

View file

@ -4705,16 +4705,7 @@ bool ClassFileParser::verify_unqualified_name(const char* name,
for (const char* p = name; p != name + length;) { for (const char* p = name; p != name + length;) {
jchar ch = *p; jchar ch = *p;
if (ch < 128) { if (ch < 128) {
if (ch == '.') { if (ch == '.' || ch == ';' || ch == '[' ) {
// permit '.' in module names unless it's the first char, or
// preceding char is also a '.', or last char is a '.'.
if ((type != ClassFileParser::LegalModule) ||
(p == name) || (*(p-1) == '.') ||
(p == name + length - 1)) {
return false;
}
}
if (ch == ';' || ch == '[' ) {
return false; // do not permit '.', ';', or '[' return false; // do not permit '.', ';', or '['
} }
if (ch == '/') { if (ch == '/') {

View file

@ -72,7 +72,7 @@ class ClassFileParser VALUE_OBJ_CLASS_SPEC {
NOF_PUBLICITY_LEVELS NOF_PUBLICITY_LEVELS
}; };
enum { LegalClass, LegalField, LegalMethod, LegalModule }; // used to verify unqualified names enum { LegalClass, LegalField, LegalMethod }; // used to verify unqualified names
private: private:
const ClassFileStream* _stream; // Actual input stream const ClassFileStream* _stream; // Actual input stream

View file

@ -51,10 +51,7 @@
static bool verify_module_name(char *module_name) { static bool verify_module_name(char *module_name) {
if (module_name == NULL) return false; if (module_name == NULL) return false;
int len = (int)strlen(module_name); int len = (int)strlen(module_name);
return (len > 0 && len <= Symbol::max_length() && return (len > 0 && len <= Symbol::max_length());
UTF8::is_legal_utf8((unsigned char *)module_name, len, false) &&
ClassFileParser::verify_unqualified_name(module_name, len,
ClassFileParser::LegalModule));
} }
bool Modules::verify_package_name(char *package_name) { bool Modules::verify_package_name(char *package_name) {

View file

@ -32,7 +32,6 @@ import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.function.Supplier;
/** /**
* A container of modules that acts as a ModuleFinder for testing * A container of modules that acts as a ModuleFinder for testing
@ -52,12 +51,13 @@ class ModuleLibrary implements ModuleFinder {
URI uri = URI.create("module:/" + descriptor.name()); URI uri = URI.create("module:/" + descriptor.name());
Supplier<ModuleReader> supplier = () -> { ModuleReference mref = new ModuleReference(descriptor, uri) {
throw new UnsupportedOperationException(); @Override
public ModuleReader open() {
throw new UnsupportedOperationException();
}
}; };
ModuleReference mref = new ModuleReference(descriptor, uri, supplier);
namesToReference.put(name, mref); namesToReference.put(name, mref);
} }
} }

View file

@ -58,9 +58,9 @@ public class JVMDefineModule {
*/ */
// NULL package argument, should not throw an exception // NULL package argument, should not throw an exception
m = ModuleHelper.ModuleObject("mymodule2", cl, new String[] { "nullpkg" }); m = ModuleHelper.ModuleObject("mymoduleTwo", cl, new String[] { "nullpkg" });
assertNotNull(m, "Module should not be null"); assertNotNull(m, "Module should not be null");
ModuleHelper.DefineModule(m, "9.0", "mymodule2/here", null); ModuleHelper.DefineModule(m, "9.0", "mymoduleTwo/here", null);
// Null module argument, expect an NPE // Null module argument, expect an NPE
try { try {
@ -160,7 +160,7 @@ public class JVMDefineModule {
// Expected // Expected
} }
// Bad module name, expect an IAE // Module name with ';', not allowed in java source
try { try {
m = ModuleHelper.ModuleObject("bad;name", cl, new String[] { "mypackage9" }); m = ModuleHelper.ModuleObject("bad;name", cl, new String[] { "mypackage9" });
ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "mypackage9" }); ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "mypackage9" });
@ -169,7 +169,7 @@ public class JVMDefineModule {
// Expected // Expected
} }
// Bad module name, expect an IAE // Module name with leading dot, not allowed in java source
try { try {
m = ModuleHelper.ModuleObject(".leadingdot", cl, new String[] { "mypackage9a" }); m = ModuleHelper.ModuleObject(".leadingdot", cl, new String[] { "mypackage9a" });
ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "mypackage9a" }); ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "mypackage9a" });
@ -178,7 +178,7 @@ public class JVMDefineModule {
// Expected // Expected
} }
// Bad module name, expect an IAE // Module name with trailing dot, not allowed in java source
try { try {
m = ModuleHelper.ModuleObject("trailingdot.", cl, new String[] { "mypackage9b" }); m = ModuleHelper.ModuleObject("trailingdot.", cl, new String[] { "mypackage9b" });
ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "mypackage9b" }); ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "mypackage9b" });
@ -187,11 +187,11 @@ public class JVMDefineModule {
// Expected // Expected
} }
// Bad module name, expect an IAE // Module name with consecutive dots, not allowed in java source
m = ModuleHelper.ModuleObject("consecutive..dots", cl, new String[] { "mypackage9c" });
try { try {
ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "mypackage9c" }); m = ModuleHelper.ModuleObject("trailingdot.", cl, new String[] { "mypackage9b" });
throw new RuntimeException("Failed to get expected IAE for consecutive..dots"); ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "mypackage9b" });
throw new RuntimeException("Failed to get expected IAE for trailingdot.");
} catch(IllegalArgumentException e) { } catch(IllegalArgumentException e) {
// Expected // Expected
} }
@ -207,7 +207,7 @@ public class JVMDefineModule {
ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { }); ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { });
// Invalid package name, expect an IAE // Invalid package name, expect an IAE
m = ModuleHelper.ModuleObject("module5", cl, new String[] { "your.package" }); m = ModuleHelper.ModuleObject("moduleFive", cl, new String[] { "your.package" });
try { try {
ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "your.package" }); ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "your.package" });
throw new RuntimeException("Failed to get expected IAE for your.package"); throw new RuntimeException("Failed to get expected IAE for your.package");
@ -218,7 +218,7 @@ public class JVMDefineModule {
} }
// Invalid package name, expect an IAE // Invalid package name, expect an IAE
m = ModuleHelper.ModuleObject("module6", cl, new String[] { "foo" }); // Name irrelevant m = ModuleHelper.ModuleObject("moduleSix", cl, new String[] { "foo" }); // Name irrelevant
try { try {
ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { ";your/package" }); ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { ";your/package" });
throw new RuntimeException("Failed to get expected IAE for ;your.package"); throw new RuntimeException("Failed to get expected IAE for ;your.package");
@ -229,7 +229,7 @@ public class JVMDefineModule {
} }
// Invalid package name, expect an IAE // Invalid package name, expect an IAE
m = ModuleHelper.ModuleObject("module7", cl, new String[] { "foo" }); // Name irrelevant m = ModuleHelper.ModuleObject("moduleSeven", cl, new String[] { "foo" }); // Name irrelevant
try { try {
ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "7[743" }); ModuleHelper.DefineModule(m, "9.0", "module.name/here", new String[] { "7[743" });
throw new RuntimeException("Failed to get expected IAE for package 7[743"); throw new RuntimeException("Failed to get expected IAE for package 7[743");
@ -240,10 +240,10 @@ public class JVMDefineModule {
} }
// Package named "java" defined to a class loader other than the boot or platform class loader, expect an IAE // Package named "java" defined to a class loader other than the boot or platform class loader, expect an IAE
m = ModuleHelper.ModuleObject("modulejavapkg1", cl, new String[] { "java/foo" }); m = ModuleHelper.ModuleObject("modulejavapkgOne", cl, new String[] { "java/foo" });
try { try {
// module m is defined to an instance of MyClassLoader class loader // module m is defined to an instance of MyClassLoader class loader
ModuleHelper.DefineModule(m, "9.0", "modulejavapkg1", new String[] { "java/foo" }); ModuleHelper.DefineModule(m, "9.0", "modulejavapkgOne", new String[] { "java/foo" });
throw new RuntimeException("Failed to get expected IAE for package java/foo"); throw new RuntimeException("Failed to get expected IAE for package java/foo");
} catch(IllegalArgumentException e) { } catch(IllegalArgumentException e) {
if (!e.getMessage().contains("prohibited package name")) { if (!e.getMessage().contains("prohibited package name")) {
@ -252,43 +252,43 @@ public class JVMDefineModule {
} }
// Package named "javabar" defined to a class loader other than the boot or platform class loader, should be ok // Package named "javabar" defined to a class loader other than the boot or platform class loader, should be ok
m = ModuleHelper.ModuleObject("modulejavapkg2", cl, new String[] { "javabar" }); m = ModuleHelper.ModuleObject("modulejavapkgTwo", cl, new String[] { "javabar" });
assertNotNull(m, "Module should not be null"); assertNotNull(m, "Module should not be null");
ModuleHelper.DefineModule(m, "9.0", "modulejavapkg2", new String[] { "javabar" }); ModuleHelper.DefineModule(m, "9.0", "modulejavapkgTwo", new String[] { "javabar" });
// Package named "java" defined to the boot class loader, should be ok // Package named "java" defined to the boot class loader, should be ok
// m's type is a java.lang.Object, module is java.base // m's type is a java.lang.Object, module is java.base
// java.base module is defined to the boot loader // java.base module is defined to the boot loader
ClassLoader boot_loader = m.getClass().getClassLoader(); ClassLoader boot_loader = m.getClass().getClassLoader();
m = ModuleHelper.ModuleObject("modulejavapkg3", boot_loader, new String[] { "java/foo" }); m = ModuleHelper.ModuleObject("modulejavapkgThree", boot_loader, new String[] { "java/foo" });
assertNotNull(m, "Module should not be null"); assertNotNull(m, "Module should not be null");
ModuleHelper.DefineModule(m, "9.0", "modulejavapkg3", new String[] { "java/foo" }); ModuleHelper.DefineModule(m, "9.0", "modulejavapkgThree", new String[] { "java/foo" });
// Package named "java" defined to the platform class loader, should be ok // Package named "java" defined to the platform class loader, should be ok
// java.sql module defined to the platform class loader. // java.sql module defined to the platform class loader.
java.sql.Time jst = new java.sql.Time(45 * 1000); java.sql.Time jst = new java.sql.Time(45 * 1000);
ClassLoader platform_loader = jst.getClass().getClassLoader(); ClassLoader platform_loader = jst.getClass().getClassLoader();
m = ModuleHelper.ModuleObject("modulejavapkg4", platform_loader, new String[] { "java/foo" }); m = ModuleHelper.ModuleObject("modulejavapkgFour", platform_loader, new String[] { "java/foo" });
assertNotNull(m, "Module should not be null"); assertNotNull(m, "Module should not be null");
ModuleHelper.DefineModule(m, "9.0", "modulejavapkg4", new String[] { "java/foo" }); ModuleHelper.DefineModule(m, "9.0", "modulejavapkgFour", new String[] { "java/foo" });
// module version that is null, should be okay // module version that is null, should be okay
m = ModuleHelper.ModuleObject("module8", cl, new String[] { "a_package_8" }); m = ModuleHelper.ModuleObject("moduleEight", cl, new String[] { "a_package_8" });
assertNotNull(m, "Module should not be null"); assertNotNull(m, "Module should not be null");
ModuleHelper.DefineModule(m, null, "module8/here", new String[] { "a_package_8" }); ModuleHelper.DefineModule(m, null, "moduleEight/here", new String[] { "a_package_8" });
// module version that is "", should be okay // module version that is "", should be okay
m = ModuleHelper.ModuleObject("module9", cl, new String[] { "a_package_9" }); m = ModuleHelper.ModuleObject("moduleNine", cl, new String[] { "a_package_9" });
assertNotNull(m, "Module should not be null"); assertNotNull(m, "Module should not be null");
ModuleHelper.DefineModule(m, "", "module9/here", new String[] { "a_package_9" }); ModuleHelper.DefineModule(m, "", "moduleNine/here", new String[] { "a_package_9" });
// module location that is null, should be okay // module location that is null, should be okay
m = ModuleHelper.ModuleObject("module10", cl, new String[] { "a_package_10" }); m = ModuleHelper.ModuleObject("moduleTen", cl, new String[] { "a_package_10" });
assertNotNull(m, "Module should not be null"); assertNotNull(m, "Module should not be null");
ModuleHelper.DefineModule(m, "9.0", null, new String[] { "a_package_10" }); ModuleHelper.DefineModule(m, "9.0", null, new String[] { "a_package_10" });
// module location that is "", should be okay // module location that is "", should be okay
m = ModuleHelper.ModuleObject("module11", cl, new String[] { "a_package_11" }); m = ModuleHelper.ModuleObject("moduleEleven", cl, new String[] { "a_package_11" });
assertNotNull(m, "Module should not be null"); assertNotNull(m, "Module should not be null");
ModuleHelper.DefineModule(m, "9.0", "", new String[] { "a_package_11" }); ModuleHelper.DefineModule(m, "9.0", "", new String[] { "a_package_11" });
} }

View file

@ -49,6 +49,17 @@ import jdk.test.lib.Asserts;
public class JvmtiGetAllModulesTest { public class JvmtiGetAllModulesTest {
static class MyModuleReference extends ModuleReference {
public MyModuleReference(ModuleDescriptor descriptor, URI uri) {
super(descriptor, uri);
}
// Trivial implementation to make the class non-abstract
public ModuleReader open() {
return null;
}
}
private static native Module[] getModulesNative(); private static native Module[] getModulesNative();
private static Set<Module> getModulesJVMTI() { private static Set<Module> getModulesJVMTI() {
@ -103,11 +114,7 @@ public class JvmtiGetAllModulesTest {
URI uri = URI.create("module:/" + name); URI uri = URI.create("module:/" + name);
Supplier<ModuleReader> supplier = () -> { ModuleReference mref = new MyModuleReference(descriptor, uri);
throw new UnsupportedOperationException();
};
ModuleReference mref = new ModuleReference(descriptor, uri, supplier);
namesToReference.put(name, mref); namesToReference.put(name, mref);
} }