← Back to team overview

openjdk team mailing list archive

Bug#826059: java may crash when loading a class named java

 

Package: openjdk-8-jre-headless
Version: 8u91-b14-2
Tags: patch

JVM may crash when trying to load a class named "java" in default package.

How to reproduce:
* Create a file named "java.java" with content "class java{}".
* Compile it: `javac java.java'.
* Try to run it: `java -cp "$PWD" java'. For some reason, running without `-cp' flag doesn't seem to trigger it.
* It may not crash on the first try. It may be necessary to run it multiple times before it crashes.

I attached a patch that should fix this problem.
--- a/hotspot/src/share/vm/classfile/systemDictionary.cpp
+++ b/hotspot/src/share/vm/classfile/systemDictionary.cpp
@@ -1087,6 +1087,7 @@
   if (!HAS_PENDING_EXCEPTION &&
       !class_loader.is_null() &&
       parsed_name != NULL &&
+      parsed_name->utf8_length() >= strlen(pkg) &&
       !strncmp((const char*)parsed_name->bytes(), pkg, strlen(pkg))) {
     // It is illegal to define classes in the "java." package from
     // JVM_DefineClass or jni_DefineClass unless you're the bootclassloader