Skip to content

Commit

Permalink
Copy INVOKEDYNAMIC args array to avoid leaking handle remaps, fixes S…
Browse files Browse the repository at this point in the history
  • Loading branch information
Mumfrey committed Dec 13, 2019
1 parent 8b9621a commit 27ea2a9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.Handle;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldNode;
import org.objectweb.asm.tree.InnerClassNode;
import org.objectweb.asm.tree.InvokeDynamicInsnNode;
import org.objectweb.asm.tree.MethodNode;
import org.spongepowered.asm.mixin.Implements;
import org.spongepowered.asm.mixin.Mixin;
Expand Down Expand Up @@ -90,6 +92,17 @@ class MixinMethodNode extends MethodNodeEx {
public MixinMethodNode(int access, String name, String desc, String signature, String[] exceptions) {
super(access, name, desc, signature, exceptions, MixinInfo.this);
}

@Override
public void visitInvokeDynamicInsn(String name, String descriptor, Handle bootstrapMethodHandle, Object... bootstrapMethodArguments) {
// Create a shallow copy of the bootstrap method args because the
// base implementation just passes the array by reference. This
// causes any changes applied to the cloned classnode to leak into
// the "master" ClassNode!
Object[] bsmArgs = new Object[bootstrapMethodArguments.length];
System.arraycopy(bootstrapMethodArguments, 0, bsmArgs, 0, bootstrapMethodArguments.length);
this.instructions.add(new InvokeDynamicInsnNode(name, descriptor, bootstrapMethodHandle, bsmArgs));
}

public boolean isInjector() {
return (this.getInjectorAnnotation() != null || this.isSurrogate());
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/org/spongepowered/asm/util/Bytecode.java
Original file line number Diff line number Diff line change
Expand Up @@ -429,10 +429,14 @@ public static String describeNode(AbstractInsnNode node) {
out += String.format("[%s] %d", Bytecode.getOpcodeName(node), ((VarInsnNode)node).var);
} else if (node instanceof MethodInsnNode) {
MethodInsnNode mth = (MethodInsnNode)node;
out += String.format("[%s] %s %s %s", Bytecode.getOpcodeName(node), mth.owner, mth.name, mth.desc);
out += String.format("[%s] %s::%s%s", Bytecode.getOpcodeName(node), mth.owner, mth.name, mth.desc);
} else if (node instanceof FieldInsnNode) {
FieldInsnNode fld = (FieldInsnNode)node;
out += String.format("[%s] %s %s %s", Bytecode.getOpcodeName(node), fld.owner, fld.name, fld.desc);
out += String.format("[%s] %s::%s:%s", Bytecode.getOpcodeName(node), fld.owner, fld.name, fld.desc);
} else if (node instanceof InvokeDynamicInsnNode) {
InvokeDynamicInsnNode idc = (InvokeDynamicInsnNode)node;
out += String.format("[%s] %s%s { %s %s::%s%s }", Bytecode.getOpcodeName(node), idc.name, idc.desc,
Bytecode.getOpcodeName(idc.bsm.getTag(), "H_GETFIELD", 1), idc.bsm.getOwner(), idc.bsm.getName(), idc.bsm.getDesc());
} else if (node instanceof LineNumberNode) {
LineNumberNode ln = (LineNumberNode)node;
out += String.format("LINE=[%d] LABEL=[%s]", ln.line, ln.start.getLabel());
Expand Down

0 comments on commit 27ea2a9

Please sign in to comment.