comparison src/share/vm/classfile/classFileParser.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 adc176e95bf2
children 5b6a231e5a86
comparison
equal deleted inserted replaced
7586:90a92d5bca17 7588:f9eb431c3efe
57 #include "runtime/signature.hpp" 57 #include "runtime/signature.hpp"
58 #include "runtime/timer.hpp" 58 #include "runtime/timer.hpp"
59 #include "services/classLoadingService.hpp" 59 #include "services/classLoadingService.hpp"
60 #include "services/threadService.hpp" 60 #include "services/threadService.hpp"
61 #include "utilities/array.hpp" 61 #include "utilities/array.hpp"
62 #include "utilities/globalDefinitions.hpp"
62 63
63 // We generally try to create the oops directly when parsing, rather than 64 // We generally try to create the oops directly when parsing, rather than
64 // allocating temporary data structures and copying the bytes twice. A 65 // allocating temporary data structures and copying the bytes twice. A
65 // temporary area is only needed when parsing utf8 entries in the constant 66 // temporary area is only needed when parsing utf8 entries in the constant
66 // pool and when parsing line number tables. 67 // pool and when parsing line number tables.
2146 parse_checked_exceptions(&checked_exceptions_length, 2147 parse_checked_exceptions(&checked_exceptions_length,
2147 method_attribute_length, 2148 method_attribute_length,
2148 cp, CHECK_(nullHandle)); 2149 cp, CHECK_(nullHandle));
2149 } else if (method_attribute_name == vmSymbols::tag_method_parameters()) { 2150 } else if (method_attribute_name == vmSymbols::tag_method_parameters()) {
2150 method_parameters_length = cfs->get_u1_fast(); 2151 method_parameters_length = cfs->get_u1_fast();
2152 // Track the actual size (note: this is written for clarity; a
2153 // decent compiler will CSE and constant-fold this into a single
2154 // expression)
2155 u2 actual_size = 1;
2151 method_parameters_data = cfs->get_u1_buffer(); 2156 method_parameters_data = cfs->get_u1_buffer();
2157 actual_size += 2 * method_parameters_length;
2152 cfs->skip_u2_fast(method_parameters_length); 2158 cfs->skip_u2_fast(method_parameters_length);
2159 actual_size += 4 * method_parameters_length;
2153 cfs->skip_u4_fast(method_parameters_length); 2160 cfs->skip_u4_fast(method_parameters_length);
2161 // Enforce attribute length
2162 if (method_attribute_length != actual_size) {
2163 classfile_parse_error(
2164 "Invalid MethodParameters method attribute length %u in class file %s",
2165 method_attribute_length, CHECK_(nullHandle));
2166 }
2154 // ignore this attribute if it cannot be reflected 2167 // ignore this attribute if it cannot be reflected
2155 if (!SystemDictionary::Parameter_klass_loaded()) 2168 if (!SystemDictionary::Parameter_klass_loaded())
2156 method_parameters_length = 0; 2169 method_parameters_length = 0;
2157 } else if (method_attribute_name == vmSymbols::tag_synthetic()) { 2170 } else if (method_attribute_name == vmSymbols::tag_synthetic()) {
2158 if (method_attribute_length != 0) { 2171 if (method_attribute_length != 0) {
2295 MethodParametersElement* elem = m->constMethod()->method_parameters_start(); 2308 MethodParametersElement* elem = m->constMethod()->method_parameters_start();
2296 for(int i = 0; i < method_parameters_length; i++) { 2309 for(int i = 0; i < method_parameters_length; i++) {
2297 elem[i].name_cp_index = 2310 elem[i].name_cp_index =
2298 Bytes::get_Java_u2(method_parameters_data); 2311 Bytes::get_Java_u2(method_parameters_data);
2299 method_parameters_data += 2; 2312 method_parameters_data += 2;
2300 elem[i].flags = Bytes::get_Java_u4(method_parameters_data); 2313 u4 flags = Bytes::get_Java_u4(method_parameters_data);
2314 // This caused an alignment fault on Sparc, if flags was a u4
2315 elem[i].flags_lo = extract_low_short_from_int(flags);
2316 elem[i].flags_hi = extract_high_short_from_int(flags);
2301 method_parameters_data += 4; 2317 method_parameters_data += 4;
2302 } 2318 }
2303 } 2319 }
2304 2320
2305 // Copy checked exceptions 2321 // Copy checked exceptions