@@ -3,8 +3,17 @@ private import semmle.code.cpp.models.interfaces.ArrayFunction
3
3
private import semmle.code.cpp.models.implementations.Strcat
4
4
import semmle.code.cpp.dataflow.DataFlow
5
5
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
+
6
14
/**
7
- * Holds if the expression `e` may add a null terminator to the string in `va`.
15
+ * Holds if the expression `e` may add a null terminator to the string in
16
+ * variable `v`.
8
17
*/
9
18
predicate mayAddNullTerminator ( Expr e , VariableAccess va ) {
10
19
// Assignment: dereferencing or array access
@@ -21,10 +30,14 @@ predicate mayAddNullTerminator(Expr e, VariableAccess va) {
21
30
)
22
31
or
23
32
// Assignment to another stack variable
24
- exists ( StackVariable v0 , Expr val |
25
- exprDefinition ( v0 , e , val ) and // e resembles `v0 := val`
26
- val .getAChild * ( ) = va and
27
- mayAddNullTerminator ( _, v0 .getAnAccess ( ) )
33
+ exists ( Expr e0 , BasicBlock bb , int pos , BasicBlock bb0 , int pos0 |
34
+ mayAddNullTerminatorHelper ( pragma [ only_bind_into ] ( e ) , va , pragma [ only_bind_into ] ( e0 ) ) and
35
+ pragma [ only_bind_into ] ( bb ) .getNode ( pos ) = e and
36
+ pragma [ only_bind_into ] ( bb0 ) .getNode ( pos0 ) = e0
37
+ |
38
+ bb = bb0 and pos < pos0
39
+ or
40
+ bb .getASuccessor + ( ) = bb0
28
41
)
29
42
or
30
43
// Assignment to non-stack variable
0 commit comments