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
+32-10Lines changed: 32 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,12 @@
1
1
.. _analyzing-data-flow-in-cpp-new:
2
2
3
+
.. pull-quote:: Note
4
+
5
+
The data flow library described here is available from CodeQL 2.13.0 onwards. See :ref:`here <analyzing-data-flow-in-cpp>` for the library available in earlier versions.
6
+
3
7
Analyzing data flow in C and C++
4
8
================================
5
9
6
-
:ref:`Data flow <analyzing-data-flow-in-cpp>`
7
-
8
10
You can use data flow analysis to track the flow of potentially malicious or insecure data that can cause vulnerabilities in your codebase.
9
11
10
12
About data flow
@@ -20,27 +22,45 @@ Local data flow is data flow within a single function. Local data flow is usuall
20
22
Using local data flow
21
23
~~~~~~~~~~~~~~~~~~~~~
22
24
23
-
The local data flow library is in the module ``DataFlow``, which defines the class ``Node`` denoting any element that data can flow through. ``Node``\ s are divided into expression nodes (``ExprNode``) and parameter nodes (``ParameterNode``). It is possible to map between data flow nodes and expressions/parameters using the member predicates ``asExpr`` and ``asParameter``:
25
+
The local data flow library is in the module ``DataFlow``, which defines the class ``Node`` denoting any element that data can flow through. ``Node``\ s are divided into expression nodes (``ExprNode``) and parameter nodes (``ParameterNode``). It is possible to map between data flow nodes and expressions/parameters using the member predicates ``asExpr``, ``asIndirectExpr``, and ``asParameter``:
24
26
25
27
.. code-block:: ql
26
28
27
29
class Node {
28
-
/** Gets the expression corresponding to this node, if any. */
30
+
/**
31
+
* Gets the expression corresponding to this node, if any.
32
+
*/
29
33
Expr asExpr() { ... }
30
34
31
-
/** Gets the parameter corresponding to this node, if any. */
35
+
/**
36
+
* Gets the expression corresponding to this node, if any, after dereferencing
37
+
* the expression `index` times.
38
+
*/
39
+
Expr asIndirectExpr(int index) { ... }
40
+
41
+
/**
42
+
* Gets the parameter corresponding to this node, if any.
43
+
*/
32
44
Parameter asParameter() { ... }
33
45
46
+
/**
47
+
* Gets the parameter corresponding to this node, if any, after dereferencing
48
+
* the expression `index` times.
49
+
*/
50
+
Parameter asParameter(int index) { ... }
51
+
34
52
...
35
53
}
36
54
37
55
The predicate ``localFlowStep(Node nodeFrom, Node nodeTo)`` holds if there is an immediate data flow edge from the node ``nodeFrom`` to the node ``nodeTo``. The predicate can be applied recursively (using the ``+`` and ``*`` operators), or through the predefined recursive predicate ``localFlow``, which is equivalent to ``localFlowStep*``.
38
56
39
-
For example, finding flow from a parameter ``source`` to an expression ``sink`` in zero or more local steps can be achieved as follows:
57
+
For example, finding flow from a parameter ``source`` to an expression ``sink`` in zero or more local steps can be achieved as follows, where ``nodeFrom`` and ``nodeTo`` are of type ``DataFlow::Node``:
@@ -56,11 +76,13 @@ In this case, the argument to ``malloc`` is tainted.
56
76
57
77
The local taint tracking library is in the module ``TaintTracking``. Like local data flow, a predicate ``localTaintStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo)`` holds if there is an immediate taint propagation edge from the node ``nodeFrom`` to the node ``nodeTo``. The predicate can be applied recursively (using the ``+`` and ``*`` operators), or through the predefined recursive predicate ``localTaint``, which is equivalent to ``localTaintStep*``.
58
78
59
-
For example, finding taint propagation from a parameter ``source`` to an expression ``sink`` in zero or more local steps can be achieved as follows:
79
+
For example, finding taint propagation from a parameter ``source`` to an expression ``sink`` in zero or more local steps can be achieved as follows, where ``nodeFrom`` and ``nodeTo`` are of type ``DataFlow::Node``:
@@ -77,7 +99,7 @@ The following query finds the filename passed to ``fopen``.
77
99
fc.getTarget() = fopen
78
100
select fc.getArgument(0)
79
101
80
-
Unfortunately, this will only give the expression in the argument, not the values which could be passed to it. So we use local data flow to find all expressions that flow into the argument:
102
+
Unfortunately, this will only give the expression in the argument, not the values which could be passed to it. So we use local data flow to find all expressions that flow into the argument, where we use ``asIndirectExpr(1)`` as we are interested in the value of the string passed to `fopen`, not the pointer pointing to it:
Copy file name to clipboardExpand all lines: docs/codeql/codeql-language-guides/analyzing-data-flow-in-cpp.rst
+4-2Lines changed: 4 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,12 @@
1
1
.. _analyzing-data-flow-in-cpp:
2
2
3
+
.. pull-quote:: Note
4
+
5
+
The data flow library described here will be deprecated in the near future. For the replacement library see :ref:`here <analyzing-data-flow-in-cpp-new>`.
6
+
3
7
Analyzing data flow in C and C++
4
8
================================
5
9
6
-
:ref:`Data flow <analyzing-data-flow-in-cpp-new>`
7
-
8
10
You can use data flow analysis to track the flow of potentially malicious or insecure data that can cause vulnerabilities in your codebase.
0 commit comments