Skip to content

Commit f108b20

Browse files
committed
Fix new testcase in backward direction
1 parent 93f1fd4 commit f108b20

2 files changed

Lines changed: 30 additions & 31 deletions

File tree

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

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,7 @@
1515
import soot.Type;
1616
import soot.Unit;
1717
import soot.Value;
18-
import soot.jimple.ArrayRef;
19-
import soot.jimple.AssignStmt;
20-
import soot.jimple.BinopExpr;
21-
import soot.jimple.CastExpr;
22-
import soot.jimple.DefinitionStmt;
23-
import soot.jimple.FieldRef;
24-
import soot.jimple.IdentityStmt;
25-
import soot.jimple.InstanceFieldRef;
26-
import soot.jimple.InstanceInvokeExpr;
27-
import soot.jimple.InstanceOfExpr;
28-
import soot.jimple.InvokeExpr;
29-
import soot.jimple.NewArrayExpr;
30-
import soot.jimple.ReturnStmt;
31-
import soot.jimple.StaticFieldRef;
32-
import soot.jimple.Stmt;
33-
import soot.jimple.UnopExpr;
18+
import soot.jimple.*;
3419
import soot.jimple.infoflow.InfoflowConfiguration;
3520
import soot.jimple.infoflow.InfoflowManager;
3621
import soot.jimple.infoflow.aliasing.Aliasing;
@@ -135,42 +120,57 @@ private Set<Abstraction> computeAliases(final DefinitionStmt defStmt, Abstractio
135120

136121
AccessPath ap = source.getAccessPath();
137122
Value sourceBase = ap.getPlainValue();
123+
Type rightType = rightOp.getType();
138124
boolean handoverLeftValue = false;
125+
boolean cutSubfield = false;
139126
boolean leftSideOverwritten = false;
140127
if (leftOp instanceof StaticFieldRef) {
141128
if (manager.getConfig()
142129
.getStaticFieldTrackingMode() != InfoflowConfiguration.StaticFieldTrackingMode.None
143130
&& ap.firstFieldMatches(((StaticFieldRef) leftOp).getField())) {
144131
handoverLeftValue = true;
132+
cutSubfield = true;
145133
}
146134
} else if (leftOp instanceof InstanceFieldRef) {
147135
InstanceFieldRef instRef = (InstanceFieldRef) leftOp;
148136

149137
// base matches
150138
if (instRef.getBase() == sourceBase) {
151-
// field matches
152-
if (ap.firstFieldMatches(instRef.getField())) {
153-
handoverLeftValue = true;
154-
}
155-
// whole object matches
156-
else if (ap.getTaintSubFields() && ap.getFragmentCount() == 0) {
157-
handoverLeftValue = true;
158-
}
159-
// due to cut down access path we can not know better
160-
else if (source.dependsOnCutAP() || isCircularType(leftVal)) {
139+
AccessPath mappedAp = Aliasing.getReferencedAPBase(ap,
140+
new SootField[] { instRef.getField() }, manager);
141+
if (mappedAp != null) {
161142
handoverLeftValue = true;
143+
cutSubfield = true;
144+
if (!mappedAp.equals(ap))
145+
ap = mappedAp;
162146
}
163147
}
164148
} else if (leftVal == sourceBase) {
165149
// Either the alias is overwritten here or a write to an array element
166-
handoverLeftValue = leftOp instanceof ArrayRef;
150+
handoverLeftValue = leftOp instanceof ArrayRef
151+
&& ap.getArrayTaintType() != AccessPath.ArrayTaintType.Length;
167152
leftSideOverwritten = !handoverLeftValue;
168153
}
169154

170155
if (handoverLeftValue) {
171-
// We found a missed path upwards
172-
// inject same stmt in infoflow solver
173-
handOver(d1, srcUnit, source);
156+
Abstraction newAbs = null;
157+
if (rightVal instanceof Constant) {
158+
if (manager.getConfig().getImplicitFlowMode().trackControlFlowDependencies()) {
159+
newAbs = source.deriveConditionalUpdate(assignStmt);
160+
for (Unit pred : manager.getICFG().getPredsOf(srcUnit))
161+
handOver(d1, pred, newAbs);
162+
}
163+
} else {
164+
AccessPath newAp = manager.getAccessPathFactory().copyWithNewValue(ap, rightOp, rightType, cutSubfield);
165+
newAbs = source.deriveNewAbstraction(newAp, assignStmt);
166+
}
167+
168+
if (newAbs != null && !newAbs.equals(source)) {
169+
// We found a missed path upwards
170+
// inject same stmt in infoflow solver
171+
for (Unit pred : manager.getICFG().getPredsOf(srcUnit))
172+
handOver(d1, pred, newAbs);
173+
}
174174
}
175175

176176
if (leftSideOverwritten)

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,6 @@ public void negativeSingleAliasTest() {
677677
IInfoflow infoflow = initInfoflow();
678678
infoflow.getConfig().setInspectSources(false);
679679
infoflow.getConfig().setInspectSinks(false);
680-
infoflow.getConfig().setWriteOutputFiles(true);
681680

682681
List<String> epoints = new ArrayList<String>();
683682
epoints.add("<soot.jimple.infoflow.test.HeapTestCode: void negativeSingleAliasTest()>");

0 commit comments

Comments
 (0)