Skip to content

Commit 0e40081

Browse files
thk123Matthias Güdemann
thk123
authored and
Matthias Güdemann
committed
Adding validation on the type of descriptor found
1 parent 6d44836 commit 0e40081

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

src/java_bytecode/java_bytecode_parser.cpp

+50-1
Original file line numberDiff line numberDiff line change
@@ -1678,6 +1678,21 @@ void java_bytecode_parsert::parse_local_variable_type_table(methodt &method)
16781678
}
16791679
}
16801680

1681+
/// Correspond to the different valid values for field reference_kind
1682+
/// From Java 8 spec 4.4.8
1683+
enum class method_handle_kindt
1684+
{
1685+
REF_getField = 1,
1686+
REF_getStatic = 2,
1687+
REF_putField = 3,
1688+
REF_putStatic = 4,
1689+
REF_invokeVirtual = 5,
1690+
REF_invokeStatic = 6,
1691+
REF_invokeSpecial = 7,
1692+
REF_newInvokeSpecial = 8,
1693+
REF_invokeInterface = 9
1694+
};
1695+
16811696
/// Read method handle pointed to from constant pool entry at index, return type
16821697
/// of method handle and name if lambda function is found.
16831698
/// \param entry: the constant pool entry of the methodhandle_info structure
@@ -1690,14 +1705,48 @@ java_bytecode_parsert::parse_method_handle(const pool_entryt &entry)
16901705
entry.tag == CONSTANT_MethodHandle,
16911706
"constant pool entry must be a MethodHandle");
16921707
lambda_method_handlet lambda_method_handle;
1693-
const auto &ref_entry = pool_entry(entry.ref2);
1708+
16941709
INVARIANT(
16951710
(entry.ref1 > 0 && entry.ref1 < 10),
16961711
"reference kind of Methodhandle must be in the range of 1 to 9");
16971712

1713+
const pool_entryt ref_entry = pool_entry(entry.ref2);
16981714
const auto &class_entry = pool_entry(ref_entry.ref1);
16991715
const auto &nameandtype_entry = pool_entry(ref_entry.ref2);
17001716

1717+
method_handle_kindt method_handle_kind = (method_handle_kindt)entry.ref1;
1718+
switch(method_handle_kind)
1719+
{
1720+
case method_handle_kindt::REF_getField:
1721+
case method_handle_kindt::REF_getStatic:
1722+
case method_handle_kindt::REF_putField:
1723+
case method_handle_kindt::REF_putStatic:
1724+
{
1725+
INVARIANT(ref_entry.tag == CONSTANT_Fieldref, "4.4.2");
1726+
break;
1727+
}
1728+
case method_handle_kindt::REF_invokeVirtual:
1729+
case method_handle_kindt::REF_newInvokeSpecial:
1730+
{
1731+
1732+
INVARIANT(ref_entry.tag == CONSTANT_Methodref, "4.4.2");
1733+
break;
1734+
}
1735+
case method_handle_kindt::REF_invokeStatic:
1736+
case method_handle_kindt::REF_invokeSpecial:
1737+
{
1738+
INVARIANT(
1739+
ref_entry.tag == CONSTANT_Methodref ||
1740+
ref_entry.tag == CONSTANT_InterfaceMethodref,
1741+
"4.4.2");
1742+
break;
1743+
}
1744+
case method_handle_kindt::REF_invokeInterface:
1745+
{
1746+
INVARIANT(ref_entry.tag == CONSTANT_InterfaceMethodref,"");
1747+
break;
1748+
}
1749+
}
17011750
const std::string method_name =
17021751
id2string(pool_entry(class_entry.ref1).s) + "." +
17031752
id2string(pool_entry(nameandtype_entry.ref1).s) +

0 commit comments

Comments
 (0)