|
15 | 15 | import soot.Type; |
16 | 16 | import soot.Unit; |
17 | 17 | 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.*; |
34 | 19 | import soot.jimple.infoflow.InfoflowConfiguration; |
35 | 20 | import soot.jimple.infoflow.InfoflowManager; |
36 | 21 | import soot.jimple.infoflow.aliasing.Aliasing; |
@@ -135,42 +120,57 @@ private Set<Abstraction> computeAliases(final DefinitionStmt defStmt, Abstractio |
135 | 120 |
|
136 | 121 | AccessPath ap = source.getAccessPath(); |
137 | 122 | Value sourceBase = ap.getPlainValue(); |
| 123 | + Type rightType = rightOp.getType(); |
138 | 124 | boolean handoverLeftValue = false; |
| 125 | + boolean cutSubfield = false; |
139 | 126 | boolean leftSideOverwritten = false; |
140 | 127 | if (leftOp instanceof StaticFieldRef) { |
141 | 128 | if (manager.getConfig() |
142 | 129 | .getStaticFieldTrackingMode() != InfoflowConfiguration.StaticFieldTrackingMode.None |
143 | 130 | && ap.firstFieldMatches(((StaticFieldRef) leftOp).getField())) { |
144 | 131 | handoverLeftValue = true; |
| 132 | + cutSubfield = true; |
145 | 133 | } |
146 | 134 | } else if (leftOp instanceof InstanceFieldRef) { |
147 | 135 | InstanceFieldRef instRef = (InstanceFieldRef) leftOp; |
148 | 136 |
|
149 | 137 | // base matches |
150 | 138 | 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) { |
161 | 142 | handoverLeftValue = true; |
| 143 | + cutSubfield = true; |
| 144 | + if (!mappedAp.equals(ap)) |
| 145 | + ap = mappedAp; |
162 | 146 | } |
163 | 147 | } |
164 | 148 | } else if (leftVal == sourceBase) { |
165 | 149 | // 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; |
167 | 152 | leftSideOverwritten = !handoverLeftValue; |
168 | 153 | } |
169 | 154 |
|
170 | 155 | 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 | + } |
174 | 174 | } |
175 | 175 |
|
176 | 176 | if (leftSideOverwritten) |
|
0 commit comments