Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix infinite loop for unary operator opcodes #131

Merged
merged 1 commit into from
Jul 11, 2023

Conversation

puff
Copy link
Sponsor Contributor

@puff puff commented Jul 11, 2023

UnaryOperatorHandlerBase does not increase the ProgramCounter so it will never progress past the current instruction.

var module = ModuleDefinition.FromModule(typeof(UnaryOperatorTestClass).Module);
var method = module.GetAllTypes().FirstOrDefault(x => x.Name == "UnaryOperatorTestClass")?.Methods.FirstOrDefault(x => x.Name == "UnaryOperatorTest");

var vm = new CilVirtualMachine(module, false);
vm.Call(method!, Array.Empty<BitVector>());
public static class UnaryOperatorTestClass
{
    public static bool UnaryOperatorTest()
    {
        var one = 1;
        var negated = -one;
        return negated == -1;
    }
}

Executing this will continuously execute the negate instruction and never progress past it.
To fix this, I just switched UnaryOperatorHandlerBase to implement FallThroughOpCodeHandler

@Washi1337 Washi1337 merged commit 4d324ef into Washi1337:master Jul 11, 2023
1 check passed
@Washi1337
Copy link
Owner

Good catch. Thanks!

@puff puff deleted the fix/unaryoperatorhandlerbase branch July 11, 2023 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants