Skip to content

Commit b04693a

Browse files
authored
Merge pull request #854 from MarcMil/extensible
TaintPropagationHandler: Do not use intermediate sets
2 parents 228b753 + 5e1f948 commit b04693a

File tree

11 files changed

+63
-58
lines changed

11 files changed

+63
-58
lines changed

soot-infoflow-summaries/src/soot/jimple/infoflow/methodSummary/handler/SummaryTaintPropagationHandler.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package soot.jimple.infoflow.methodSummary.handler;
22

3-
import java.util.Collections;
43
import java.util.HashSet;
54
import java.util.Iterator;
65
import java.util.Set;
@@ -201,16 +200,18 @@ protected void addResult(Abstraction abs, Stmt stmt) {
201200
}
202201

203202
@Override
204-
public Set<Abstraction> notifyFlowOut(Unit u, Abstraction d1, Abstraction incoming, Set<Abstraction> outgoing,
203+
public boolean notifyFlowOut(Unit u, Abstraction d1, Abstraction incoming, Set<Abstraction> outgoing,
205204
InfoflowManager manager, FlowFunctionType type) {
206205
// Do not propagate through excluded methods
207206
SootMethod sm = manager.getICFG().getMethodOf(u);
208-
if (excludedMethods.contains(sm))
209-
return Collections.emptySet();
210-
if (type == FlowFunctionType.ReturnFlowFunction && !followReturnsPastSeeds && sm == method)
211-
return Collections.emptySet();
212-
213-
return outgoing;
207+
if (excludedMethods.contains(sm)) {
208+
return true;
209+
}
210+
if (type == FlowFunctionType.ReturnFlowFunction && !followReturnsPastSeeds && sm == method) {
211+
outgoing.clear();
212+
return true;
213+
}
214+
return false;
214215
}
215216

216217
public MultiMap<Abstraction, Stmt> getResult() {

soot-infoflow/src/soot/jimple/infoflow/collections/strategies/widening/WideningTaintPropagationHandler.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package soot.jimple.infoflow.collections.strategies.widening;
22

3-
import java.util.HashSet;
3+
import java.util.ArrayList;
4+
import java.util.Iterator;
5+
import java.util.List;
46
import java.util.Set;
57
import java.util.function.Function;
68

@@ -37,22 +39,23 @@ public void notifyFlowIn(Unit stmt, Abstraction taint, InfoflowManager manager,
3739
}
3840

3941
@Override
40-
public Set<Abstraction> notifyFlowOut(Unit stmt, Abstraction d1, Abstraction incoming, Set<Abstraction> outgoing,
42+
public boolean notifyFlowOut(Unit stmt, Abstraction d1, Abstraction incoming, Set<Abstraction> outgoing,
4143
InfoflowManager manager, FlowFunctionType type) {
4244
if (type != FlowFunctionType.CallToReturnFlowFunction)
43-
return outgoing;
45+
return false;
4446

45-
Set<Abstraction> newOutgoing = outgoing;
4647
WideningStrategy<Unit, Abstraction> wideningStrategy = getWideningStrategy(manager);
47-
for (Abstraction abs : outgoing) {
48+
List<Abstraction> toAdd = new ArrayList<>();
49+
Iterator<Abstraction> it = outgoing.iterator();
50+
while (it.hasNext()) {
51+
Abstraction abs = it.next();
4852
Abstraction widened = wideningStrategy.widen(incoming, abs, stmt);
4953
if (widened != abs) {
50-
if (newOutgoing == outgoing)
51-
newOutgoing = new HashSet<>(outgoing);
52-
newOutgoing.add(widened);
53-
newOutgoing.remove(abs);
54+
toAdd.add(widened);
55+
it.remove();
5456
}
5557
}
56-
return newOutgoing;
58+
outgoing.addAll(toAdd);
59+
return false;
5760
}
5861
}

soot-infoflow/src/soot/jimple/infoflow/data/pathBuilders/ContextSensitivePathBuilder.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,10 @@ protected boolean checkForSource(Abstraction abs, SourceContextAndPath scap) {
220220

221221
// A source should normally never have neighbors, but it can happen
222222
// with ICCTA
223-
if (abs.getNeighbors() != null) {
224-
// we ignore this issue for now, because the neighbor's source
225-
// contexts seem to be equal to our own one
226-
}
223+
//if (abs.getNeighbors() != null) {
224+
// we ignore this issue for now, because the neighbor's source
225+
// contexts seem to be equal to our own one
226+
//}
227227

228228
// Register the source that we have found
229229
SourceContext sourceContext = abs.getSourceContext();

soot-infoflow/src/soot/jimple/infoflow/handlers/SequentialTaintPropagationHandler.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package soot.jimple.infoflow.handlers;
22

33
import java.util.ArrayList;
4-
import java.util.HashSet;
54
import java.util.List;
65
import java.util.Set;
76

@@ -63,18 +62,17 @@ public void notifyFlowIn(Unit stmt, Abstraction taint, InfoflowManager manager,
6362
}
6463

6564
@Override
66-
public Set<Abstraction> notifyFlowOut(Unit stmt, Abstraction d1, Abstraction incoming, Set<Abstraction> outgoing,
65+
public boolean notifyFlowOut(Unit stmt, Abstraction d1, Abstraction incoming, Set<Abstraction> outgoing,
6766
InfoflowManager manager, FlowFunctionType type) {
6867
if (innerHandlers.isEmpty())
69-
return outgoing;
68+
return false;
7069

71-
Set<Abstraction> resultSet = new HashSet<>();
70+
boolean killed = false;
7271
for (TaintPropagationHandler handler : innerHandlers) {
73-
Set<Abstraction> handlerResults = handler.notifyFlowOut(stmt, d1, incoming, outgoing, manager, type);
74-
if (handlerResults != null && !handlerResults.isEmpty())
75-
resultSet.addAll(handlerResults);
72+
if (handler.notifyFlowOut(stmt, d1, incoming, outgoing, manager, type))
73+
killed = true;
7674
}
77-
return resultSet;
75+
return killed;
7876
}
7977

8078
/**

soot-infoflow/src/soot/jimple/infoflow/handlers/TaintPropagationHandler.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,9 @@ public enum FlowFunctionType {
5353
* The manager object that gives access to the data flow engine
5454
* @param type
5555
* The type of data flow edge being processed
56-
* @return The new abstractions to be propagated on. If you do not want to
57-
* change the normal propagation behavior, just return the value of the
58-
* "taints" parameter as-is.
56+
* @return Whether to kill the outgoing set
5957
*/
60-
public Set<Abstraction> notifyFlowOut(Unit stmt, Abstraction d1, Abstraction incoming, Set<Abstraction> outgoing,
58+
public boolean notifyFlowOut(Unit stmt, Abstraction d1, Abstraction incoming, Set<Abstraction> outgoing,
6159
InfoflowManager manager, FlowFunctionType type);
6260

6361
}

soot-infoflow/src/soot/jimple/infoflow/problems/AbstractInfoflowProblem.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,14 @@
4242
import soot.jimple.infoflow.taintWrappers.ITaintPropagationWrapper;
4343
import soot.jimple.infoflow.util.SystemClassHandler;
4444
import soot.jimple.toolkits.ide.DefaultJimpleIFDSTabulationProblem;
45-
import soot.jimple.toolkits.ide.icfg.BiDiInterproceduralCFG;
4645

4746
/**
4847
* abstract super class which - concentrates functionality used by
4948
* InfoflowProblem and AliasProblem - contains helper functions which should not
5049
* pollute the naturally large InfofflowProblems
5150
*
5251
*/
53-
public abstract class AbstractInfoflowProblem
54-
extends DefaultJimpleIFDSTabulationProblem<Abstraction, IInfoflowCFG> {
52+
public abstract class AbstractInfoflowProblem extends DefaultJimpleIFDSTabulationProblem<Abstraction, IInfoflowCFG> {
5553

5654
protected final InfoflowManager manager;
5755

@@ -321,8 +319,11 @@ protected boolean isExceptionHandler(Unit u) {
321319
*/
322320
protected Set<Abstraction> notifyOutFlowHandlers(Unit stmt, Abstraction d1, Abstraction incoming,
323321
Set<Abstraction> outgoing, FlowFunctionType functionType) {
324-
if (taintPropagationHandler != null && outgoing != null && !outgoing.isEmpty())
325-
outgoing = taintPropagationHandler.notifyFlowOut(stmt, d1, incoming, outgoing, manager, functionType);
322+
if (taintPropagationHandler != null && outgoing != null && !outgoing.isEmpty()) {
323+
boolean res = taintPropagationHandler.notifyFlowOut(stmt, d1, incoming, outgoing, manager, functionType);
324+
if (res)
325+
return null;
326+
}
326327
return outgoing;
327328
}
328329

soot-infoflow/src/soot/jimple/infoflow/results/InfoflowResults.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,7 @@ public Collection<Pair<ResultSourceInfo, ResultSinkInfo>> addResult(
171171
if (propagationPath != null) {
172172
stmtPath = new ArrayList<>(propagationPath.size());
173173
apPath = new ArrayList<>(propagationPath.size());
174-
if (!manager.getConfig().getPathAgnosticResults())
175-
csPath = new ArrayList<>(propagationPath.size());
174+
csPath = new ArrayList<>(propagationPath.size());
176175
for (Abstraction pathAbs : propagationPath) {
177176
if (pathAbs.getCurrentStmt() != null) {
178177
stmtPath.add(pathAbs.getCurrentStmt());

soot-infoflow/src/soot/jimple/infoflow/river/SecondaryFlowGenerator.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
import java.util.Set;
66

77
import heros.solver.PathEdge;
8-
import soot.*;
8+
import soot.RefType;
9+
import soot.Unit;
10+
import soot.Value;
11+
import soot.ValueBox;
912
import soot.jimple.InstanceInvokeExpr;
1013
import soot.jimple.Stmt;
1114
import soot.jimple.infoflow.InfoflowManager;
@@ -52,15 +55,15 @@ public void notifyFlowIn(Unit stmt, Abstraction taint, InfoflowManager manager,
5255
}
5356

5457
@Override
55-
public Set<Abstraction> notifyFlowOut(Unit unit, Abstraction d1, Abstraction incoming, Set<Abstraction> outgoing,
58+
public boolean notifyFlowOut(Unit unit, Abstraction d1, Abstraction incoming, Set<Abstraction> outgoing,
5659
InfoflowManager manager, FlowFunctionType type) {
5760
// We only need to handle CallToReturn edges
5861
if (type != FlowFunctionType.CallToReturnFlowFunction)
59-
return outgoing;
62+
return false;
6063

6164
// Check whether any use matches the incoming taint
6265
if (!isReadAt(unit, incoming.getAccessPath()))
63-
return outgoing;
66+
return false;
6467

6568
ensureCondFlowManager(manager);
6669

@@ -82,15 +85,15 @@ public Set<Abstraction> notifyFlowOut(Unit unit, Abstraction d1, Abstraction inc
8285
}
8386

8487
// Check for usage contexts
85-
for (AdditionalFlowInfoSpecification spec : manager.getUsageContextProvider().needsAdditionalInformation(stmt, outgoing))
88+
for (AdditionalFlowInfoSpecification spec : manager.getUsageContextProvider().needsAdditionalInformation(stmt,
89+
outgoing))
8690
additionalAbsSet.add(createAdditionalFlowAbstraction(spec, stmt, manager));
8791

8892
// Query the backward analysis
8993
for (Abstraction addAbs : additionalAbsSet)
9094
for (Unit pred : manager.getICFG().getPredsOf(unit))
9195
manager.additionalManager.getMainSolver().processEdge(new PathEdge<>(d1, pred, addAbs));
92-
93-
return outgoing;
96+
return false;
9497
}
9598

9699
/**
@@ -117,7 +120,8 @@ protected Abstraction createAdditionalFlowAbstraction(Abstraction baseTaint, Stm
117120
* @param manager Infoflow Manager
118121
* @return New abstraction
119122
*/
120-
protected Abstraction createAdditionalFlowAbstraction(AdditionalFlowInfoSpecification spec, Stmt stmt, InfoflowManager manager) {
123+
protected Abstraction createAdditionalFlowAbstraction(AdditionalFlowInfoSpecification spec, Stmt stmt,
124+
InfoflowManager manager) {
121125
AccessPath ap = spec.toAccessPath(manager);
122126
ISourceSinkDefinition def = spec.getDefinition();
123127
Abstraction newAbs = new Abstraction(Collections.singleton(def), ap, stmt, null, false, false);

soot-infoflow/src/soot/jimple/infoflow/river/SecondaryFlowListener.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import soot.jimple.infoflow.InfoflowManager;
88
import soot.jimple.infoflow.data.Abstraction;
99
import soot.jimple.infoflow.handlers.TaintPropagationHandler;
10-
import soot.jimple.infoflow.problems.rules.PropagationRuleManager;
1110
import soot.jimple.infoflow.problems.rules.ITaintPropagationRule;
11+
import soot.jimple.infoflow.problems.rules.PropagationRuleManager;
1212

1313
/**
1414
* TaintPropagationHandler to record which statements secondary flows reach.
@@ -37,7 +37,8 @@ private void ensureSourcePropagationRule(InfoflowManager manager) {
3737
}
3838
}
3939

40-
throw new IllegalStateException("Enabled additional flows but no IConditionalFlowSinkPropagationRule in place!");
40+
throw new IllegalStateException(
41+
"Enabled additional flows but no IConditionalFlowSinkPropagationRule in place!");
4142
}
4243

4344
@Override
@@ -59,10 +60,10 @@ public void notifyFlowIn(Unit unit, Abstraction incoming, InfoflowManager manage
5960
}
6061

6162
@Override
62-
public Set<Abstraction> notifyFlowOut(Unit stmt, Abstraction d1, Abstraction incoming, Set<Abstraction> outgoing,
63+
public boolean notifyFlowOut(Unit stmt, Abstraction d1, Abstraction incoming, Set<Abstraction> outgoing,
6364
InfoflowManager manager, FlowFunctionType type) {
6465
// NO-OP
65-
return outgoing;
66+
return false;
6667
}
6768

6869
}

soot-infoflow/src/soot/jimple/infoflow/util/DebugFlowFunctionTaintPropagationHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ public void notifyFlowIn(Unit stmt, Abstraction taint, InfoflowManager manager,
5555
}
5656

5757
@Override
58-
public Set<Abstraction> notifyFlowOut(Unit stmt, Abstraction d1, Abstraction incoming, Set<Abstraction> outgoing,
58+
public boolean notifyFlowOut(Unit stmt, Abstraction d1, Abstraction incoming, Set<Abstraction> outgoing,
5959
InfoflowManager manager, FlowFunctionType type) {
6060
if (this.filter != null && !this.filter.evaluate(manager.getICFG().getMethodOf(stmt).toString()))
61-
return outgoing;
61+
return false;
6262

6363
String typeString = "";
6464
switch (type) {
@@ -88,7 +88,7 @@ public Set<Abstraction> notifyFlowOut(Unit stmt, Abstraction d1, Abstraction inc
8888
} else
8989
System.out.println(this.prefix + " " + typeString + " @ " + stmt + ":\n\tIn: " + incoming + "\n\tOut: "
9090
+ outgoing + "\n");
91+
return false;
9192

92-
return outgoing;
9393
}
9494
}

0 commit comments

Comments
 (0)