Skip to content

Commit 5eeb5c6

Browse files
committed
C++: Use asExpr, not getConvertedResultExpression
We designed the IR's `DataFlow::Node.asExpr` very carefully so that it's suitable for taint tracking, but then we didn't use it in `DefaultTaintTracking.qll`. This meant that the sources in `ArithmeticWithExtremeValues.ql` didn't get associated with any `Instruction` and thus didn't propagate anywhere. With this commit, the mapping of `Expr`-based sources to IR data-flow nodes uses `asExpr`.
1 parent ceeb9ab commit 5eeb5c6

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

cpp/ql/src/semmle/code/cpp/ir/dataflow/DefaultTaintTracking.qll

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,29 @@ private predicate predictableInstruction(Instruction instr) {
1919
predictableInstruction(instr.(UnaryInstruction).getUnary())
2020
}
2121

22-
private predicate userInputInstruction(Instruction instr) {
23-
exists(CallInstruction ci, WriteSideEffectInstruction wsei |
24-
userInputArgument(ci.getConvertedResultExpression(), wsei.getIndex()) and
25-
instr = wsei and
26-
wsei.getPrimaryInstruction() = ci
27-
)
28-
or
29-
userInputReturned(instr.getConvertedResultExpression())
30-
or
31-
isUserInput(instr.getConvertedResultExpression(), _)
32-
or
33-
instr.getConvertedResultExpression() instanceof EnvironmentRead
34-
or
35-
instr
36-
.(LoadInstruction)
37-
.getSourceAddress()
38-
.(VariableAddressInstruction)
39-
.getASTVariable()
40-
.hasName("argv") and
41-
instr.getEnclosingFunction().hasGlobalName("main")
42-
}
43-
4422
private class DefaultTaintTrackingCfg extends DataFlow::Configuration {
4523
DefaultTaintTrackingCfg() { this = "DefaultTaintTrackingCfg" }
4624

4725
override predicate isSource(DataFlow::Node source) {
48-
userInputInstruction(source.asInstruction())
26+
exists(CallInstruction ci, WriteSideEffectInstruction wsei |
27+
userInputArgument(ci.getConvertedResultExpression(), wsei.getIndex()) and
28+
source.asInstruction() = wsei and
29+
wsei.getPrimaryInstruction() = ci
30+
)
31+
or
32+
userInputReturned(source.asExpr())
33+
or
34+
isUserInput(source.asExpr(), _)
35+
or
36+
source.asExpr() instanceof EnvironmentRead
37+
or
38+
source.asInstruction()
39+
.(LoadInstruction)
40+
.getSourceAddress()
41+
.(VariableAddressInstruction)
42+
.getASTVariable()
43+
.hasName("argv") and
44+
source.asInstruction().getEnclosingFunction().hasGlobalName("main")
4945
}
5046

5147
override predicate isSink(DataFlow::Node sink) { any() }

0 commit comments

Comments
 (0)