diff src/share/vm/prims/jvm.cpp @ 24003:0a78f55d49fa

8036630: Null ProtectionDomain in JVM can cause NPE because principals field is not initialized to an empty array Summary: Call ProtectionDomain constructor instead of making all fields null. Reviewed-by: fparain, zgu
author robm
date Thu, 05 May 2016 13:28:49 +0100
parents 3c8b53552a43
children e828a0e2a4bc
line wrap: on
line diff
--- a/src/share/vm/prims/jvm.cpp	Tue Apr 26 02:49:59 2016 +0100
+++ b/src/share/vm/prims/jvm.cpp	Thu May 05 13:28:49 2016 +0100
@@ -1290,18 +1290,22 @@
 // and null permissions - which gives no permissions.
 oop create_dummy_access_control_context(TRAPS) {
   InstanceKlass* pd_klass = InstanceKlass::cast(SystemDictionary::ProtectionDomain_klass());
-  // new ProtectionDomain(null,null);
-  oop null_protection_domain = pd_klass->allocate_instance(CHECK_NULL);
-  Handle null_pd(THREAD, null_protection_domain);
+  Handle obj = pd_klass->allocate_instance_handle(CHECK_NULL);
+  // Call constructor ProtectionDomain(null, null);
+  JavaValue result(T_VOID);
+  JavaCalls::call_special(&result, obj, KlassHandle(THREAD, pd_klass),
+                          vmSymbols::object_initializer_name(),
+                          vmSymbols::codesource_permissioncollection_signature(),
+                          Handle(), Handle(), CHECK_NULL);
 
   // new ProtectionDomain[] {pd};
   objArrayOop context = oopFactory::new_objArray(pd_klass, 1, CHECK_NULL);
-  context->obj_at_put(0, null_pd());
+  context->obj_at_put(0, obj());
 
   // new AccessControlContext(new ProtectionDomain[] {pd})
   objArrayHandle h_context(THREAD, context);
-  oop result = java_security_AccessControlContext::create(h_context, false, Handle(), CHECK_NULL);
-  return result;
+  oop acc = java_security_AccessControlContext::create(h_context, false, Handle(), CHECK_NULL);
+  return acc;
 }
 
 JVM_ENTRY(jobject, JVM_DoPrivileged(JNIEnv *env, jclass cls, jobject action, jobject context, jboolean wrapException))