Skip to content

[Bug]: Obtained Jimple code using ASMMethodSource may contain invalid exception handling code #1536

@MarcMil

Description

@MarcMil

What happened?

A slightly modified version of the Soot1577Test test case prints the Jimple body of a problematic method:


  public static void test() {
    AnalysisInputLocation inputLocation =
        new ClassFileBasedAnalysisInputLocation(
            Paths.get("src/test/resources/soot-1577/g.class"),
            "cn.com.chinatelecom.account.api.c",
            SourceType.Application);

    JavaView view = new JavaView(inputLocation);
    
    MethodSignature sig = JavaIdentifierFactory.getInstance().getMethodSignature("cn.com.chinatelecom.account.api.c.g", "h", "int", Arrays.asList("android.content.Context"));
    @NonNull Body body = view.getMethod(sig).get().getBody();
    System.out.println(body);

    assertEquals(1, view.getClasses().count());
    view.getClasses().findFirst().get().getMethods().forEach(SootMethod::getBody);
  }

Prints the method body that contains invalid code:


  label19:
    $stack4 := @caughtexception;

    goto label21;
...
label21:
    $stack14#1 := @caughtexception;
    virtualinvoke $stack14#1.<java.lang.NullPointerException: void printStackTrace()>();

…

 catch java.lang.NullPointerException from label07 to label08 with label19;

In this code, the caught exception reference is used twice, since label21 can be reached via label19. Note that label19 is a valid exceptional handler. label21 was never registered as an exceptional handler.

I think that the merge might work properly; the printStackTrace statement can be reached from two different event handlers and prints the corresponding exception's stack trace.

Here is the method's javap output.
javap.txt

The full jimple body of the corresponding method:
Jimple body of SootUp

Legacy Soot does not exhibit the same problem:
Jimple body of Legacy Soot

Version

Latest develop branch

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions