This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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: verifier bug fix


I'm checking this in on the trunk.

This fixes a small bytecode verifier bug.  We didn't correctly handle
(invalid) code that falls off the end of the bytecode.  Instead, we
crashed.

Tom

Index: gcc/java/ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	* verify-impl.c (verify_instructions_0): Correctly handle
	situation where PC falls off end.

Index: gcc/java/verify-impl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/verify-impl.c,v
retrieving revision 1.9
diff -u -r1.9 verify-impl.c
--- gcc/java/verify-impl.c 9 Jun 2005 10:55:02 -0000 1.9
+++ gcc/java/verify-impl.c 24 Jun 2005 22:06:54 -0000
@@ -2251,10 +2251,12 @@
       else
 	{
 	  /* We only have to do this checking in the situation where
-	     control flow falls through from the previous
-	     instruction.  Otherwise merging is done at the time we
-	     push the branch.  */
-	  if (vfr->states[vfr->PC] != NULL)
+	     control flow falls through from the previous instruction.
+	     Otherwise merging is done at the time we push the branch.
+	     Note that we'll catch the off-the-end problem just
+	     below.  */
+	  if (vfr->PC < vfr->current_method->code_length
+	      && vfr->states[vfr->PC] != NULL)
 	    {
 	      /* We've already visited this instruction.  So merge
 	         the states together.  It is simplest, but not most
Index: libjava/ChangeLog
from  Tom Tromey  <tromey@redhat.com>
	* verify.cc (verify_instructions_0): Correctly handle situation
	where PC falls off end.

Index: libjava/verify.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/verify.cc,v
retrieving revision 1.69
diff -u -r1.69 verify.cc
--- libjava/verify.cc 5 Apr 2005 22:26:22 -0000 1.69
+++ libjava/verify.cc 24 Jun 2005 22:06:57 -0000
@@ -2198,8 +2198,9 @@
 	    // We only have to do this checking in the situation where
 	    // control flow falls through from the previous
 	    // instruction.  Otherwise merging is done at the time we
-	    // push the branch.
-	    if (states[PC] != NULL)
+	    // push the branch.  Note that we'll catch the
+	    // off-the-end problem just below.
+	    if (PC < current_method->code_length && states[PC] != NULL)
 	      {
 		// We've already visited this instruction.  So merge
 		// the states together.  It is simplest, but not most


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