wala / WALA

T.J. Watson Libraries for Analysis, with frontends for Java, Android, and JavaScript, and may common static program analyses
http://github.com/wala/WALA
Eclipse Public License 2.0
758 stars 221 forks source link

A Wala crash bug when I set entry point #1389

Open tisble opened 6 months ago

tisble commented 6 months ago

When I tried to add an entrypoint to the call graph, Wala failed and threw a runtime exception. The input file is available via a maven link, which is a top popular library in maven.

Setup

AnalysisScope scope = AnalysisScopeReader.instance.makeJavaBinaryAnalysisScope("Path/to/package", exclusionFile);
scope.addToScope("JDK SCOPE");
IClassHierarchy hierarchy = ClassHierarchyFactory.makeWithRoot(scope);
String targetSig="androidx.appcompat.view.SupportMenuInflater$MenuState.readItem(Landroid/util/AttributeSet;)V"
Collection<Entrypoint> result=new ArrayList<>();
for (Iterator<IClass> it = hierarchy.iterator(); it.hasNext(); ) {
    IClass klass = it.next();
    if(targetSig.contains(klass.getName().toString()){
        for (IMethod method : klass.getDeclaredMethods()) {
            if (method.getSignature().contains(targetSig)) {
                result.add(new DefaultEntrypoint(method, hierarchy)); // crashed here
            }
        }
    }
}
// ......

After an initial investigation, it seems that Wala mistook that there are 2 parameters in the Callsite. Wala assigned j with -1 and addCall method returned null to entrypointCallSites. image

Then Wala crashed with the following exception log: Stacktrace When I set the entry point with new DefaultEntrypoint(method, hierarchy) or new ArgumentTypeEntrypoint(method, hierarchy), the stacktrace is here:

java.lang.IllegalStateException: Could not create entrypoint callsites: 1. [SEVERE] class com.ibm.wala.classLoader.BytecodeClass$ClassNotFoundWarning : Landroid/content/DialogInterface
2. [SEVERE] class com.ibm.wala.classLoader.BytecodeClass$ClassNotFoundWarning : Landroid/content/DialogInterface$OnClickListener
3. [SEVERE] class com.ibm.wala.classLoader.BytecodeClass$ClassNotFoundWarning : Landroid/content/DialogInterface$OnDismissListener
4. [SEVERE] class com.ibm.wala.classLoader.BytecodeClass$ClassNotFoundWarning : Landroid/content/DialogInterface$OnKeyListener
......        
at com.ibm.wala.ipa.callgraph.propagation.PropagationCallGraphBuilder.makeCallGraph(PropagationCallGraphBuilder.java:238)
        ...
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
msridhar commented 4 months ago

@tisble is there any way you could put together a standalone github repo that reproduces this crash? That would help me debug it. Thanks!