Skip to content

Commit 9fc84f8

Browse files
author
james
committed
Merge branch 'rc/1.26' into main-126-merge
2 parents b5ef3bd + 7c3ea0e commit 9fc84f8

File tree

93 files changed

+399
-396
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+399
-396
lines changed

docs/language/README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Project structure
1818
The documentation currently consists of the following Sphinx projects:
1919

2020
- ``learn-ql``–help topics to help you learn CodeQL and write queries
21-
- ``ql-handbook``–an overview of important concepts in QL, the language that underlies CodeQL analysis
21+
- ``ql-language-reference``–an overview of important concepts in QL, the language that underlies CodeQL analysis
2222
- ``support``–the languages and frameworks currently supported in CodeQL analysis
2323
- ``ql-training``–source files for the CodeQL training and variant analysis examples slide decks
2424

docs/language/learn-ql/intro-to-data-flow.rst renamed to docs/language/learn-ql/about-data-flow-analysis.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ The following sections provide a brief introduction to data flow analysis with C
1414

1515
See the following tutorials for more information about analyzing data flow in specific languages:
1616

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>`"
2222

2323
.. pull-quote::
2424

2525
Note
2626

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>`."
2828

2929
.. _data-flow-graph:
3030

@@ -49,8 +49,8 @@ flow between functions and through object properties. Global data flow, however,
4949
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
5050
operation.
5151

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.
5454

5555
Computing an accurate and complete data flow graph presents several challenges:
5656

@@ -82,5 +82,5 @@ These flow steps are modeled in the taint-tracking library using predicates that
8282
Further reading
8383
***************
8484

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>`__"
8686

docs/language/learn-ql/beginner/catch-the-fire-starter.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Read the examples below to learn how to define predicates and classes in QL. The
1414
Select the southerners
1515
----------------------
1616

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``:
1818

1919
.. code-block:: ql
2020
@@ -41,7 +41,7 @@ You can now list all southerners using:
4141
where isSouthern(p)
4242
select p
4343
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.
4545

4646
.. code-block:: ql
4747

docs/language/learn-ql/beginner/cross-the-river.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ A solution should be a set of instructions for how to ferry the items, such as "
2020
across the river, and come back with nothing. Then ferry the cabbage across, and come back with ..."
2121

2222
There are lots of ways to approach this problem and implement it in QL. Before you start, make
23-
sure that you are familiar with how to define `classes <https://help.semmle.com/QL/ql-handbook/types.html#classes>`__
24-
and `predicates <https://help.semmle.com/QL/ql-handbook/predicates.html>`__ in QL.
23+
sure that you are familiar with how to define `classes <https://help.semmle.com/QL/ql-language-reference/types.html#classes>`__
24+
and `predicates <https://help.semmle.com/QL/ql-language-reference/predicates.html>`__ in QL.
2525
The following walkthrough is just one of many possible implementations, so have a go at writing your
2626
own query too! To find more example queries, see the list :ref:`below <alternatives>`.
2727

@@ -69,7 +69,7 @@ For example, if the man is on the left shore, the goat on the right shore, and t
6969
shore, the state should be ``Left, Right, Left, Left``.
7070

7171
You may find it helpful to introduce some variables that refer to the shore on which the man and the cargo items are. These
72-
temporary variables in the body of a class are called `fields <https://help.semmle.com/QL/ql-handbook/types.html#fields>`__.
72+
temporary variables in the body of a class are called `fields <https://help.semmle.com/QL/ql-language-reference/types.html#fields>`__.
7373

7474
.. container:: toggle
7575

@@ -159,12 +159,12 @@ could ferry the goat back and forth any number of times without ever reaching an
159159
Such a path would have an infinite number of river crossings without ever solving the puzzle.
160160

161161
One way to restrict our paths to a finite number of river crossings is to define a
162-
`member predicate <https://help.semmle.com/QL/ql-handbook/types.html#member-predicates>`__
162+
`member predicate <https://help.semmle.com/QL/ql-language-reference/types.html#member-predicates>`__
163163
``State reachesVia(string path, int steps)``.
164164
The result of this predicate is any state that is reachable from the current state (``this``) via
165165
the given path in a specified finite number of steps.
166166

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>`__,
168168
with the following base case and recursion step:
169169

170170
- 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.
203203
revisiting any previous states, and there is a ``safeFerry`` action from the intermediate state to
204204
the result state.
205205
(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>`__
207207
``visitedStates`` at which the state occurs.)
208208

209209
.. container:: toggle
@@ -218,7 +218,7 @@ the given path without revisiting any previously visited states.
218218
Display the results
219219
~~~~~~~~~~~~~~~~~~~
220220

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>`__
222222
that returns the resulting path.
223223

224224
.. container:: toggle
@@ -230,7 +230,7 @@ that returns the resulting path.
230230
.. literalinclude:: river-crossing.ql
231231
:lines: 115-117
232232

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>`__ (``_``),
234234
as the second argument to the ``reachesVia`` predicate, represents any value of ``visitedStates``.
235235

236236
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:
254254
➤ `See solution in the query console on LGTM.com <https://lgtm.com/query/659603593702729237/>`__
255255

256256
#. This query models the man and the cargo items in a different way, using an
257-
`abstract <https://help.semmle.com/QL/ql-handbook/annotations.html#abstract>`__
257+
`abstract <https://help.semmle.com/QL/ql-language-reference/annotations.html#abstract>`__
258258
class and predicate. It also displays the resulting path in a more visual way.
259259

260260
➤ `See solution in the query console on LGTM.com <https://lgtm.com/query/1025323464423811143/>`__
261261

262-
#. This query introduces `algebraic datatypes <https://help.semmle.com/QL/ql-handbook/types.html#algebraic-datatypes>`__
262+
#. This query introduces `algebraic datatypes <https://help.semmle.com/QL/ql-language-reference/types.html#algebraic-datatypes>`__
263263
to model the situation, instead of defining everything as a subclass of ``string``.
264264

265265
➤ `See solution in the query console on LGTM.com <https://lgtm.com/query/7260748307619718263/>`__

docs/language/learn-ql/beginner/crown-the-rightful-heir.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ You can translate this into QL as follows:
106106
result = parentOf(ancestorOf(p))
107107
}
108108
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>`__.
110110

111111
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:
112112

docs/language/learn-ql/beginner/find-the-thief.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ There is too much information to search through by hand, so you decide to use yo
4848

4949
#. Open the `query console on LGTM.com <https://lgtm.com/query>`__ to get started.
5050
#. 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"``.
5252

5353
QL libraries
5454
------------
5555

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.
5757

5858
+--------------------+----------------------------------------------------------------------------------------+
5959
| Predicate | Description |
@@ -84,14 +84,14 @@ The villagers answered "yes" to the question "Is the thief taller than 150cm?" T
8484
where t.getHeight() > 150
8585
select t
8686
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``.
8888

8989
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:
9090

9191
Logical connectives
9292
-------------------
9393

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.
9595

9696
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:
9797

@@ -157,7 +157,7 @@ Notice that we have only temporarily introduced the variable ``c`` and we didn't
157157

158158
Note
159159

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)``.
161161

162162
The real investigation
163163
----------------------
@@ -218,7 +218,7 @@ You are getting closer to solving the mystery! Unfortunately, you still have qui
218218
More advanced queries
219219
---------------------
220220

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>`__.
222222

223223
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:
224224

docs/language/learn-ql/cpp/dataflow.rst renamed to docs/language/learn-ql/cpp/analyzing-data-flow-in-cpp.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ You can use data flow analysis to track the flow of potentially malicious or ins
66
About data flow
77
---------------
88

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>`."
1010

1111
Local data flow
1212
---------------
@@ -390,7 +390,7 @@ Exercise 4
390390
Further reading
391391
---------------
392392

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>`__"
394394

395395

396396
.. include:: ../../reusables/cpp-further-reading.rst
File renamed without changes.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
CodeQL for C and C++
2+
====================
3+
4+
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.
File renamed without changes.

0 commit comments

Comments
 (0)