Skip to content

Commit

Permalink
Merge pull request #910 from soot-oss/fix/redundantTrapHandlerCheck
Browse files Browse the repository at this point in the history
Add check for redundant trap handlers
  • Loading branch information
stschott authored Apr 9, 2024
2 parents 111fbc9 + 2f4d9b7 commit ede4319
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,8 @@ public SootMethod visitMethod(@Nonnull JimpleParser.MethodContext ctx) {
ClassType exceptionType = util.getClassType(it.exceptiontype.getText());
String beginLabel = it.from.getText();
String toLabel = it.to.getText();
if (beginLabel.equals(toLabel)) continue;

String handlerLabel = it.with.getText();
traps.add(
Jimple.newTrap(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class RedundantTrapHandler extends java.lang.Object
{

void method()
{
unknown $stack1, l1, l2;

l1 = 0;

label1:
$stack1 = l1;

label2:
l2 := @caughtexception;

return;

catch java.lang.Exception from label1 to label1 with label2;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.IOException;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CharStreams;
Expand All @@ -15,6 +16,7 @@
import sootup.core.frontend.ResolveException;
import sootup.core.inputlocation.EagerInputLocation;
import sootup.core.jimple.Jimple;
import sootup.core.jimple.basic.Trap;
import sootup.core.model.*;
import sootup.core.signatures.MethodSubSignature;
import sootup.core.types.PrimitiveType;
Expand Down Expand Up @@ -814,4 +816,15 @@ public void testLegacyTransientMethodModifier() throws IOException {
MethodModifier modifier = modifiers.iterator().next();
assertEquals(MethodModifier.VARARGS, modifier);
}

@Test
public void testRedundantTrapHandler() throws IOException {
SootClass clazz =
parseJimpleClass(
CharStreams.fromFileName("src/test/java/resources/jimple/RedundantTrapHandler.jimple"));
Set<? extends SootMethod> methods = clazz.getMethods();
SootMethod method = methods.iterator().next();
List<Trap> traps = method.getBody().getTraps();
assertEquals(0, traps.size());
}
}

0 comments on commit ede4319

Please sign in to comment.