Avoid cross-contaminating injector-added locals by when capturing locals

Fixes #493

Adds a preinject pass to local-capturing injectors so they see only
valid locals. Also decorate mixin-added locals to safeguard against
accidental leakage.
This commit is contained in:
Mumfrey committed 2021-06-05 15:55:17 +01:00
1 parent 6994e81622
commit 99a51998c0
8 files changed
+223 -34

No files matched your search

@@ -57,6 +57,17 @@ import org.spongepowered.asm.util.throwables.LVTGeneratorError;
*/
public final class Locals {
/**
* A local variable entry added by mixin itself, eg. by an injector
*/
public static class SyntheticLocalVariableNode extends LocalVariableNode {
public SyntheticLocalVariableNode(String name, String descriptor, String signature, LabelNode start, LabelNode end, int index) {
super(name, descriptor, signature, start, end, index);
}
}
/**
* Frame type names just for the purposes of debug printing
*/
@@ -287,9 +298,9 @@ public final class Locals {
}
}
// Null out any "unknown" locals
// Null out any "unknown" or mixin-provided locals
for (int l = 0; l < frame.length; l++) {
if (frame[l] != null && frame[l].desc == null) {
if (frame[l] != null && frame[l].desc == null || frame[l] instanceof SyntheticLocalVariableNode) {
frame[l] = null;
}
}