Skip to content

Commit a75d6d1

Browse files
committed
Merge branch 'kotlinFix' into injectTypeHierarchy
2 parents 1cce25e + 7f35e67 commit a75d6d1

3 files changed

Lines changed: 39 additions & 4 deletions

File tree

soot-infoflow-integration/test/soot/jimple/infoflow/integration/test/junit/AndroidRegressionTests.java

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@
33
import org.junit.Assert;
44
import org.junit.Test;
55
import org.xmlpull.v1.XmlPullParserException;
6+
import soot.SootMethod;
67
import soot.jimple.infoflow.InfoflowConfiguration;
78
import soot.jimple.infoflow.android.SetupApplication;
9+
import soot.jimple.infoflow.android.data.parsers.PermissionMethodParser;
810
import soot.jimple.infoflow.methodSummary.taintWrappers.TaintWrapperFactory;
11+
import soot.jimple.infoflow.results.DataFlowResult;
912
import soot.jimple.infoflow.results.InfoflowResults;
1013
import soot.jimple.infoflow.taintWrappers.ITaintPropagationWrapper;
11-
import soot.jimple.infoflow.util.DebugFlowFunctionTaintPropagationHandler;
1214

1315
import javax.xml.stream.XMLStreamException;
1416
import java.io.IOException;
1517
import java.util.Collections;
18+
import java.util.*;
1619

1720
/**
1821
* Tests that uncovered a bug.
@@ -42,17 +45,47 @@ public void testFlowSensitivityWithOverwrite() throws XmlPullParserException, IO
4245
Assert.assertEquals(2, results.getResultSet().size());
4346
}
4447

45-
4648
/**
4749
* Tests that StubDroid correctly narrows the type when the summary is in a superclass.
4850
* See also the comment in SummaryTaintWrapper#getSummaryDeclaringClass().
4951
*/
5052
@Test
5153
public void testTypeHierarchyFromSummary() throws XmlPullParserException, IOException {
5254
SetupApplication app = initApplication("testAPKs/TypeHierarchyTest.apk");
53-
app.setTaintPropagationHandler(new DebugFlowFunctionTaintPropagationHandler());
5455
InfoflowResults results = app.runInfoflow("../soot-infoflow-android/SourcesAndSinks.txt");
5556
Assert.assertEquals(1, results.size());
5657
Assert.assertEquals(1, results.getResultSet().size());
5758
}
59+
60+
/**
61+
* Tests an app that uses the kotlin collections.
62+
* Expects four leaks:
63+
* * From getDeviceId() in onCreate() to Log.d(String, String)
64+
* in listFlow(String), mapFlow(String) and setFlow(String).
65+
* * From new File in fileFlow() to Log.d(String, String) in fileFlow(String).
66+
*/
67+
@Test
68+
public void testKotlinAppWithCollections() throws IOException {
69+
SetupApplication app = initApplication("testAPKs/KotlinCollectionApp.apk");
70+
71+
// Make sure we find only one flow per method
72+
app.addResultsAvailableHandler((cfg, results) -> {
73+
Set<SootMethod> seenSet = new HashSet<>();
74+
for (DataFlowResult res : results.getResultSet()) {
75+
SootMethod sm = cfg.getMethodOf(res.getSink().getStmt());
76+
Assert.assertFalse(seenSet.contains(sm));
77+
seenSet.add(sm);
78+
}
79+
});
80+
81+
// Add the sources and sinks
82+
List<String> ssinks = new ArrayList<>();
83+
ssinks.add("<android.telephony.TelephonyManager: java.lang.String getDeviceId()> android.permission.READ_PHONE_STATE -> _SOURCE_");
84+
ssinks.add("<android.util.Log: int d(java.lang.String,java.lang.String)> -> _SINK_");
85+
ssinks.add("<kotlin.io.TextStreamsKt: java.util.List readLines(java.io.Reader)> -> _SOURCE_");
86+
87+
InfoflowResults results = app.runInfoflow(PermissionMethodParser.fromStringList(ssinks));
88+
Assert.assertEquals(4, results.size());
89+
Assert.assertEquals(4, results.getResultSet().size());
90+
}
5891
}
5.27 MB
Binary file not shown.

soot-infoflow-summaries/summariesManual/java.util.Collection.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
<method id="java.util.Iterator iterator()">
3333
<flows>
3434
<flow isAlias="false" typeChecking="false">
35-
<from sourceSinkType="Field" />
35+
<from sourceSinkType="Field"
36+
AccessPath="[java.util.Collection: java.lang.Object[] innerArray]"
37+
AccessPathTypes="[java.lang.Object[]]" />
3638
<to sourceSinkType="Return"
3739
AccessPath="[java.util.Iterator: java.lang.Object innerCollection]"
3840
AccessPathTypes="[java.lang.Object]" />

0 commit comments

Comments
 (0)