Skip to content

Commit 7f35e67

Browse files
committed
Fix iterator summary and add new test case
1 parent 733a609 commit 7f35e67

3 files changed

Lines changed: 49 additions & 2 deletions

File tree

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

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
package soot.jimple.infoflow.integration.test.junit;
22

33
import org.junit.Assert;
4+
import org.junit.Assume;
45
import org.junit.Test;
56
import org.xmlpull.v1.XmlPullParserException;
7+
import soot.SootMethod;
68
import soot.jimple.infoflow.InfoflowConfiguration;
79
import soot.jimple.infoflow.android.SetupApplication;
10+
import soot.jimple.infoflow.android.data.parsers.PermissionMethodParser;
811
import soot.jimple.infoflow.methodSummary.data.provider.EagerSummaryProvider;
912
import soot.jimple.infoflow.methodSummary.taintWrappers.SummaryTaintWrapper;
1013
import soot.jimple.infoflow.methodSummary.taintWrappers.TaintWrapperFactory;
14+
import soot.jimple.infoflow.results.DataFlowResult;
1115
import soot.jimple.infoflow.results.InfoflowResults;
1216
import soot.jimple.infoflow.taintWrappers.ITaintPropagationWrapper;
17+
import soot.jimple.infoflow.util.DebugFlowFunctionTaintPropagationHandler;
1318

19+
import javax.swing.text.html.parser.Parser;
1420
import javax.xml.stream.XMLStreamException;
21+
import java.io.BufferedReader;
22+
import java.io.ByteArrayInputStream;
1523
import java.io.IOException;
1624
import java.net.URISyntaxException;
17-
import java.util.Collections;
25+
import java.util.*;
1826

1927
/**
2028
* Tests that uncovered a bug.
@@ -43,4 +51,41 @@ public void testFlowSensitivityWithOverwrite() throws XmlPullParserException, IO
4351
Assert.assertEquals(2, results.size());
4452
Assert.assertEquals(2, results.getResultSet().size());
4553
}
54+
55+
/**
56+
* Tests an app that uses the kotlin collections.
57+
* Expects four leaks:
58+
* * From getDeviceId() in onCreate() to Log.d(String, String)
59+
* in listFlow(String), mapFlow(String) and setFlow(String).
60+
* * From new File in fileFlow() to Log.d(String, String) in fileFlow(String).
61+
*/
62+
@Test
63+
public void testKotlinAppWithCollections() throws IOException {
64+
65+
SetupApplication app = initApplication("testAPKs/KotlinCollectionApp.apk");
66+
67+
// Make sure we find only one flow per method
68+
app.addResultsAvailableHandler((cfg, results) -> {
69+
Set<SootMethod> seenSet = new HashSet<>();
70+
for (DataFlowResult res : results.getResultSet()) {
71+
SootMethod sm = cfg.getMethodOf(res.getSink().getStmt());
72+
Assert.assertFalse(seenSet.contains(sm));
73+
seenSet.add(sm);
74+
}
75+
});
76+
77+
// Add the sources and sinks
78+
List<String> ssinks = new ArrayList<>();
79+
ssinks.add("<android.telephony.TelephonyManager: java.lang.String getDeviceId()> android.permission.READ_PHONE_STATE -> _SOURCE_");
80+
ssinks.add("<android.util.Log: int d(java.lang.String,java.lang.String)> -> _SINK_");
81+
ssinks.add("<kotlin.io.TextStreamsKt: java.util.List readLines(java.io.Reader)> -> _SOURCE_");
82+
83+
// TODO: Triggers an NPE in the backward direction in Soot
84+
// because the hierarchy for a phantom class is not initialized.
85+
Assume.assumeTrue(app.getConfig().getDataFlowDirection() == InfoflowConfiguration.DataFlowDirection.Forwards);
86+
87+
InfoflowResults results = app.runInfoflow(PermissionMethodParser.fromStringList(ssinks));
88+
Assert.assertEquals(4, results.size());
89+
Assert.assertEquals(4, results.getResultSet().size());
90+
}
4691
}
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)