Mercurial > hg > graal-jvmci-8
comparison src/share/vm/prims/jvm.cpp @ 7588:f9eb431c3efe
8006005: Fix constant pool index validation and alignment trap for method parameter reflection
Summary: This patch addresses an alignment trap due to the storage format of method parameters data in constMethod. It also adds code to validate constant pool indexes for method parameters data.
Reviewed-by: jrose, dholmes
Contributed-by: eric.mccorkle@oracle.com
author | coleenp |
---|---|
date | Mon, 14 Jan 2013 11:01:39 -0500 |
parents | ade95d680b42 |
children | f422634e5828 b14da2e6f2dc |
comparison
equal
deleted
inserted
replaced
7586:90a92d5bca17 | 7588:f9eb431c3efe |
---|---|
1587 } | 1587 } |
1588 } | 1588 } |
1589 return NULL; | 1589 return NULL; |
1590 JVM_END | 1590 JVM_END |
1591 | 1591 |
1592 static void bounds_check(constantPoolHandle cp, jint index, TRAPS) { | |
1593 if (!cp->is_within_bounds(index)) { | |
1594 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "Constant pool index out of bounds"); | |
1595 } | |
1596 } | |
1597 | |
1592 JVM_ENTRY(jobjectArray, JVM_GetMethodParameters(JNIEnv *env, jobject method)) | 1598 JVM_ENTRY(jobjectArray, JVM_GetMethodParameters(JNIEnv *env, jobject method)) |
1593 { | 1599 { |
1594 JVMWrapper("JVM_GetMethodParameters"); | 1600 JVMWrapper("JVM_GetMethodParameters"); |
1595 // method is a handle to a java.lang.reflect.Method object | 1601 // method is a handle to a java.lang.reflect.Method object |
1596 Method* method_ptr = jvm_get_method_common(method); | 1602 Method* method_ptr = jvm_get_method_common(method); |
1597 methodHandle mh (THREAD, method_ptr); | 1603 methodHandle mh (THREAD, method_ptr); |
1598 Handle reflected_method (THREAD, JNIHandles::resolve_non_null(method)); | 1604 Handle reflected_method (THREAD, JNIHandles::resolve_non_null(method)); |
1599 const int num_params = mh->method_parameters_length(); | 1605 const int num_params = mh->method_parameters_length(); |
1600 | 1606 |
1601 if(0 != num_params) { | 1607 if (0 != num_params) { |
1608 // make sure all the symbols are properly formatted | |
1609 for (int i = 0; i < num_params; i++) { | |
1610 MethodParametersElement* params = mh->method_parameters_start(); | |
1611 int index = params[i].name_cp_index; | |
1612 bounds_check(mh->constants(), index, CHECK_NULL); | |
1613 | |
1614 if (0 != index && !mh->constants()->tag_at(index).is_utf8()) { | |
1615 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), | |
1616 "Wrong type at constant pool index"); | |
1617 } | |
1618 | |
1619 } | |
1620 | |
1602 objArrayOop result_oop = oopFactory::new_objArray(SystemDictionary::reflect_Parameter_klass(), num_params, CHECK_NULL); | 1621 objArrayOop result_oop = oopFactory::new_objArray(SystemDictionary::reflect_Parameter_klass(), num_params, CHECK_NULL); |
1603 objArrayHandle result (THREAD, result_oop); | 1622 objArrayHandle result (THREAD, result_oop); |
1604 | 1623 |
1605 for(int i = 0; i < num_params; i++) { | 1624 for (int i = 0; i < num_params; i++) { |
1606 MethodParametersElement* params = mh->method_parameters_start(); | 1625 MethodParametersElement* params = mh->method_parameters_start(); |
1607 Symbol* const sym = mh->constants()->symbol_at(params[i].name_cp_index); | 1626 // For a 0 index, give a NULL symbol |
1627 Symbol* const sym = 0 != params[i].name_cp_index ? | |
1628 mh->constants()->symbol_at(params[i].name_cp_index) : NULL; | |
1629 int flags = build_int_from_shorts(params[i].flags_lo, params[i].flags_hi); | |
1608 oop param = Reflection::new_parameter(reflected_method, i, sym, | 1630 oop param = Reflection::new_parameter(reflected_method, i, sym, |
1609 params[i].flags, CHECK_NULL); | 1631 flags, CHECK_NULL); |
1610 result->obj_at_put(i, param); | 1632 result->obj_at_put(i, param); |
1611 } | 1633 } |
1612 return (jobjectArray)JNIHandles::make_local(env, result()); | 1634 return (jobjectArray)JNIHandles::make_local(env, result()); |
1613 } else { | 1635 } else { |
1614 return (jobjectArray)NULL; | 1636 return (jobjectArray)NULL; |
1828 return cp->length(); | 1850 return cp->length(); |
1829 } | 1851 } |
1830 JVM_END | 1852 JVM_END |
1831 | 1853 |
1832 | 1854 |
1833 static void bounds_check(constantPoolHandle cp, jint index, TRAPS) { | |
1834 if (!cp->is_within_bounds(index)) { | |
1835 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "Constant pool index out of bounds"); | |
1836 } | |
1837 } | |
1838 | |
1839 | |
1840 JVM_ENTRY(jclass, JVM_ConstantPoolGetClassAt(JNIEnv *env, jobject obj, jobject unused, jint index)) | 1855 JVM_ENTRY(jclass, JVM_ConstantPoolGetClassAt(JNIEnv *env, jobject obj, jobject unused, jint index)) |
1841 { | 1856 { |
1842 JVMWrapper("JVM_ConstantPoolGetClassAt"); | 1857 JVMWrapper("JVM_ConstantPoolGetClassAt"); |
1843 constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); | 1858 constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); |
1844 bounds_check(cp, index, CHECK_NULL); | 1859 bounds_check(cp, index, CHECK_NULL); |
1848 } | 1863 } |
1849 Klass* k = cp->klass_at(index, CHECK_NULL); | 1864 Klass* k = cp->klass_at(index, CHECK_NULL); |
1850 return (jclass) JNIHandles::make_local(k->java_mirror()); | 1865 return (jclass) JNIHandles::make_local(k->java_mirror()); |
1851 } | 1866 } |
1852 JVM_END | 1867 JVM_END |
1853 | |
1854 | 1868 |
1855 JVM_ENTRY(jclass, JVM_ConstantPoolGetClassAtIfLoaded(JNIEnv *env, jobject obj, jobject unused, jint index)) | 1869 JVM_ENTRY(jclass, JVM_ConstantPoolGetClassAtIfLoaded(JNIEnv *env, jobject obj, jobject unused, jint index)) |
1856 { | 1870 { |
1857 JVMWrapper("JVM_ConstantPoolGetClassAtIfLoaded"); | 1871 JVMWrapper("JVM_ConstantPoolGetClassAtIfLoaded"); |
1858 constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); | 1872 constantPoolHandle cp = constantPoolHandle(THREAD, sun_reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj))); |