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/language/learn-ql/about-data-flow-analysis.rst
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,17 +14,17 @@ The following sections provide a brief introduction to data flow analysis with C
14
14
15
15
See the following tutorials for more information about analyzing data flow in specific languages:
16
16
17
-
- ":doc:`Analyzing data flow in C/C++ <cpp/dataflow>`"
18
-
- ":doc:`Analyzing data flow in C# <csharp/dataflow>`"
19
-
- ":doc:`Analyzing data flow in Java <java/dataflow>`"
20
-
- ":doc:`Analyzing data flow in JavaScript/TypeScript <javascript/dataflow>`"
21
-
- ":doc:`Analyzing data flow and tracking tainted data in Python <python/taint-tracking>`"
17
+
- ":doc:`Analyzing data flow in C/C++ <cpp/analyzing-data-flow-in-cpp>`"
18
+
- ":doc:`Analyzing data flow in C# <csharp/analyzing-data-flow-in-csharp>`"
19
+
- ":doc:`Analyzing data flow in Java <java/analyzing-data-flow-in-java>`"
20
+
- ":doc:`Analyzing data flow in JavaScript/TypeScript <javascript/analyzing-data-flow-in-javascript>`"
21
+
- ":doc:`Analyzing data flow and tracking tainted data in Python <python/analyzing-data-flow-and-tracking-tainted-data-in-python>`"
22
22
23
23
.. pull-quote::
24
24
25
25
Note
26
26
27
-
Data flow analysis is used extensively in path queries. To learn more about path queries, see ":doc:`Creating path queries <writing-queries/path-queries>`."
27
+
Data flow analysis is used extensively in path queries. To learn more about path queries, see ":doc:`Creating path queries <writing-queries/creating-path-queries>`."
28
28
29
29
.. _data-flow-graph:
30
30
@@ -49,8 +49,8 @@ flow between functions and through object properties. Global data flow, however,
49
49
graph that do not precisely correspond to the flow of values, but model whether some value at runtime may be derived from another, for instance through a string manipulating
50
50
operation.
51
51
52
-
The data flow graph is computed using `classes <https://help.semmle.com/QL/ql-handbook/types.html#classes>`__ to model the program elements that represent the graph's nodes.
53
-
The flow of data between the nodes is modeled using `predicates <https://help.semmle.com/QL/ql-handbook/predicates.html>`__ to compute the graph's edges.
52
+
The data flow graph is computed using `classes <https://help.semmle.com/QL/ql-language-reference/types.html#classes>`__ to model the program elements that represent the graph's nodes.
53
+
The flow of data between the nodes is modeled using `predicates <https://help.semmle.com/QL/ql-language-reference/predicates.html>`__ to compute the graph's edges.
54
54
55
55
Computing an accurate and complete data flow graph presents several challenges:
56
56
@@ -82,5 +82,5 @@ These flow steps are modeled in the taint-tracking library using predicates that
82
82
Further reading
83
83
***************
84
84
85
-
- "`Exploring data flow with path queries <https://help.semmle.com/codeql/codeql-for-vscode/procedures/exploring-paths.html>`__"
85
+
- "`Exploring data flow with path queries <https://help.semmle.com/codeql/codeql-for-vscode/procedures/exploring-data-flow-with-path-queries.html>`__"
Copy file name to clipboardExpand all lines: docs/language/learn-ql/beginner/catch-the-fire-starter.rst
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ Read the examples below to learn how to define predicates and classes in QL. The
14
14
Select the southerners
15
15
----------------------
16
16
17
-
This time you only need to consider a specific group of villagers, namely those living in the south of the village. Instead of writing ``getLocation() = "south"`` in all your queries, you could define a new `predicate <https://help.semmle.com/QL/ql-handbook/predicates.html>`__ ``isSouthern``:
17
+
This time you only need to consider a specific group of villagers, namely those living in the south of the village. Instead of writing ``getLocation() = "south"`` in all your queries, you could define a new `predicate <https://help.semmle.com/QL/ql-language-reference/predicates.html>`__ ``isSouthern``:
18
18
19
19
.. code-block:: ql
20
20
@@ -41,7 +41,7 @@ You can now list all southerners using:
41
41
where isSouthern(p)
42
42
select p
43
43
44
-
This is already a nice way to simplify the logic, but we could be more efficient. Currently, the query looks at every ``Person p``, and then restricts to those who satisfy ``isSouthern(p)``. Instead, we could define a new `class <https://help.semmle.com/QL/ql-handbook/types.html#classes>`__ ``Southerner`` containing precisely the people we want to consider.
44
+
This is already a nice way to simplify the logic, but we could be more efficient. Currently, the query looks at every ``Person p``, and then restricts to those who satisfy ``isSouthern(p)``. Instead, we could define a new `class <https://help.semmle.com/QL/ql-language-reference/types.html#classes>`__ ``Southerner`` containing precisely the people we want to consider.
The result of this predicate is any state that is reachable from the current state (``this``) via
165
165
the given path in a specified finite number of steps.
166
166
167
-
You can write this as a `recursive predicate <https://help.semmle.com/QL/ql-handbook/recursion.html>`__,
167
+
You can write this as a `recursive predicate <https://help.semmle.com/QL/ql-language-reference/recursion.html>`__,
168
168
with the following base case and recursion step:
169
169
170
170
- If ``this`` *is* the result state, then it (trivially) reaches the result state via an
@@ -203,7 +203,7 @@ the given path without revisiting any previously visited states.
203
203
revisiting any previous states, and there is a ``safeFerry`` action from the intermediate state to
204
204
the result state.
205
205
(Hint: To check whether a state has previously been visited, you could check if
206
-
there is an `index of <https://help.semmle.com/QL/ql-spec/language.html#built-ins-for-string>`__
206
+
there is an `index of <ql-language-specification#built-ins-for-string>`__
207
207
``visitedStates`` at which the state occurs.)
208
208
209
209
.. container:: toggle
@@ -218,7 +218,7 @@ the given path without revisiting any previously visited states.
218
218
Display the results
219
219
~~~~~~~~~~~~~~~~~~~
220
220
221
-
Once you've defined all the necessary classes and predicates, write a `select clause <https://help.semmle.com/QL/ql-handbook/queries.html#select-clauses>`__
221
+
Once you've defined all the necessary classes and predicates, write a `select clause <https://help.semmle.com/QL/ql-language-reference/queries.html#select-clauses>`__
222
222
that returns the resulting path.
223
223
224
224
.. container:: toggle
@@ -230,7 +230,7 @@ that returns the resulting path.
230
230
.. literalinclude:: river-crossing.ql
231
231
:lines: 115-117
232
232
233
-
The `don't-care expression <https://help.semmle.com/QL/ql-handbook/expressions.html#don-t-care-expressions>`__ (``_``),
233
+
The `don't-care expression <https://help.semmle.com/QL/ql-language-reference/expressions.html#don-t-care-expressions>`__ (``_``),
234
234
as the second argument to the ``reachesVia`` predicate, represents any value of ``visitedStates``.
235
235
236
236
For now, the path defined in ``reachesVia`` just lists the order of cargo items to ferry.
@@ -254,12 +254,12 @@ Here are some more example queries that solve the river crossing puzzle:
254
254
➤ `See solution in the query console on LGTM.com <https://lgtm.com/query/659603593702729237/>`__
255
255
256
256
#. This query models the man and the cargo items in a different way, using an
Copy file name to clipboardExpand all lines: docs/language/learn-ql/beginner/crown-the-rightful-heir.rst
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -106,7 +106,7 @@ You can translate this into QL as follows:
106
106
result = parentOf(ancestorOf(p))
107
107
}
108
108
109
-
As you can see, you have used the predicate ``ancestorOf()`` inside its own definition. This is an example of `recursion <https://help.semmle.com/QL/ql-handbook/recursion.html>`__.
109
+
As you can see, you have used the predicate ``ancestorOf()`` inside its own definition. This is an example of `recursion <https://help.semmle.com/QL/ql-language-reference/recursion.html>`__.
110
110
111
111
This kind of recursion, where the same operation (in this case ``parentOf()``) is applied multiple times, is very common in QL, and is known as the *transitive closure* of the operation. There are two special symbols ``+`` and ``*`` that are extremely useful when working with transitive closures:
Copy file name to clipboardExpand all lines: docs/language/learn-ql/beginner/find-the-thief.rst
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -48,12 +48,12 @@ There is too much information to search through by hand, so you decide to use yo
48
48
49
49
#. Open the `query console on LGTM.com <https://lgtm.com/query>`__ to get started.
50
50
#. Select a language and a demo project. For this tutorial, any language and project will do.
51
-
#. Delete the default code ``import <language> select "hello world"``.
51
+
#. Delete the default code ``import <ql-language-specification> select "hello world"``.
52
52
53
53
QL libraries
54
54
------------
55
55
56
-
We've defined a number of QL `predicates <https://help.semmle.com/QL/ql-handbook/predicates.html>`__ to help you extract data from your table. A QL predicate is a mini-query that expresses a relation between various pieces of data and describes some of their properties. In this case, the predicates give you information about a person, for example their height or age.
56
+
We've defined a number of QL `predicates <https://help.semmle.com/QL/ql-language-reference/predicates.html>`__ to help you extract data from your table. A QL predicate is a mini-query that expresses a relation between various pieces of data and describes some of their properties. In this case, the predicates give you information about a person, for example their height or age.
@@ -84,14 +84,14 @@ The villagers answered "yes" to the question "Is the thief taller than 150cm?" T
84
84
where t.getHeight() > 150
85
85
select t
86
86
87
-
The first line, ``from Person t``, declares that ``t`` must be a ``Person``. We say that the `type <https://help.semmle.com/QL/ql-handbook/types.html>`__ of ``t`` is ``Person``.
87
+
The first line, ``from Person t``, declares that ``t`` must be a ``Person``. We say that the `type <https://help.semmle.com/QL/ql-language-reference/types.html>`__ of ``t`` is ``Person``.
88
88
89
89
Before you use the rest of your answers in your QL search, here are some more tools and examples to help you write your own QL queries:
90
90
91
91
Logical connectives
92
92
-------------------
93
93
94
-
Using `logical connectives <https://help.semmle.com/QL/ql-handbook/formulas.html#logical-connectives>`__, you can write more complex queries that combine different pieces of information.
94
+
Using `logical connectives <https://help.semmle.com/QL/ql-language-reference/formulas.html#logical-connectives>`__, you can write more complex queries that combine different pieces of information.
95
95
96
96
For example, if you know that the thief is older than 30 *and* has brown hair, you can use the following ``where`` clause to link two predicates:
97
97
@@ -157,7 +157,7 @@ Notice that we have only temporarily introduced the variable ``c`` and we didn't
157
157
158
158
Note
159
159
160
-
If you are familiar with logic, you may notice that ``exists`` in QL corresponds to the existential `quantifier <https://help.semmle.com/QL/ql-handbook/formulas.html#quantified-formulas>`__ in logic. QL also has a universal quantifier ``forall(vars | formula 1 | formula 2)`` which is logically equivalent to ``not exists(vars | formula 1 | not formula 2)``.
160
+
If you are familiar with logic, you may notice that ``exists`` in QL corresponds to the existential `quantifier <https://help.semmle.com/QL/ql-language-reference/formulas.html#quantified-formulas>`__ in logic. QL also has a universal quantifier ``forall(vars | formula 1 | formula 2)`` which is logically equivalent to ``not exists(vars | formula 1 | not formula 2)``.
161
161
162
162
The real investigation
163
163
----------------------
@@ -218,7 +218,7 @@ You are getting closer to solving the mystery! Unfortunately, you still have qui
218
218
More advanced queries
219
219
---------------------
220
220
221
-
What if you want to find the oldest, youngest, tallest, or shortest person in the village? As mentioned in the previous topic, you can do this using ``exists``. However, there is also a more efficient way to do this in QL using functions like ``max`` and ``min``. These are examples of `aggregates <https://help.semmle.com/QL/ql-handbook/expressions.html#aggregations>`__.
221
+
What if you want to find the oldest, youngest, tallest, or shortest person in the village? As mentioned in the previous topic, you can do this using ``exists``. However, there is also a more efficient way to do this in QL using functions like ``max`` and ``min``. These are examples of `aggregates <https://help.semmle.com/QL/ql-language-reference/expressions.html#aggregations>`__.
222
222
223
223
In general, an aggregate is a function that performs an operation on multiple pieces of data and returns a single value as its output. Common aggregates are ``count``, ``max``, ``min``, ``avg`` (average) and ``sum``. The general way to use an aggregate is:
Copy file name to clipboardExpand all lines: docs/language/learn-ql/cpp/analyzing-data-flow-in-cpp.rst
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ You can use data flow analysis to track the flow of potentially malicious or ins
6
6
About data flow
7
7
---------------
8
8
9
-
Data flow analysis computes the possible values that a variable can hold at various points in a program, determining how those values propagate through the program, and where they are used. In CodeQL, you can model both local data flow and global data flow. For a more general introduction to modeling data flow, see ":doc:`About data flow analysis <../intro-to-data-flow>`."
9
+
Data flow analysis computes the possible values that a variable can hold at various points in a program, determining how those values propagate through the program, and where they are used. In CodeQL, you can model both local data flow and global data flow. For a more general introduction to modeling data flow, see ":doc:`About data flow analysis <../about-data-flow-analysis>`."
10
10
11
11
Local data flow
12
12
---------------
@@ -390,7 +390,7 @@ Exercise 4
390
390
Further reading
391
391
---------------
392
392
393
-
- "`Exploring data flow with path queries <https://help.semmle.com/codeql/codeql-for-vscode/procedures/exploring-paths.html>`__"
393
+
- "`Exploring data flow with path queries <https://help.semmle.com/codeql/codeql-for-vscode/procedures/exploring-data-flow-with-path-queries.html>`__"
Experiment and learn how to write effective and efficient queries for CodeQL databases generated from C and C++ codebases.
5
+
6
+
.. toctree::
7
+
:hidden:
8
+
9
+
basic-query-for-cpp-code
10
+
codeql-library-for-cpp
11
+
functions-in-cpp
12
+
expressions-types-and-statements-in-cpp
13
+
conversions-and-classes-in-cpp
14
+
analyzing-data-flow-in-cpp
15
+
refining-a-query-to-account-for-edge-cases
16
+
detecting-a-potential-buffer-overflow
17
+
using-the-guards-library-in-cpp
18
+
using-range-analsis-in-cpp
19
+
hash-consing-and-value-numbering
20
+
21
+
22
+
- :doc:`Basic query for C and C++ code <basic-query-for-cpp-code>`: Learn to write and run a simple CodeQL query using LGTM.
23
+
24
+
- :doc:`CodeQL library for C and C++ <codeql-library-for-cpp>`: When analyzing C or C++ code, you can use the large collection of classes in the CodeQL library for C and C++.
25
+
26
+
- :doc:`Functions in C and C++ <functions-in-cpp>`: You can use CodeQL to explore functions in C and C++ code.
27
+
28
+
- :doc:`Expressions, types, and statements in C and C++ <expressions-types-and-statements-in-cpp>`: You can use CodeQL to explore expressions, types, and statements in C and C++ code to find, for example, incorrect assignments.
29
+
30
+
- :doc:`Conversions and classes in C and C++ <conversions-and-classes-in-cpp>`: You can use the standard CodeQL libraries for C and C++ to detect when the type of an expression is changed.
31
+
32
+
- :doc:`Analyzing data flow in C and C++ <analyzing-data-flow-in-cpp>`: You can use data flow analysis to track the flow of potentially malicious or insecure data that can cause vulnerabilities in your codebase.
33
+
34
+
- :doc:`Refining a query to account for edge cases <refining-a-query-to-account-for-edge-cases>`: You can improve the results generated by a CodeQL query by adding conditions to remove false positive results caused by common edge cases.
35
+
36
+
- :doc:`Detecting a potential buffer overflow <detecting-a-potential-buffer-overflow>`: You can use CodeQL to detect potential buffer overflows by checking for allocations equal to ``strlen`` in C and C++.
37
+
38
+
- :doc:`Using the guards library in C and C++ <using-the-guards-library-in-cpp>`: You can use the CodeQL guards library to identify conditional expressions that control the execution of other parts of a program in C and C++ codebases.
39
+
40
+
- :doc:`Using range analysis for C and C++ <using-range-analsis-in-cpp>`: You can use range analysis to determine the upper or lower bounds on an expression, or whether an expression could potentially over or underflow.
41
+
42
+
- :doc:`Hash consing and value numbering <hash-consing-and-value-numbering>`: You can use specialized CodeQL libraries to recognize expressions that are syntactically identical or compute the same value at runtime in C and C++ codebases.
0 commit comments