@@ -3,8 +3,17 @@ private import semmle.code.cpp.models.interfaces.ArrayFunction
33private import semmle.code.cpp.models.implementations.Strcat
44import 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+
614/**
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`.
817 */
918predicate mayAddNullTerminator ( Expr e , VariableAccess va ) {
1019 // Assignment: dereferencing or array access
@@ -21,10 +30,14 @@ predicate mayAddNullTerminator(Expr e, VariableAccess va) {
2130 )
2231 or
2332 // 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
2841 )
2942 or
3043 // Assignment to non-stack variable
0 commit comments