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

In the case of two nested IF statements, the IfStmt returns the wrong lineNumber #2017

Open
chumobyte opened this issue Nov 7, 2023 · 0 comments

Comments

@chumobyte
Copy link

chumobyte commented Nov 7, 2023

Describe the bug
In the case of nested IF expressions, the outer second IF expression fetches the wrong lineNumber, mistakenly taking the lineNumber of the first IF.

Input file
sootbug.zip

  • The main code in sootbug.zip
    public static void main(String[] args) {
        Options.v().set_src_prec(Options.src_prec_class);
        Options.v().set_keep_line_number(true);

        String classpath = System.getProperty("java.class.path");

        Options.v().set_soot_classpath(classpath);

        String classPath = "org.example.IfClass";
        Scene.v().loadClassAndSupport(classPath);
        Scene.v().loadNecessaryClasses();

        SootClass sc = Scene.v().getSootClass("org.example.IfClass");
        SootMethod sm = sc.getMethodByName("print");
        Body b = sm.retrieveActiveBody();

        for (Unit u : b.getUnits()) {
            if (u instanceof IfStmt) {
                IfStmt is = (IfStmt) u;
                System.out.println("line:[" + is.getTags().get(0) + "]      " + is.toString());
            }
        }
    }
  • IfClass
    public void print(int score, String name) {
        if (score >= 90) {
            String aaa = "";
            if (!name.equals("admin")) {
                aaa = name;
            } else {
                aaa = "mute";
            }
            System.out.println(aaa + ":A");
        } else if (score >= 80) {
            System.out.println("B");
        } else if (score >= 70) {
            System.out.println("C");
        }
    }

To reproduce
Steps to reproduce the behavior:

  1. Attached is a complete Java Maven project demonstrating the bug (it can only run in a Java 8 environment). Open it using IntelliJ IDEA and run it directly to demonstrate the issue I want to convey.
  2. After running the project, the following information will be printed:
line:[9]      if i0 < 90 goto (branch)
line:[11]      if $z0 != 0 goto r9 = "mute"
line:[9]      if i0 < 80 goto (branch)
line:[19]      if i0 < 70 goto return

Expected behavior
I expect the expression if (score >= 80) to correctly display lineNumber 17.

Stacktrace

Additional context
Thank you very much

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

No branches or pull requests

1 participant