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/ql-training-rst/cpp/bad-overflow-guard.rst
+5-1Lines changed: 5 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,7 +24,11 @@ For this example you should download:
24
24
25
25
You can query the project in `the query console <https://lgtm.com/query/project:2034240708/lang:cpp/>`__ on LGTM.com.
26
26
27
-
Note that results generated in the query console are likely to differ to those generated in the QL plugin as LGTM.com analyzes the most recent revisions of each project that has been added–the snapshot available to download above is based on an historical version of the code base.
27
+
.. insert snapshot-note.rst to explain differences between snapshot available to download and the version available in the query console.
Copy file name to clipboardExpand all lines: docs/language/ql-training-rst/cpp/control-flow-cpp.rst
+5-1Lines changed: 5 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,7 +26,11 @@ For this example you should download:
26
26
27
27
You can query the project in `the query console <https://lgtm.com/query/project:2034240708/lang:cpp/>`__ on LGTM.com.
28
28
29
-
Note that results generated in the query console are likely to differ to those generated in the QL plugin as LGTM.com analyzes the most recent revisions of each project that has been added–the snapshot available to download above is based on an historical version of the code base.
29
+
.. insert snapshot-note.rst to explain differences between snapshot available to download and the version available in the query console.
Copy file name to clipboardExpand all lines: docs/language/ql-training-rst/cpp/data-flow-cpp.rst
+6-2Lines changed: 6 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,7 +24,11 @@ For this example you should download:
24
24
25
25
You can query the project in `the query console <https://lgtm.com/query/projects:1505958977333/lang:cpp/>`__ on LGTM.com.
26
26
27
-
Note that results generated in the query console are likely to differ to those generated in the QL plugin as LGTM.com analyzes the most recent revisions of each project that has been added–the snapshot available to download above is based on an historical version of the code base.
27
+
.. insert snapshot-note.rst to explain differences between snapshot available to download and the version available in the query console.
28
+
29
+
.. include:: ../slide-snippets/snapshot-note.rst
30
+
31
+
.. resume slides
28
32
29
33
.. rst-class:: agenda
30
34
@@ -112,7 +116,7 @@ We need something better.
112
116
113
117
Here, ``DMLOut`` and ``ExtOut`` are macros that expand to formatting calls. The format specifier is not constant, in the sense that the format argument is not a string literal. However, it is clearly one of two possible constants, both with the same number of format specifiers.
114
118
115
-
What we need is a way to determine whether the format argument is ever set to something that is, not constant.
119
+
What we need is a way to determine whether the format argument is ever set to something that is not constant.
Copy file name to clipboardExpand all lines: docs/language/ql-training-rst/cpp/global-data-flow-cpp.rst
+5-1Lines changed: 5 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,7 +24,11 @@ For this example you should download:
24
24
25
25
You can query the project in `the query console <https://lgtm.com/query/projects:1505958977333/lang:cpp/>`__ on LGTM.com.
26
26
27
-
Note that results generated in the query console are likely to differ to those generated in the QL plugin as LGTM.com analyzes the most recent revisions of each project that has been added–the snapshot available to download above is based on an historical version of the code base.
27
+
.. insert snapshot-note.rst to explain differences between snapshot available to download and the version available in the query console.
Copy file name to clipboardExpand all lines: docs/language/ql-training-rst/cpp/intro-ql-cpp.rst
+5-1Lines changed: 5 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,7 +24,11 @@ For this example you should download:
24
24
25
25
You can also query the project in `the query console <https://lgtm.com/query/project:1506532406873/lang:cpp/>`__ on LGTM.com.
26
26
27
-
Note that results generated in the query console are likely to differ to those generated in the QL plugin as LGTM.com analyzes the most recent revisions of each project that has been added–the snapshot available to download above is based on an historical version of the code base.
27
+
.. insert snapshot-note.rst to explain differences between snapshot available to download and the version available in the query console.
When writing queries in QL it is important to have in mind the underlying representation of the program which is stored in the database. Typically queries make use of the “AST” representation of the program–a tree structure where program elements are nested within other program elements.
61
-
62
-
The “Introducing the C/C++ libraries” help topic contains a more complete overview of important AST classes and the rest of the C++ QL libraries: https://help.semmle.com/QL/learn-ql/ql/cpp/introduce-libraries-cpp.html
63
-
64
-
Database representations of ASTs
65
-
================================
66
-
67
-
AST nodes and other program elements are encoded in the database as *entity values*. Entities are implemented as integers, but in QL they are opaque–all one can do with them is to check their equality.
68
-
69
-
Each entity belongs to an entity type. Entity types have names starting with “@” and are defined in the database schema (not in QL).
70
-
71
-
Properties of AST nodes and their relationships to each other are encoded by database relations, which are predicates defined in the database (not in QL).
72
-
73
-
Entity types are rarely used directly, the usual pattern is to define a QL class that extends the type and exposes properties of its entities through member predicates.
74
-
75
-
.. note::
76
-
77
-
ASTs are a typical example of the kind of data representation one finds in object-oriented programming, with data-carrying nodes that reference each other. At first glance, QL, which can only work with atomic values, does not seem to be well suited for working with this kind of data. However, ultimately all that we require of the nodes in an AST is that they have an identity. The relationships among nodes, usually implemented by reference-valued object fields in other languages, can just as well (and arguably more naturally) be represented as relations over nodes. Attaching data (such as strings or numbers) to nodes can also be represented with relations over nodes and primitive values. All we need is a way for relations to reference nodes. This is achieved in QL (as in other database languages) by means of *entity values* (or entities, for short), which are opaque atomic values, implemented as integers under the hood.
78
-
79
-
It is the job of the extractor to create entity values for all AST nodes and populate database relations that encode the relationship between AST nodes and any values associated with them. These relations are *extensional*, that is, explicitly stored in the database, unlike the relations described by QL predicates, which we also refer to as *intensional* relations. Entity values belong to *entity types*, whose name starts with “@” to set them apart from primitive types and classes.
80
-
81
-
The interface between entity types and extensional relations on the one hand and QL predicates and classes on the other hand is provided by the *database schema*, which defines the available entity types and the schema of each extensional relation, that is, how many columns the relation has, and which entity type or primitive type the values in each column come from. QL programs can refer to entity types and extensional relations just as they would refer to QL classes and predicates, with the restriction that entity types cannot be directly selected in a “select” clause, since they do not have a well-defined string representation.
82
-
83
-
For example, the database schema for C++ snapshot databases is here: https://github.com/Semmle/ql/blob/master/cpp/ql/src/semmlecode.cpp.dbscheme
26
+
.. resume slides
84
27
85
28
AST QL classes
86
29
==============
@@ -93,10 +36,6 @@ Important AST classes include:
93
36
94
37
These three (and all other AST classes) are subclasses of ``Element``.
95
38
96
-
.. note::
97
-
98
-
The “Introducing the C/C++ libraries” help topic contains a more complete overview of important AST classes and the rest of the C++ QL libraries: https://help.semmle.com/QL/learn-ql/ql/cpp/introduce-libraries-cpp.html
99
-
100
39
Symbol table
101
40
============
102
41
@@ -108,10 +47,6 @@ The database also includes information about the symbol table associated with a
108
47
109
48
- ``Type``: built-in and user-defined types
110
49
111
-
.. note::
112
-
113
-
The “Introducing the C/C++ libraries” help topic contains a more complete overview of important symbol table classes and the rest of the C++ QL libraries: https://help.semmle.com/QL/learn-ql/ql/cpp/introduce-libraries-cpp.html
Copy file name to clipboardExpand all lines: docs/language/ql-training-rst/cpp/snprintf.rst
+5-1Lines changed: 5 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,7 +24,11 @@ For this example you should download:
24
24
25
25
You can also query the project in `the query console <https://lgtm.com/query/project:1506087977050/lang:cpp/>`__ on LGTM.com.
26
26
27
-
Note that results generated in the query console are likely to differ to those generated in the QL plugin as LGTM.com analyzes the most recent revisions of each project that has been added–the snapshot available to download above is based on an historical version of the code base.
27
+
.. insert snapshot-note.rst to explain differences between snapshot available to download and the version available in the query console.
Copy file name to clipboardExpand all lines: docs/language/ql-training-rst/java/apache-struts-java.rst
+8-3Lines changed: 8 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,19 +28,23 @@ For this example you should download:
28
28
29
29
You can also query the project in `the query console <https://lgtm.com/query/project:1878521151/lang:java/>`__ on LGTM.com.
30
30
31
-
Note that results generated in the query console are likely to differ to those generated in the QL plugin as LGTM.com analyzes the most recent revisions of each project that has been added–the snapshot available to download above is based on an historical version of the code base.
31
+
.. insert snapshot-note.rst to explain differences between snapshot available to download and the version available in the query console.
32
+
33
+
.. include:: ../slide-snippets/snapshot-note.rst
34
+
35
+
.. resume slides
32
36
33
37
Unsafe deserialization in Struts
34
38
================================
35
39
36
-
Apache Struts provides a ContentTypeHandler interface, which can be implemented for specific content types. It defines the following interface method:
40
+
Apache Struts provides a ``ContentTypeHandler`` interface, which can be implemented for specific content types. It defines the following interface method:
37
41
38
42
.. code-block:: java
39
43
40
44
void toObject(Reader in, Object target);
41
45
42
46
43
-
which is intended to populate the “target” object with data from the reader, usually through deserialization. However, the in parameter should be considered untrusted, and should not be deserialized without sanitization.
47
+
which is intended to populate the ``target`` object with data from the reader, usually through deserialization. However, the ``in`` parameter should be considered untrusted, and should not be deserialized without sanitization.
44
48
45
49
RCE in Apache Struts
46
50
====================
@@ -85,6 +89,7 @@ Model answer, step 1
85
89
import java
86
90
87
91
/** The interface `org.apache.struts2.rest.handler.ContentTypeHandler`. */
Copy file name to clipboardExpand all lines: docs/language/ql-training-rst/java/data-flow-java.rst
+8-4Lines changed: 8 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,7 +24,11 @@ For this example you should download:
24
24
25
25
You can also query the project in `the query console <https://lgtm.com/query/project:14040005/lang:java/>`__ on LGTM.com.
26
26
27
-
Note that results generated in the query console are likely to differ to those generated in the QL plugin as LGTM.com analyzes the most recent revisions of each project that has been added–the snapshot available to download above is based on an historical version of the code base.
27
+
.. insert snapshot-note.rst to explain differences between snapshot available to download and the version available in the query console.
28
+
29
+
.. include:: ../slide-snippets/snapshot-note.rst
30
+
31
+
.. resume slides
28
32
29
33
.. rst-class:: agenda
30
34
@@ -54,15 +58,15 @@ Motivation
54
58
55
59
If you have completed the “Example: Query injection” slide deck which was part of the previous course, this example will look familiar to you.
56
60
57
-
To understand the scope of this vulnerability, consider what would happen if a malicious user could provide the following as the content of the individualURI variable:
61
+
To understand the scope of this vulnerability, consider what would happen if a malicious user could provide the following as the content of the ``individualURI`` variable:
0 commit comments