Skip to content

Commit 7fefe43

Browse files
authored
Merge pull request github#1963 from jbj/predictableInstruction
C++: Implement predictableInstruction without Expr
2 parents ebc10cf + 30d1c32 commit 7fefe43

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

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

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,17 @@ private import semmle.code.cpp.ir.dataflow.DataFlow
44
private import semmle.code.cpp.ir.IR
55

66
/**
7-
* A predictable expression is one where an external user can predict
7+
* A predictable instruction is one where an external user can predict
88
* the value. For example, a literal in the source code is considered
99
* predictable.
1010
*/
11-
// TODO: Change to use Instruction instead of Expr. Naive attempt breaks
12-
// TaintedAllocationSize qltest.
13-
private predicate predictable(Expr expr) {
14-
expr instanceof Literal
11+
private predicate predictableInstruction(Instruction instr) {
12+
instr instanceof ConstantInstruction
1513
or
16-
exists(BinaryOperation binop | binop = expr |
17-
predictable(binop.getLeftOperand()) and predictable(binop.getRightOperand())
18-
)
14+
instr instanceof StringConstantInstruction
1915
or
20-
exists(UnaryOperation unop | unop = expr | predictable(unop.getOperand()))
21-
}
22-
23-
// TODO: remove when `predictable` has an `Instruction` parameter instead of `Expr`.
24-
private predicate predictableInstruction(Instruction instr) {
25-
predictable(DataFlow::instructionNode(instr).asExpr())
16+
// This could be a conversion on a string literal
17+
predictableInstruction(instr.(UnaryInstruction).getUnary())
2618
}
2719

2820
private class DefaultTaintTrackingCfg extends DataFlow::Configuration {

0 commit comments

Comments
 (0)