Skip to content

Commit 5cbf632

Browse files
committed
C++: Inline and simplify 'Assignment to another stack variable' case in NullTermination.qll.
1 parent f38dade commit 5cbf632

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

cpp/ql/lib/semmle/code/cpp/commons/NullTermination.qll

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,8 @@ private import semmle.code.cpp.models.interfaces.ArrayFunction
33
private import semmle.code.cpp.models.implementations.Strcat
44
import semmle.code.cpp.dataflow.DataFlow
55

6-
private predicate mayAddNullTerminatorHelper(Expr e, VariableAccess va, Expr e0) {
7-
exists(StackVariable v0, Expr val |
8-
exprDefinition(v0, e, val) and
9-
val.getAChild*() = va and
10-
mayAddNullTerminator(e0, v0.getAnAccess())
11-
)
12-
}
13-
146
/**
15-
* Holds if the expression `e` may add a null terminator to the string in
16-
* variable `v`.
7+
* Holds if the expression `e` may add a null terminator to the string in `va`.
178
*/
189
predicate mayAddNullTerminator(Expr e, VariableAccess va) {
1910
// Assignment: dereferencing or array access
@@ -30,14 +21,12 @@ predicate mayAddNullTerminator(Expr e, VariableAccess va) {
3021
)
3122
or
3223
// Assignment to another stack variable
33-
exists(Expr e0, BasicBlock bb, int pos, BasicBlock bb0, int pos0 |
34-
mayAddNullTerminatorHelper(e, va, e0) and
35-
bb.getNode(pos) = e and
36-
bb0.getNode(pos0) = e0
37-
|
38-
bb = bb0 and pos < pos0
39-
or
40-
bb.getASuccessor+() = bb0
24+
exists(Expr e0 |
25+
exists(StackVariable v0, Expr val |
26+
exprDefinition(v0, e, val) and // e resembles `v0 := val`
27+
val.getAChild*() = va and
28+
mayAddNullTerminator(e0, v0.getAnAccess())
29+
)
4130
)
4231
or
4332
// Assignment to non-stack variable

0 commit comments

Comments
 (0)