This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: FYI: fix verifier bug


I'm checking this in on the trunk and the 4.0 branch.

Colin noticed that our verifier incorrect rejects 'new <abstractclass>'.
Instead this should be accepted and then cause an error at runtime.
Apparently some program out there generates bogus bytecode like this
with ASM and then expects it to verify.

The same holds true for interfaces.

I wrote test cases and put them in the mauve 'verify' module.

Note that we fail to detect this error when compiling bytecode BC.
I have filed PR 22377 for this.

Tom

Index: ChangeLog
from  Colin Walters  <walters@verbum.org>

	* verify.cc (class _Jv_BytecodeVerifier) <op_new>: Don't
	check for abstract classes or interfaces here; JVM spec
	says it should throw an exception, so we'll do so later.
	* interpret.cc (run): Throw an InstantiationException for
	abstract classes and interfaces.

Index: interpret.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/interpret.cc,v
retrieving revision 1.52
diff -u -r1.52 interpret.cc
--- interpret.cc 29 Jun 2005 16:18:53 -0000 1.52
+++ interpret.cc 8 Jul 2005 18:55:31 -0000
@@ -30,6 +30,7 @@
 #include <java/lang/NullPointerException.h>
 #include <java/lang/ArithmeticException.h>
 #include <java/lang/IncompatibleClassChangeError.h>
+#include <java/lang/InstantiationException.h>
 #include <java/lang/Thread.h>
 #include <java-insns.h>
 #include <java-signal.h>
@@ -2942,6 +2943,10 @@
 	int index = GET2U ();
 	jclass klass = (_Jv_Linker::resolve_pool_entry (meth->defining_class,
 							  index)).clazz;
+	/* VM spec, section 3.11.5 */
+	if ((klass->getModifiers() & Modifier::ABSTRACT)
+	    || klass->isInterface())
+	  throw new java::lang::InstantiationException;
 	jobject res = _Jv_AllocObject (klass);
 	PUSHA (res);
 
Index: verify.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/verify.cc,v
retrieving revision 1.70
diff -u -r1.70 verify.cc
--- verify.cc 24 Jun 2005 22:09:15 -0000 1.70
+++ verify.cc 8 Jul 2005 18:55:32 -0000
@@ -2926,8 +2926,8 @@
 	  case op_new:
 	    {
 	      type t = check_class_constant (get_ushort ());
-	      if (t.isarray () || t.isinterface (this) || t.isabstract (this))
-		verify_fail ("type is array, interface, or abstract");
+	      if (t.isarray ())
+		verify_fail ("type is array");
 	      t.set_uninitialized (start_PC, this);
 	      push_type (t);
 	    }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]