Skip to content

Commit ecf09a4

Browse files
committed
Fix backward path reconstruction
1 parent 16d9c66 commit ecf09a4

5 files changed

Lines changed: 25 additions & 63 deletions

File tree

soot-infoflow/src/soot/jimple/infoflow/data/SourceContextAndPath.java

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -210,32 +210,15 @@ public SourceContextAndPath extendPath(Abstraction abs, InfoflowConfiguration co
210210
}
211211

212212
// Extend the call stack
213-
switch (config.getDataFlowDirection()) {
214-
case Forwards:
215-
if (abs.getCorrespondingCallSite() != null && abs.getCorrespondingCallSite() != abs.getCurrentStmt()) {
216-
if (scap == null)
217-
scap = this.clone();
218-
if (scap.callStack == null)
219-
scap.callStack = new ExtensibleList<Stmt>();
220-
else if (pathConfig != null && pathConfig.getMaxCallStackSize() > 0
221-
&& scap.callStack.size() >= pathConfig.getMaxCallStackSize())
222-
return null;
223-
scap.callStack.add(abs.getCorrespondingCallSite());
224-
}
225-
break;
226-
case Backwards:
227-
if (abs.getCurrentStmt() != null && abs.getCurrentStmt().containsInvokeExpr()
228-
&& abs.getCorrespondingCallSite() != abs.getCurrentStmt()) {
229-
if (scap == null)
230-
scap = this.clone();
231-
if (scap.callStack == null)
232-
scap.callStack = new ExtensibleList<Stmt>();
233-
else if (pathConfig != null && pathConfig.getMaxCallStackSize() > 0
234-
&& scap.callStack.size() >= pathConfig.getMaxCallStackSize())
235-
return null;
236-
scap.callStack.add(abs.getCurrentStmt());
237-
}
238-
break;
213+
if (abs.getCorrespondingCallSite() != null && abs.getCorrespondingCallSite() != abs.getCurrentStmt()) {
214+
if (scap == null)
215+
scap = this.clone();
216+
if (scap.callStack == null)
217+
scap.callStack = new ExtensibleList<Stmt>();
218+
else if (pathConfig != null && pathConfig.getMaxCallStackSize() > 0
219+
&& scap.callStack.size() >= pathConfig.getMaxCallStackSize())
220+
return null;
221+
scap.callStack.add(abs.getCorrespondingCallSite());
239222
}
240223

241224
this.neighborCounter = abs.getNeighbors() == null ? 0 : abs.getNeighbors().size();

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

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -136,40 +136,19 @@ private ProcessingResult processPredecessor(SourceContextAndPath scap, Abstracti
136136
return ProcessingResult.INFEASIBLE_OR_MAX_PATHS_REACHED();
137137

138138
// Check if we are in the right context
139-
switch (manager.getConfig().getDataFlowDirection()) {
140-
case Forwards:
141-
if (pred.getCurrentStmt() != null && pred.getCurrentStmt().containsInvokeExpr()) {
142-
// Pop the top item off the call stack. This gives us the item
143-
// and the new SCAP without the item we popped off.
144-
Pair<SourceContextAndPath, Stmt> pathAndItem = extendedScap.popTopCallStackItem();
145-
if (pathAndItem != null) {
146-
Stmt topCallStackItem = pathAndItem.getO2();
147-
// Make sure that we don't follow an unrealizable path
148-
if (topCallStackItem != pred.getCurrentStmt())
149-
return ProcessingResult.INFEASIBLE_OR_MAX_PATHS_REACHED();
150-
151-
// We have returned from a function
152-
extendedScap = pathAndItem.getO1();
153-
}
139+
if (pred.getCurrentStmt() != null && pred.getCurrentStmt().containsInvokeExpr()) {
140+
// Pop the top item off the call stack. This gives us the item
141+
// and the new SCAP without the item we popped off.
142+
Pair<SourceContextAndPath, Stmt> pathAndItem = extendedScap.popTopCallStackItem();
143+
if (pathAndItem != null) {
144+
Stmt topCallStackItem = pathAndItem.getO2();
145+
// Make sure that we don't follow an unrealizable path
146+
if (topCallStackItem != pred.getCurrentStmt())
147+
return ProcessingResult.INFEASIBLE_OR_MAX_PATHS_REACHED();
148+
149+
// We have returned from a function
150+
extendedScap = pathAndItem.getO1();
154151
}
155-
break;
156-
case Backwards:
157-
if (pred.getCorrespondingCallSite() != null
158-
&& pred.getCorrespondingCallSite() != pred.getCurrentStmt()) {
159-
// Pop the top item off the call stack. This gives us the item
160-
// and the new SCAP without the item we popped off.
161-
Pair<SourceContextAndPath, Stmt> pathAndItem = extendedScap.popTopCallStackItem();
162-
if (pathAndItem != null) {
163-
Stmt topCallStackItem = pathAndItem.getO2();
164-
// Make sure that we don't follow an unrealizable path
165-
if (topCallStackItem != pred.getCorrespondingCallSite())
166-
return ProcessingResult.INFEASIBLE_OR_MAX_PATHS_REACHED();
167-
168-
// We have returned from a function
169-
extendedScap = pathAndItem.getO1();
170-
}
171-
}
172-
break;
173152
}
174153

175154
// Add the new path

soot-infoflow/src/soot/jimple/infoflow/problems/rules/backward/BackwardsImplicitFlowRule.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ public Collection<Abstraction> propagateCallToReturnFlow(Abstraction d1, Abstrac
243243
for (Unit condUnit : condUnits) {
244244
Abstraction abs = new Abstraction(sink.getDefinition(), AccessPath.getEmptyAccessPath(), stmt,
245245
sink.getUserData(), false, false);
246+
abs.setCorrespondingCallSite(stmt);
246247
abs.setDominator(condUnit);
247248
res.add(abs);
248249
}
@@ -252,6 +253,7 @@ public Collection<Abstraction> propagateCallToReturnFlow(Abstraction d1, Abstrac
252253
.createAccessPath(sm.getActiveBody().getThisLocal(), false);
253254
Abstraction thisTaint = new Abstraction(sink.getDefinition(), thisAp, stmt, sink.getUserData(),
254255
false, false);
256+
thisTaint.setCorrespondingCallSite(stmt);
255257
res.add(thisTaint);
256258
}
257259

soot-infoflow/src/soot/jimple/infoflow/problems/rules/backward/BackwardsSinkPropagationRule.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ private Collection<Abstraction> propagate(Abstraction source, Stmt stmt, ByRefer
5656
// Create the new taint abstraction
5757
Abstraction abs = new Abstraction(sinkInfo.getDefinition(), ap, stmt, sinkInfo.getUserData(), false,
5858
false);
59+
abs.setCorrespondingCallSite(stmt);
5960
abs = abs.deriveNewAbstractionWithTurnUnit(stmt);
6061

6162
res.add(abs);

soot-infoflow/test/soot/jimple/infoflow/test/junit/JUnitTests.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@
2424
import org.junit.Before;
2525
import org.junit.BeforeClass;
2626

27-
import soot.jimple.infoflow.AbstractInfoflow;
28-
import soot.jimple.infoflow.BackwardsInfoflow;
29-
import soot.jimple.infoflow.IInfoflow;
30-
import soot.jimple.infoflow.Infoflow;
27+
import soot.jimple.infoflow.*;
3128
import soot.jimple.infoflow.config.ConfigForTest;
3229
import soot.jimple.infoflow.results.InfoflowResults;
3330
import soot.jimple.infoflow.taintWrappers.EasyTaintWrapper;

0 commit comments

Comments
 (0)