@@ -18,9 +18,16 @@ private predicate externalCallNeverDereferences(FormattingFunctionCall call, int
18
18
)
19
19
}
20
20
21
+ /**
22
+ * Holds if `e` is a use. A use is a pointer dereference or a
23
+ * parameter to a call with no function definition.
24
+ * Uses in deallocation expressions (e.g., free) are excluded.
25
+ * Default isUse definition for an expression.
26
+ */
21
27
predicate isUse0 ( Expr e ) {
22
28
not isFree ( _, _, e , _) and
23
29
(
30
+ // TODO: use DirectDefereferencedByOperation in Dereferenced.qll
24
31
e = any ( PointerDereferenceExpr pde ) .getOperand ( )
25
32
or
26
33
e = any ( PointerFieldAccess pfa ) .getQualifier ( )
@@ -131,26 +138,22 @@ private module ParameterSinks {
131
138
}
132
139
}
133
140
134
- private module IsUse {
135
- private import semmle.code.cpp.ir.dataflow.internal.DataFlowImplCommon
136
-
137
- /**
138
- * Holds if `n` represents the expression `e`, and `e` is a pointer that is
139
- * guarenteed to be dereferenced (either because it's an operand of a
140
- * dereference operation, or because it's an argument to a function that
141
- * always dereferences the parameter).
142
- */
143
- predicate isUse ( DataFlow:: Node n , Expr e ) {
144
- isUse0 ( e ) and n .asExpr ( ) = e
145
- or
146
- exists ( CallInstruction call , InitializeParameterInstruction init |
147
- n .asOperand ( ) .getDef ( ) .getUnconvertedResultExpression ( ) = e and
148
- pragma [ only_bind_into ] ( init ) = ParameterSinks:: getAnAlwaysDereferencedParameter ( ) and
149
- viableParamArg ( call , DataFlow:: instructionNode ( init ) , n ) and
150
- pragma [ only_bind_out ] ( init .getEnclosingFunction ( ) ) =
151
- pragma [ only_bind_out ] ( call .getStaticCallTarget ( ) )
152
- )
153
- }
154
- }
141
+ private import semmle.code.cpp.ir.dataflow.internal.DataFlowImplCommon
155
142
156
- import IsUse
143
+ /**
144
+ * Holds if `n` represents the expression `e`, and `e` is a pointer that is
145
+ * guarenteed to be dereferenced (either because it's an operand of a
146
+ * dereference operation, or because it's an argument to a function that
147
+ * always dereferences the parameter).
148
+ */
149
+ predicate isUse ( DataFlow:: Node n , Expr e ) {
150
+ isUse0 ( e ) and n .asExpr ( ) = e
151
+ or
152
+ exists ( CallInstruction call , InitializeParameterInstruction init |
153
+ n .asOperand ( ) .getDef ( ) .getUnconvertedResultExpression ( ) = e and
154
+ pragma [ only_bind_into ] ( init ) = ParameterSinks:: getAnAlwaysDereferencedParameter ( ) and
155
+ viableParamArg ( call , DataFlow:: instructionNode ( init ) , n ) and
156
+ pragma [ only_bind_out ] ( init .getEnclosingFunction ( ) ) =
157
+ pragma [ only_bind_out ] ( call .getStaticCallTarget ( ) )
158
+ )
159
+ }
0 commit comments