Skip to content

Commit 633292c

Browse files
committed
fixed summary access when no direct match is available
1 parent 273fbba commit 633292c

File tree

7 files changed

+329
-15
lines changed

7 files changed

+329
-15
lines changed

soot-infoflow-summaries/src/soot/jimple/infoflow/methodSummary/taintWrappers/SummaryTaintWrapper.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,12 @@ public SummaryResponse load(SummaryQuery query) throws Exception {
111111
if (declaredClass != null && !isClassSupported)
112112
isClassSupported = getSummariesHierarchy(methodSig, classSummaries, declaredClass);
113113

114-
if (!classSummaries.isEmpty())
114+
if (isClassSupported) {
115+
if (classSummaries.isEmpty())
116+
return SummaryResponse.EMPTY_BUT_SUPPORTED;
115117
return new SummaryResponse(classSummaries, isClassSupported);
116-
else
117-
return isClassSupported ? SummaryResponse.EMPTY_BUT_SUPPORTED : SummaryResponse.NOT_SUPPORTED;
118+
} else
119+
return SummaryResponse.NOT_SUPPORTED;
118120
}
119121

120122
/**
@@ -184,7 +186,7 @@ private boolean getSummaries(final String methodSig, final ClassSummaries summar
184186
private boolean getSummariesHierarchy(final String methodSig, final ClassSummaries summaries,
185187
SootClass clazz) {
186188
// Don't try to look up the whole Java hierarchy
187-
if (clazz == Scene.v().getSootClassUnsafe("java.lang.Object"))
189+
if (clazz != null && clazz.getName().equals("java.lang.Object"))
188190
return false;
189191

190192
// If the target is abstract and we haven't found any flows,
@@ -193,21 +195,23 @@ private boolean getSummariesHierarchy(final String methodSig, final ClassSummari
193195
// flows for all possible classes.
194196
SootMethod targetMethod = clazz.getMethodUnsafe(methodSig);
195197
if (!clazz.isConcrete() || targetMethod == null || !targetMethod.isConcrete()) {
198+
int found = 0;
196199
Set<SootClass> childClasses = getAllChildClasses(clazz);
197-
if (childClasses.size() > MAX_HIERARCHY_DEPTH)
198-
return false;
199-
200-
boolean found = false;
201200
for (SootClass childClass : childClasses) {
202201
// Do we have support for the target class?
203202
if (summaries.merge(flows.getMethodFlows(childClass, methodSig)))
204-
found = true;
203+
found++;
205204

206205
// Do we support any interface this class might have?
207206
if (checkInterfaces(methodSig, summaries, childClass))
208-
found = true;
207+
found++;
208+
209+
// If we have too many summaries that could be applicable, we abort here to
210+
// avoid false positives
211+
if (found > MAX_HIERARCHY_DEPTH)
212+
return false;
209213
}
210-
return found;
214+
return found > 0;
211215
}
212216
return false;
213217

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
<?xml version="1.0" ?>
22
<summary fileFormatVersion="101">
3-
<hierarchy>
3+
<hierarchy superClass="java.util.Vector">
44
<interface name="java.util.List" />
5+
<interface name="java.util.Collection" />
6+
<interface name="java.util.RandomAccess" />
7+
<interface name="java.lang.Iterable" />
8+
<interface name="java.lang.Cloneable" />
9+
<interface name="java.io.Serializable" />
510
</hierarchy>
611
<methods>
712
<method id="void addElement(java.lang.Object)">

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
<?xml version="1.0" ?>
22
<summary fileFormatVersion="101">
3+
<hierarchy superClass="java.util.AbstractList">
4+
<interface name="java.util.List" />
5+
<interface name="java.util.Collection" />
6+
<interface name="java.util.RandomAccess" />
7+
<interface name="java.lang.Iterable" />
8+
<interface name="java.lang.Cloneable" />
9+
<interface name="java.io.Serializable" />
10+
</hierarchy>
311
<methods>
412
<method id="void &lt;init&gt;(java.util.Collection)">
513
<flows>
Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,33 @@
1-
<?xml version="1.0" ?><summary fileFormatVersion="101"><methods><method id="void remove()"><flows><flow isAlias="false"><from sourceSinkType="Field" BaseType="java.util.ArrayList$Itr" AccessPath="[&lt;java.util.ArrayList$Itr: int lastRet&gt;]" AccessPathTypes="[int]"></from><to sourceSinkType="Field" BaseType="java.util.ArrayList$Itr" AccessPath="[&lt;java.util.ArrayList$Itr: int cursor&gt;]" AccessPathTypes="[int]" taintSubFields="true"></to></flow><flow isAlias="false"><from sourceSinkType="Field" BaseType="java.util.ArrayList$Itr" AccessPath="[&lt;java.util.ArrayList$Itr: java.util.ArrayList this$0&gt;, &lt;java.util.AbstractList: int modCount&gt;]" AccessPathTypes="[java.util.ArrayList, int]"></from><to sourceSinkType="Field" BaseType="java.util.ArrayList$Itr" AccessPath="[&lt;java.util.ArrayList$Itr: int expectedModCount&gt;]" AccessPathTypes="[int]" taintSubFields="true"></to></flow></flows></method><method id="java.lang.Object next()"><flows><flow isAlias="true"><from sourceSinkType="Field" BaseType="java.util.ArrayList$Itr" AccessPath="[&lt;java.util.ArrayList$Itr: java.util.ArrayList this$0&gt;, &lt;java.util.ArrayList: java.lang.Object[] elementData&gt;]" AccessPathTypes="[java.util.ArrayList, java.lang.Object[]]"></from><to sourceSinkType="Return" BaseType="java.lang.Object" taintSubFields="true"></to></flow><flow isAlias="false"><from sourceSinkType="Field" BaseType="java.util.ArrayList$Itr" AccessPath="[&lt;java.util.ArrayList$Itr: int cursor&gt;]" AccessPathTypes="[int]"></from><to sourceSinkType="Field" BaseType="java.util.ArrayList$Itr" AccessPath="[&lt;java.util.ArrayList$Itr: int lastRet&gt;]" AccessPathTypes="[int]" taintSubFields="true"></to></flow></flows></method></methods><gaps></gaps></summary>
1+
<?xml version="1.0"?>
2+
<summary fileFormatVersion="101">
3+
<hierarchy superClass="java.lang.Object">
4+
<interface name="java.util.Iterator" />
5+
</hierarchy>
6+
<methods>
7+
<method id="void remove()">
8+
<flows>
9+
<flow isAlias="false">
10+
<from sourceSinkType="Field" BaseType="java.util.ArrayList$Itr" AccessPath="[&lt;java.util.ArrayList$Itr: int lastRet&gt;]" AccessPathTypes="[int]"></from>
11+
<to sourceSinkType="Field" BaseType="java.util.ArrayList$Itr" AccessPath="[&lt;java.util.ArrayList$Itr: int cursor&gt;]" AccessPathTypes="[int]" taintSubFields="true"></to>
12+
</flow>
13+
<flow isAlias="false">
14+
<from sourceSinkType="Field" BaseType="java.util.ArrayList$Itr" AccessPath="[&lt;java.util.ArrayList$Itr: java.util.ArrayList this$0&gt;, &lt;java.util.AbstractList: int modCount&gt;]" AccessPathTypes="[java.util.ArrayList, int]"></from>
15+
<to sourceSinkType="Field" BaseType="java.util.ArrayList$Itr" AccessPath="[&lt;java.util.ArrayList$Itr: int expectedModCount&gt;]" AccessPathTypes="[int]" taintSubFields="true"></to>
16+
</flow>
17+
</flows>
18+
</method>
19+
<method id="java.lang.Object next()">
20+
<flows>
21+
<flow isAlias="true">
22+
<from sourceSinkType="Field" BaseType="java.util.ArrayList$Itr" AccessPath="[&lt;java.util.ArrayList$Itr: java.util.ArrayList this$0&gt;, &lt;java.util.ArrayList: java.lang.Object[] elementData&gt;]" AccessPathTypes="[java.util.ArrayList, java.lang.Object[]]"></from>
23+
<to sourceSinkType="Return" BaseType="java.lang.Object" taintSubFields="true"></to>
24+
</flow>
25+
<flow isAlias="false">
26+
<from sourceSinkType="Field" BaseType="java.util.ArrayList$Itr" AccessPath="[&lt;java.util.ArrayList$Itr: int cursor&gt;]" AccessPathTypes="[int]"></from>
27+
<to sourceSinkType="Field" BaseType="java.util.ArrayList$Itr" AccessPath="[&lt;java.util.ArrayList$Itr: int lastRet&gt;]" AccessPathTypes="[int]" taintSubFields="true"></to>
28+
</flow>
29+
</flows>
30+
</method>
31+
</methods>
32+
<gaps></gaps>
33+
</summary>

0 commit comments

Comments
 (0)