You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/codeql/codeql-language-guides/analyzing-data-flow-in-cpp-new.rst
+47-63Lines changed: 47 additions & 63 deletions
Original file line number
Diff line number
Diff line change
@@ -168,74 +168,61 @@ Global data flow tracks data flow throughout the entire program, and is therefor
168
168
Using global data flow
169
169
~~~~~~~~~~~~~~~~~~~~~~
170
170
171
-
The global data flow library is used by extending the class ``DataFlow::Configuration`` as follows:
171
+
The global data flow library is used by implementing the signature ``DataFlow::ConfigSig`` and applying the module ``DataFlow::Global<ConfigSig>`` as follows:
172
172
173
173
.. code-block:: ql
174
174
175
175
import semmle.code.cpp.dataflow.new.DataFlow
176
176
177
-
class MyDataFlowConfiguration extends DataFlow::Configuration {
178
-
MyDataFlowConfiguration() { this = "MyDataFlowConfiguration" }
The characteristic predicate ``MyDataFlowConfiguration()`` defines the name of the configuration, so ``"MyDataFlowConfiguration"`` should be replaced by the name of your class.
198
-
199
-
The data flow analysis is performed using the predicate ``hasFlow(DataFlow::Node source, DataFlow::Node sink)``:
196
+
The data flow analysis is performed using the predicate ``flow(DataFlow::Node source, DataFlow::Node sink)``:
200
197
201
198
.. code-block:: ql
202
199
203
-
from MyDataFlowConfiguration dataflow, DataFlow::Node source, DataFlow::Node sink
204
-
where dataflow.hasFlow(source, sink)
200
+
from DataFlow::Node source, DataFlow::Node sink
201
+
where MyFlow::flow(source, sink)
205
202
select source, "Data flow to $@.", sink, sink.toString()
206
203
207
204
Using global taint tracking
208
205
~~~~~~~~~~~~~~~~~~~~~~~~~~~
209
206
210
-
Global taint tracking is to global data flow as local taint tracking is to local data flow. That is, global taint tracking extends global data flow with additional non-value-preserving steps. The global taint tracking library is used by extending the class ``TaintTracking::Configuration`` as follows:
207
+
Global taint tracking is to global data flow as local taint tracking is to local data flow. That is, global taint tracking extends global data flow with additional non-value-preserving steps. The global taint tracking library is used by applying the module ``TaintTracking::Global<ConfigSig>`` to your configuration instead of ``DataFlow::Global<ConfigSig>`` as follows:
211
208
212
209
.. code-block:: ql
213
210
214
211
import semmle.code.cpp.dataflow.new.TaintTracking
215
212
216
-
class MyTaintTrackingConfiguration extends TaintTracking::Configuration {
217
-
MyTaintTrackingConfiguration() { this = "MyTaintTrackingConfiguration" }
Similar to global data flow, the characteristic predicate ``MyTaintTrackingConfiguration()`` defines the unique name of the configuration, so ``"MyTaintTrackingConfiguration"`` should be replaced by the name of your class.
237
-
238
-
The taint tracking analysis is performed using the predicate ``hasFlow(DataFlow::Node source, DataFlow::Node sink)``.
225
+
The resulting module is completely similar to the one obtained from ``DataFlow::Global<ConfigSig>``.
239
226
240
227
Examples
241
228
~~~~~~~~
@@ -247,53 +234,50 @@ The following data flow configuration tracks data flow from environment variable
247
234
import cpp
248
235
import semmle.code.cpp.dataflow.new.DataFlow
249
236
250
-
class EnvironmentToFileConfiguration extends DataFlow::Configuration {
251
-
EnvironmentToFileConfiguration() { this = "EnvironmentToFileConfiguration" }
select fopen, "This 'fopen' uses data from $@.", getenv, "call to 'getenv'"
276
262
277
-
The following taint-tracking configuration tracks data from a call to ``ntohl`` to an array index operation. It uses the ``Guards`` library to recognize expressions that have been bounds-checked, and defines ``isSanitizer`` to prevent taint from propagating through them. It also uses ``isAdditionalTaintStep`` to add flow from loop bounds to loop indexes.
263
+
The following taint-tracking configuration tracks data from a call to ``ntohl`` to an array index operation. It uses the ``Guards`` library to recognize expressions that have been bounds-checked, and defines ``isBarrier`` to prevent taint from propagating through them. It also uses ``isAdditionalFlowStep`` to add flow from loop bounds to loop indexes.
278
264
279
265
.. code-block:: ql
280
266
281
267
import cpp
282
268
import semmle.code.cpp.controlflow.Guards
283
269
import semmle.code.cpp.dataflow.new.TaintTracking
284
270
285
-
class NetworkToBufferSizeConfiguration extends TaintTracking::Configuration {
286
-
NetworkToBufferSizeConfiguration() { this = "NetworkToBufferSizeConfiguration" }
0 commit comments