Skip to content

Commit 8c7acde

Browse files
authored
Merge pull request #424 from stefanie-koss/fixTaintWrappers
Fix killed taints in taint wrappers
2 parents 122ff47 + 22b8077 commit 8c7acde

File tree

3 files changed

+33
-33
lines changed

3 files changed

+33
-33
lines changed

soot-infoflow-summaries/src/soot/jimple/infoflow/methodSummary/generator/SummaryGenerationTaintWrapper.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,19 +127,23 @@ protected Set<Abstraction> getTaintsForHashCodeEquals(Stmt stmt, Abstraction tai
127127
InstanceInvokeExpr iiexpr = (InstanceInvokeExpr) iexpr;
128128
AccessPath ap = taintedPath.getAccessPath();
129129

130+
final Set<Abstraction> taints = new HashSet<Abstraction>();
131+
132+
// We always keep the incoming taint
133+
taints.add(taintedPath);
134+
130135
// Check for hashCode()
131136
if (ref.getName().equals("hashCode") && ref.getParameterTypes().isEmpty()
132137
&& ref.getReturnType() instanceof IntType) {
133138
if (ap.getPlainValue() == iiexpr.getBase()) {
134139
// If the return value is used, we taint it
135140
if (stmt instanceof DefinitionStmt) {
136141
DefinitionStmt defStmt = (DefinitionStmt) stmt;
137-
return Collections.singleton(taintedPath.deriveNewAbstraction(
142+
taints.add(taintedPath.deriveNewAbstraction(
138143
manager.getAccessPathFactory().createAccessPath(defStmt.getLeftOp(), false), stmt));
139144
}
140145

141-
// The return value is apparently ignored
142-
return Collections.emptySet();
146+
return taints;
143147
}
144148
}
145149

@@ -150,12 +154,11 @@ protected Set<Abstraction> getTaintsForHashCodeEquals(Stmt stmt, Abstraction tai
150154
// If the return value is used, we taint it
151155
if (config.getImplicitFlowMode().trackControlFlowDependencies() && stmt instanceof DefinitionStmt) {
152156
DefinitionStmt defStmt = (DefinitionStmt) stmt;
153-
return Collections.singleton(taintedPath.deriveNewAbstraction(
157+
taints.add(taintedPath.deriveNewAbstraction(
154158
manager.getAccessPathFactory().createAccessPath(defStmt.getLeftOp(), false), stmt));
155159
}
156160

157-
// The return value is apparently ignored
158-
return Collections.emptySet();
161+
return taints;
159162
}
160163
}
161164

soot-infoflow/src/soot/jimple/infoflow/taintWrappers/EasyTaintWrapper.java

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -186,22 +186,16 @@ public EasyTaintWrapper(EasyTaintWrapper taintWrapper) {
186186
@Override
187187
public Set<AccessPath> getTaintsForMethodInternal(Stmt stmt, AccessPath taintedPath) {
188188
if (!stmt.containsInvokeExpr())
189-
return Collections.emptySet();
189+
return Collections.singleton(taintedPath);
190190

191191
final Set<AccessPath> taints = new HashSet<AccessPath>();
192192
final SootMethod method = stmt.getInvokeExpr().getMethod();
193193

194-
// If the callee is a phantom class or has no body, we pass on the taint
195-
if (method.isPhantom() || !method.hasActiveBody()) {
196-
// Exception: Tainted value is overwritten
197-
if (!(!taintedPath.isStaticFieldRef() && stmt instanceof DefinitionStmt
198-
&& ((DefinitionStmt) stmt).getLeftOp() == taintedPath.getPlainValue()))
199-
taints.add(taintedPath);
200-
}
194+
// We always keep the incoming taint
195+
taints.add(taintedPath);
201196

202-
// For the moment, we don't implement static taints on wrappers. Pass it
203-
// on
204-
// not to break anything
197+
// For the moment, we don't implement static taints on wrappers. Pass it on not
198+
// to break anything
205199
if (taintedPath.isStaticFieldRef())
206200
return Collections.singleton(taintedPath);
207201

@@ -249,9 +243,6 @@ public Set<AccessPath> getTaintsForMethodInternal(Stmt stmt, AccessPath taintedP
249243
&& SystemClassHandler.v().isTaintVisible(taintedPath, method))
250244
taints.add(manager.getAccessPathFactory().createAccessPath(def.getLeftOp(), true));
251245
}
252-
253-
// If the base object is tainted, we pass this taint on
254-
taints.add(taintedPath);
255246
}
256247
}
257248

@@ -289,10 +280,6 @@ public Set<AccessPath> getTaintsForMethodInternal(Stmt stmt, AccessPath taintedP
289280
if (stmt.getInvokeExprBox().getValue() instanceof InstanceInvokeExpr)
290281
taints.add(manager.getAccessPathFactory().createAccessPath(
291282
((InstanceInvokeExpr) stmt.getInvokeExprBox().getValue()).getBase(), true));
292-
293-
// The originally tainted parameter or base object as such
294-
// stays tainted
295-
taints.add(taintedPath);
296283
}
297284
}
298285

soot-infoflow/src/soot/jimple/infoflow/taintWrappers/IdentityTaintWrapper.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
package soot.jimple.infoflow.taintWrappers;
1212

1313
import java.util.Collections;
14+
import java.util.HashSet;
1415
import java.util.Set;
1516

1617
import soot.SootMethod;
@@ -38,29 +39,38 @@ public Set<AccessPath> getTaintsForMethodInternal(Stmt stmt, AccessPath taintedP
3839
if (!stmt.getInvokeExpr().getMethod().getDeclaringClass().isLibraryClass())
3940
return null;
4041

41-
// For the moment, we don't implement static taints on wrappers. Pass it on
42-
// not to break anything
42+
// For the moment, we don't implement static taints on wrappers. Pass it on not
43+
// to break anything
4344
if (taintedPath.isStaticFieldRef())
4445
return Collections.singleton(taintedPath);
4546

47+
final Set<AccessPath> taints = new HashSet<AccessPath>();
48+
49+
// We always keep the incoming taint
50+
taints.add(taintedPath);
51+
4652
if (stmt.getInvokeExpr() instanceof InstanceInvokeExpr) {
4753
InstanceInvokeExpr iiExpr = (InstanceInvokeExpr) stmt.getInvokeExpr();
4854

4955
// If the base object is tainted, the return value is always tainted
5056
if (taintedPath.getPlainValue().equals(iiExpr.getBase()))
51-
if (stmt instanceof AssignStmt)
52-
return Collections.singleton(manager.getAccessPathFactory()
53-
.createAccessPath(((AssignStmt) stmt).getLeftOp(), taintedPath.getTaintSubFields()));
57+
if (stmt instanceof AssignStmt) {
58+
taints.add(manager.getAccessPathFactory().createAccessPath(((AssignStmt) stmt).getLeftOp(),
59+
taintedPath.getTaintSubFields()));
60+
return taints;
61+
}
5462
}
5563

5664
// If one of the parameters is tainted, the return value is tainted, too
5765
for (Value param : stmt.getInvokeExpr().getArgs())
5866
if (taintedPath.getPlainValue().equals(param))
59-
if (stmt instanceof AssignStmt)
60-
return Collections.singleton(manager.getAccessPathFactory()
61-
.createAccessPath(((AssignStmt) stmt).getLeftOp(), taintedPath.getTaintSubFields()));
67+
if (stmt instanceof AssignStmt) {
68+
taints.add(manager.getAccessPathFactory().createAccessPath(((AssignStmt) stmt).getLeftOp(),
69+
taintedPath.getTaintSubFields()));
70+
return taints;
71+
}
6272

63-
return Collections.emptySet();
73+
return taints;
6474
}
6575

6676
@Override

0 commit comments

Comments
 (0)