changeset 12767:8f941bab493f

8180565: Null pointer dereferences of ConstMethod::method() Summary: We need to check ConstMethod::method() for NULL before dereferencing. Reviewed-by: kvn, iignatyev
author thartmann
date Mon, 22 May 2017 09:14:10 +0200
parents 34c47915ae05
children 0b218e675429
files src/share/vm/oops/constMethod.cpp
diffstat 1 files changed, 13 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/oops/constMethod.cpp	Fri May 19 15:32:17 2017 +0530
+++ b/src/share/vm/oops/constMethod.cpp	Mon May 22 09:14:10 2017 +0200
@@ -407,8 +407,12 @@
   ResourceMark rm;
   assert(is_constMethod(), "must be constMethod");
   st->print_cr("%s", internal_name());
-  st->print(" - method:       " INTPTR_FORMAT " ", p2i((address)method()));
-  method()->print_value_on(st); st->cr();
+  Method* m = method();
+  st->print(" - method:       " INTPTR_FORMAT " ", p2i((address)m));
+  if (m != NULL) {
+    m->print_value_on(st);
+  }
+  st->cr();
   if (has_stackmap_table()) {
     st->print(" - stackmap data:       ");
     stackmap_data()->print_value_on(st);
@@ -421,7 +425,12 @@
 void ConstMethod::print_value_on(outputStream* st) const {
   assert(is_constMethod(), "must be constMethod");
   st->print(" const part of method " );
-  method()->print_value_on(st);
+  Method* m = method();
+  if (m != NULL) {
+    m->print_value_on(st);
+  } else {
+    st->print("NULL");
+  }
 }
 
 #if INCLUDE_SERVICES
@@ -461,7 +470,7 @@
 
   // Verification can occur during oop construction before the method or
   // other fields have been initialized.
-  guarantee(method()->is_method(), "should be method");
+  guarantee(method() != NULL && method()->is_method(), "should be method");
 
   address m_end = (address)((intptr_t) this + size());
   address compressed_table_start = code_end();