diff src/share/vm/classfile/verifier.cpp @ 18007:364b73402247

Merge
author asaha
date Thu, 22 May 2014 11:09:06 -0700
parents 386dd1c71858 b5ae226b7516
children f73af4455d7d
line wrap: on
line diff
--- a/src/share/vm/classfile/verifier.cpp	Tue May 13 23:17:52 2014 -0700
+++ b/src/share/vm/classfile/verifier.cpp	Thu May 22 11:09:06 2014 -0700
@@ -632,6 +632,9 @@
   bool no_control_flow = false; // Set to true when there is no direct control
                                 // flow from current instruction to the next
                                 // instruction in sequence
+
+  set_furthest_jump(0);
+
   Bytecodes::Code opcode;
   while (!bcs.is_last_bytecode()) {
     // Check for recursive re-verification before each bytecode.
@@ -2245,6 +2248,29 @@
           "Bad <init> method call");
       return;
     }
+
+    // Make sure that this call is not jumped over.
+    if (bci < furthest_jump()) {
+      verify_error(ErrorContext::bad_code(bci),
+                   "Bad <init> method call from inside of a branch");
+      return;
+    }
+
+    // Make sure that this call is not done from within a TRY block because
+    // that can result in returning an incomplete object.  Simply checking
+    // (bci >= start_pc) also ensures that this call is not done after a TRY
+    // block.  That is also illegal because this call must be the first Java
+    // statement in the constructor.
+    ExceptionTable exhandlers(_method());
+    int exlength = exhandlers.length();
+    for(int i = 0; i < exlength; i++) {
+      if (bci >= exhandlers.start_pc(i)) {
+        verify_error(ErrorContext::bad_code(bci),
+                     "Bad <init> method call from after the start of a try block");
+        return;
+      }
+    }
+
     current_frame->initialize_object(type, current_type());
     *this_uninit = true;
   } else if (type.is_uninitialized()) {
@@ -2280,8 +2306,12 @@
         ref_class_type.name(), CHECK_VERIFY(this));
       Method* m = InstanceKlass::cast(ref_klass)->uncached_lookup_method(
         vmSymbols::object_initializer_name(),
-        cp->signature_ref_at(bcs->get_index_u2()),
-        Klass::normal);
+        cp->signature_ref_at(bcs->get_index_u2()), Klass::normal);
+      if (m == NULL) {
+        verify_error(ErrorContext::bad_code(bci),
+            "Call to missing <init> method");
+        return;
+      }
       instanceKlassHandle mh(THREAD, m->method_holder());
       if (m->is_protected() && !mh->is_same_class_package(_klass())) {
         bool assignable = current_type().is_assignable_from(