This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-bcel.git
The following commit(s) were added to refs/heads/master by this push: new bf06bda [BCEL-338] org.apache.bcel.generic.InstructionFactory.createInvoke() populates its internal ConstantPoolGen on bad input, then throws exception. bf06bda is described below commit bf06bdaec1aa40d2069bc72337f0105f7fdc1498 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Mon Jun 1 18:25:22 2020 -0400 [BCEL-338] org.apache.bcel.generic.InstructionFactory.createInvoke() populates its internal ConstantPoolGen on bad input, then throws exception. --- src/changes/changes.xml | 1 + .../apache/bcel/generic/InstructionFactory.java | 32 +++++++++++++--------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index b32b36c..25ad8c4 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -78,6 +78,7 @@ The <action> type attribute can be add,update,fix,remove. <action type="update" dev="ggregory" due-to="Gary Gregory">Update tests from commons-io:commons-io 2.6 to 2.7.</action> <action type="update" dev="ggregory" due-to="Mark Roberts">Add support for invokestatic of an InterfaceMethodref #39.</action> <action type="update" dev="ggregory" due-to="Mark Roberts">Add attribute name(s) to Code.toString() #40.</action> + <action issue="BCEL-338" type="update" dev="ggregory" due-to="Gary Gregory">org.apache.bcel.generic.InstructionFactory.createInvoke() populates its internal ConstantPoolGen on bad input, then throws exception.</action> </release> <release version="6.4.1" date="2019-09-26" description="Bug fix release."> <action issue="BCEL-328" type="fix" dev="ggregory" due-to="Gary Gregory, Mark Roberts">java.util.EmptyStackException at org.apache.bcel.classfile.DescendingVisitor.visitModule (DescendingVisitor.java:592).</action> diff --git a/src/main/java/org/apache/bcel/generic/InstructionFactory.java b/src/main/java/org/apache/bcel/generic/InstructionFactory.java index 8610cd1..3d9d1d6 100644 --- a/src/main/java/org/apache/bcel/generic/InstructionFactory.java +++ b/src/main/java/org/apache/bcel/generic/InstructionFactory.java @@ -94,10 +94,15 @@ public class InstructionFactory implements InstructionConstants { * @param arg_types argument types of method * @param kind how to invoke: INVOKEINTERFACE, INVOKESTATIC, INVOKEVIRTUAL, or INVOKESPECIAL * @param use_interface force use of InterfaceMethodref + * @return A new InvokeInstruction. * @since 6.4.2 */ public InvokeInstruction createInvoke( final String class_name, final String name, final Type ret_type, - final Type[] arg_types, final short kind, final boolean use_interface ) { + final Type[] arg_types, final short kind, final boolean use_interface) { + if (kind != Const.INVOKESPECIAL && kind != Const.INVOKEVIRTUAL && kind != Const.INVOKESTATIC + && kind != Const.INVOKEINTERFACE && kind != Const.INVOKEDYNAMIC) { + throw new RuntimeException("Oops: Unknown invoke kind: " + kind); + } int index; int nargs = 0; final String signature = Type.getMethodSignature(ret_type, arg_types); @@ -110,18 +115,19 @@ public class InstructionFactory implements InstructionConstants { index = cp.addMethodref(class_name, name, signature); } switch (kind) { - case Const.INVOKESPECIAL: - return new INVOKESPECIAL(index); - case Const.INVOKEVIRTUAL: - return new INVOKEVIRTUAL(index); - case Const.INVOKESTATIC: - return new INVOKESTATIC(index); - case Const.INVOKEINTERFACE: - return new INVOKEINTERFACE(index, nargs + 1); - case Const.INVOKEDYNAMIC: - return new INVOKEDYNAMIC(index); - default: - throw new RuntimeException("Oops: Unknown invoke kind: " + kind); + case Const.INVOKESPECIAL: + return new INVOKESPECIAL(index); + case Const.INVOKEVIRTUAL: + return new INVOKEVIRTUAL(index); + case Const.INVOKESTATIC: + return new INVOKESTATIC(index); + case Const.INVOKEINTERFACE: + return new INVOKEINTERFACE(index, nargs + 1); + case Const.INVOKEDYNAMIC: + return new INVOKEDYNAMIC(index); + default: + // Can't happen + throw new IllegalStateException("Unknown invoke kind: " + kind); } }