soot-oss / SootUp

A new version of Soot with a completely overhauled architecture
https://soot-oss.github.io/SootUp/
GNU Lesser General Public License v2.1
546 stars 66 forks source link

Fix self-referencing issue in `getMethodSignatureInSubClass` at `ICFGDotExporter` #920

Closed shenjunjiekoda closed 2 months ago

shenjunjiekoda commented 2 months ago

Problem

In the current implementation of getMethodSignatureInSubClass within ICFGDotExporter.java, there's a logical oversight where the method could potentially include the target method in its own set of sub-class method signatures. This leads to the incorrect behavior in connectEdgesToSubClasses, where a method might connect an edge from its starting statement back to itself, causing confusion in the call graph visualization.

Before applying the PR change: source in connectEdgesToSubClasses:

Set<MethodSignature> methodSignatureInSubClass =
        getMethodSignatureInSubClass(source, target, callgraph);

Here result methodSignatureInSubClass will contains target

sink in connectEdgesToSubClasses:

calls.put(
                  method.get().getBody().getStmtGraph().getStartingStmt().hashCode(),
                  subclassmethodSignature);

which will also overwrite previous entry set where call the connectEdgesToSubClasses in computeCalls

 if (stmt.containsInvokeExpr()) {
            MethodSignature target = stmt.getInvokeExpr().getMethodSignature();
            int hashCode = stmt.hashCode();
            calls.put(hashCode, target);
            // compute all the classes that are made to the subclasses as well
            connectEdgesToSubClasses(source, target, view, calls, callgraph);

Solution

This PR addresses the issue by adding an additional check in the filter operation within getMethodSignatureInSubClass. The updated logic ensures that the target method signature is explicitly excluded from the set of callable sub-class signatures.

Changes Made

Thank you for considering this fix to improve the accuracy of our tool.

codecov[bot] commented 2 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 70.04%. Comparing base (5af272d) to head (0ff4b1c). Report is 18 commits behind head on develop.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## develop #920 +/- ## ============================================= + Coverage 69.97% 70.04% +0.06% - Complexity 4061 4069 +8 ============================================= Files 312 312 Lines 15281 15303 +22 Branches 2611 2618 +7 ============================================= + Hits 10693 10719 +26 + Misses 3731 3727 -4 Partials 857 857 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.