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
`Variant analysis <https://semmle.com/variant-analysis>`__ is the process of using a known vulnerability as a seed to find similar problems in your code. Security engineers typically perform variant analysis to identify possible vulnerabilities and to ensure that these threats are properly fixed across multiple code bases.
8
8
9
-
`QL<https://semmle.com/ql>`__ is Semmle's variant analysis engine, and it is also the technology that underpins LGTM, Semmle's community driven security analysis platform. Together, QL and LGTM provide continuous monitoring and scalable variant analysis for your projects, even if you don’t have your own team of dedicated security engineers. You can read more about using QL and LGTM in variant analysis in the `Semmle blog <https://blog.semmle.com/tags/variant-analysis>`__.
9
+
`CodeQL<https://semmle.com/ql>`__ is the code analysis enginethat underpins LGTM, Semmle's community driven security analysis platform. Together, CodeQL and LGTM provide continuous monitoring and scalable variant analysis for your projects, even if you don’t have your own team of dedicated security engineers. You can read more about using CodeQL and LGTM in variant analysis in the `Semmle blog <https://blog.semmle.com/tags/variant-analysis>`__.
10
10
11
-
The QL language is easy to learn, and exploring code using QL is the most efficient way to perform variant analysis.
11
+
CodeQL is easy to learn, and exploring code using CodeQL is the most efficient way to perform variant analysis.
12
12
13
13
Learning QL for variant analysis
14
-
================================
14
+
--------------------------------
15
15
16
-
Start learning how to use QL in variant analysis for a specific language by looking at the topics below. Each topic links to a short presentation on the QL language, QL libraries, or an example variant discovered using QL.
16
+
Start learning how to use CodeQL in variant analysis for a specific language by looking at the topics below. Each topic links to a short presentation on CodeQL, its libraries, or an example variant discovered using CodeQL.
17
17
18
18
.. |arrow-l| unicode:: U+2190
19
19
@@ -24,43 +24,43 @@ Start learning how to use QL in variant analysis for a specific language by look
24
24
When you have selected a presentation, use |arrow-r| and |arrow-l| to navigate between slides.
25
25
Press **p** to view the additional notes on slides that have an information icon |info| in the top right corner, and press **f** to enter full-screen mode.
26
26
27
-
The presentations contain a number of QL query examples.
27
+
The presentations contain a number of query examples.
28
28
We recommend that you download `QL for Eclipse <https://help.semmle.com/ql-for-eclipse/Content/WebHelp/home-page.html>`__ and import the example snapshot for each presentation so that you can find the bugs mentioned in the slides.
29
29
30
30
31
31
.. pull-quote::
32
32
33
33
Information
34
34
35
-
The presentations listed below are used in QL language and variant analysis training sessions run by Semmle engineers.
35
+
The presentations listed below are used in CodeQL and variant analysis training sessions run by Semmle engineers.
36
36
Therefore, be aware that the slides are designed to be presented by an instructor.
37
37
If you are using the slides without an instructor, please use the additional notes to help guide you through the examples.
38
38
39
-
QL and variant analysis for C/C++
40
-
---------------------------------
39
+
CodeQL and variant analysis for C/C++
40
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
41
41
42
-
- `Introduction to variant analysis: QL for C/C++ <../ql-training/cpp/intro-ql-cpp.html>`__–an introduction to variant analysis and QL for C/C++ programmers.
42
+
- `Introduction to variant analysis: CodeQL for C/C++ <../ql-training/cpp/intro-ql-cpp.html>`__–an introduction to variant analysis and CodeQL for C/C++ programmers.
43
43
- `Example: Bad overflow guard <../ql-training/cpp/bad-overflow-guard.html>`__–an example of iterative query development to find bad overflow guards in a C++ project.
44
-
- `Program representation: QL for C/C++ <../ql-training/cpp/program-representation-cpp.html>`__–information on how QL analysis represents C/C++ programs.
45
-
- `Introduction to local data flow <../ql-training/cpp/data-flow-cpp.html>`__–an introduction to analyzing local data flow in C/C++ using QL, including an example demonstrating how to develop a query to find a real CVE.
44
+
- `Program representation: CodeQL for C/C++ <../ql-training/cpp/program-representation-cpp.html>`__–information on how CodeQL analysis represents C/C++ programs.
45
+
- `Introduction to local data flow <../ql-training/cpp/data-flow-cpp.html>`__–an introduction to analyzing local data flow in C/C++ using CodeQL, including an example demonstrating how to develop a query to find a real CVE.
46
46
- `Exercise: snprintf overflow <../ql-training/cpp/snprintf.html>`__–an example demonstrating how to develop a data flow query.
47
-
- `Introduction to global data flow <../ql-training/cpp/global-data-flow-cpp.html>`__–an introduction to analyzing global data flow in C/C++ using QL.
48
-
- `Analyzing control flow: QL for C/C++ <../ql-training/cpp/control-flow-cpp.html>`__–an introduction to analyzing control flow in C/C++ using QL.
47
+
- `Introduction to global data flow <../ql-training/cpp/global-data-flow-cpp.html>`__–an introduction to analyzing global data flow in C/C++ using CodeQL.
48
+
- `Analyzing control flow: CodeQL for C/C++ <../ql-training/cpp/control-flow-cpp.html>`__–an introduction to analyzing control flow in C/C++ using QL.
49
49
50
-
QL and variant analysis for Java
51
-
--------------------------------
50
+
CodeQL and variant analysis for Java
51
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
52
52
53
-
- `Introduction to variant analysis: QL for Java <../ql-training/java/intro-ql-java.html>`__–an introduction to variant analysis and QL for Java programmers.
53
+
- `Introduction to variant analysis: CodeQL for Java <../ql-training/java/intro-ql-java.html>`__–an introduction to variant analysis and CodeQL for Java programmers.
54
54
- `Example: Query injection <../ql-training/java/query-injection-java.html>`__–an example of iterative query development to find unsanitized SPARQL injections in a Java project.
55
-
- `Program representation: QL for Java <../ql-training/java/program-representation-java.html>`__–information on how QL analysis represents Java programs.
56
-
- `Introduction to local data flow <../ql-training/java/data-flow-java.html>`__–an introduction to analyzing local data flow in Java using QL, including an example demonstrating how to develop a query to find a real CVE.
55
+
- `Program representation: CodeQL for Java <../ql-training/java/program-representation-java.html>`__–information on how CodeQL analysis represents Java programs.
56
+
- `Introduction to local data flow <../ql-training/java/data-flow-java.html>`__–an introduction to analyzing local data flow in Java using CodeQL, including an example demonstrating how to develop a query to find a real CVE.
57
57
- `Exercise: Apache Struts <../ql-training/java/apache-struts-java.html>`__–an example demonstrating how to develop a data flow query.
58
-
- `Introduction to global data flow <../ql-training/java/global-data-flow-java.html>`__–an introduction to analyzing global data flow in Java using QL.
58
+
- `Introduction to global data flow <../ql-training/java/global-data-flow-java.html>`__–an introduction to analyzing global data flow in Java using CodeQL.
59
59
60
60
More resources
61
-
--------------
61
+
~~~~~~~~~~~~~~
62
62
63
-
- If you are completely new to QL, look at our introductory topics in :ref:`Getting started <getting-started>`.
64
-
- To find more detailed information about how to write QL queries for specific languages, visit the links in :ref:`Writing QL queries <writing-ql-queries>`.
65
-
- To read more about how QL queries have been used in Semmle's security research, and to read about new QL developments, visit the `Semmle blog <https://blog.semmle.com>`__.
63
+
- If you are completely new to CodeQL, look at our introductory topics in :doc:`Learning CodeQL <index>`.
64
+
- To find more detailed information about how to write CodeQL queries for specific languages, visit the links in :ref:`Writing CodeQL queries <writing-ql-queries>`.
65
+
- To read more about how CodeQL queries have been used in Semmle's security research, and to read about new CodeQL developments, visit the `Semmle blog <https://blog.semmle.com>`__.
66
66
- Find more examples of queries written by Semmle's own security researchers in the `Semmle Demos repository <https://github.com/semmle/demos>`__ on GitHub.
Copy file name to clipboardExpand all lines: docs/language/ql-training/cpp/bad-overflow-guard.rst
+12-12Lines changed: 12 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
Example: Bad overflow guard
3
3
===========================
4
4
5
-
QL for C/C++
5
+
CodeQL for C/C++
6
6
7
7
.. container:: semmle-logo
8
8
@@ -127,13 +127,13 @@ This happens even though the overflow check passed!
127
127
128
128
.. rst-class:: background2
129
129
130
-
Developing a QL query
131
-
=====================
130
+
Developing a CodeQL query
131
+
=========================
132
132
133
133
Finding bad overflow guards
134
134
135
-
QL query: bad overflow guards
136
-
=============================
135
+
CodeQL query: bad overflow guards
136
+
==================================
137
137
138
138
Let’s look for overflow guards of the form ``v + b < v``, using the classes
139
139
``AddExpr``, ``Variable`` and ``RelationalOperation`` from the ``cpp`` library.
@@ -153,10 +153,10 @@ Let’s look for overflow guards of the form ``v + b < v``, using the classes
153
153
- a ``RelationalOperation``: the overflow comparison check.
154
154
- a ``Variable``: used as an argument to both the addition and comparison.
155
155
156
-
- The ``where`` part of the query ties these three QL variables together using `predicates <https://help.semmle.com/QL/ql-handbook/predicates.html>`__ defined in the `standard QL for C/C++ library <https://help.semmle.com/qldoc/cpp/>`__.
156
+
- The ``where`` part of the query ties these three variables together using `predicates <https://help.semmle.com/QL/ql-handbook/predicates.html>`__ defined in the `standard CodeQL for C/C++ library <https://help.semmle.com/qldoc/cpp/>`__.
157
157
158
-
QL query: bad overflow guards
159
-
=============================
158
+
CodeQL query: bad overflow guards
159
+
=================================
160
160
161
161
We want to ensure the operands being added have size less than 4 bytes.
162
162
@@ -180,8 +180,8 @@ We can get the size (in bytes) of a type using the ``getSize()`` method.
180
180
- We therefore write a helper predicate for small expressions.
181
181
- This predicate effectively represents the set of all expressions in the database where the size of the type of the expression is less than 4 bytes, that is, less than 32-bits.
182
182
183
-
QL query: bad overflow guards
184
-
=============================
183
+
CodeQL query: bad overflow guards
184
+
==================================
185
185
186
186
We can ensure the operands being added have size less than 4 bytes, using our new predicate.
187
187
@@ -216,8 +216,8 @@ Now our query becomes:
216
216
- The “range” part, ``op = a.getAnOperand()``, restricts ``op`` to being one of the two operands to the addition.
217
217
- The “condition” part, ``isSmall(op)``, says that the ``forall`` holds only if the condition (that the ``op`` is small) holds for everything in the range–that is, both the arguments to the addition.
218
218
219
-
QL query: bad overflow guards
220
-
=============================
219
+
CodeQL query: bad overflow guards
220
+
=================================
221
221
222
222
Sometimes the result of the addition is cast to a small type of size less than 4 bytes, preventing automatic widening. We don’t want our query to flag these instances.
Copy file name to clipboardExpand all lines: docs/language/ql-training/cpp/data-flow-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
@@ -86,9 +86,9 @@ Write a query that flags ``printf`` calls where the format argument is not a ``S
86
86
87
87
.. note::
88
88
89
-
This first query is about finding places where the format specifier is not a constant string. In QL for C/C++, constant strings are modeled as ``StringLiteral`` nodes, so we are looking for calls to format functions where the format specifier argument is not a string literal.
89
+
This first query is about finding places where the format specifier is not a constant string. In CodeQL for C/C++, constant strings are modeled as ``StringLiteral`` nodes, so we are looking for calls to format functions where the format specifier argument is not a string literal.
90
90
91
-
The `C/C++ standard libraries <https://help.semmle.com/qldoc/cpp/>`__ include many different formatting functions that may be vulnerable to this particular attack–including ``printf``, ``snprintf``, and others. Furthermore, each of these different formatting functions may include the format string in a different position in the argument list. Instead of laboriously listing all these different variants, we can make use of the QL for C/C++ standard library class ``FormattingFunction``, which provides an interface that models common formatting functions in C/C++.
91
+
The `C/C++ standard libraries <https://help.semmle.com/qldoc/cpp/>`__ include many different formatting functions that may be vulnerable to this particular attack–including ``printf``, ``snprintf``, and others. Furthermore, each of these different formatting functions may include the format string in a different position in the argument list. Instead of laboriously listing all these different variants, we can make use of the CodeQL for C/C++ standard library class ``FormattingFunction``, which provides an interface that models common formatting functions in C/C++.
Copy file name to clipboardExpand all lines: docs/language/ql-training/cpp/global-data-flow-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
@@ -2,7 +2,7 @@
2
2
Introduction to global data flow
3
3
================================
4
4
5
-
QL for C/C++
5
+
CodeQL for C/C++
6
6
7
7
.. container:: semmle-logo
8
8
@@ -77,7 +77,7 @@ The library class ``SecurityOptions`` provides a (configurable) model of what co
77
77
78
78
.. note::
79
79
80
-
We first define what it means to be a *source* of tainted data for this particular problem. In this case, what we care about is whether the format string can be provided by an external user to our application or service. As there are many such ways external data could be introduced into the system, the standard QL libraries for C/C++ include an extensible API for modeling user input. In this case, we will simply use the predefined set of *user inputs*, which includes arguments provided to command line applications.
80
+
We first define what it means to be a *source* of tainted data for this particular problem. In this case, what we care about is whether the format string can be provided by an external user to our application or service. As there are many such ways external data could be introduced into the system, the standard CodeQL libraries for C/C++ include an extensible API for modeling user input. In this case, we will simply use the predefined set of *user inputs*, which includes arguments provided to command line applications.
0 commit comments