Skip to content

Commit 8c88cbb

Browse files
author
james
committed
docs: address review comments
1 parent 0b31ca4 commit 8c88cbb

20 files changed

+160
-169
lines changed

docs/language/ql-training-rst/_static-training/slides-semmle-2/static/theme/css/default.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,12 @@ article.smaller q:before, article.smaller q:after {
10091009
background-image: -webkit-radial-gradient(50% 50%, #b1dfff 0%, #4387fd 600px);
10101010
background-image: radial-gradient(50% 50%, #b1dfff 0%, #4387fd 600px);
10111011
}
1012+
1013+
/* the popup class is used to display the speaker notes when 'presenter' view
1014+
is enabled. This view is not currently optimal, so certain selectors have been commented-out,
1015+
with a view to improving the styles at a later date */
1016+
1017+
10121018
/* line 684, ../scss/default.scss */
10131019
/*.with-notes.popup slide.next {
10141020
-moz-transform: translate3d(570px, 80px, 0) scale(0.35);

docs/language/ql-training-rst/cpp/bad-overflow-guard.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ For this example you should download:
2424

2525
You can query the project in `the query console <https://lgtm.com/query/project:2034240708/lang:cpp/>`__ on LGTM.com.
2626

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
2832
2933
Checking for overflow in C
3034
==========================

docs/language/ql-training-rst/cpp/control-flow-cpp.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ For this example you should download:
2626

2727
You can query the project in `the query console <https://lgtm.com/query/project:2034240708/lang:cpp/>`__ on LGTM.com.
2828

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.
30+
31+
.. include:: ../slide-snippets/snapshot-note.rst
32+
33+
.. resume slides
3034
3135
3236
.. rst-class:: agenda

docs/language/ql-training-rst/cpp/data-flow-cpp.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ For this example you should download:
2424

2525
You can query the project in `the query console <https://lgtm.com/query/projects:1505958977333/lang:cpp/>`__ on LGTM.com.
2626

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
2832
2933
.. rst-class:: agenda
3034

@@ -112,7 +116,7 @@ We need something better.
112116
113117
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.
114118

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

117121
.. include general data flow slides
118122

docs/language/ql-training-rst/cpp/global-data-flow-cpp.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ For this example you should download:
2424

2525
You can query the project in `the query console <https://lgtm.com/query/projects:1505958977333/lang:cpp/>`__ on LGTM.com.
2626

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
2832
2933
.. rst-class:: agenda
3034

docs/language/ql-training-rst/cpp/intro-ql-cpp.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ For this example you should download:
2424

2525
You can also query the project in `the query console <https://lgtm.com/query/project:1506532406873/lang:cpp/>`__ on LGTM.com.
2626

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
2832
2933
.. Include language-agnostic section here
3034

docs/language/ql-training-rst/cpp/program-representation-cpp.rst

Lines changed: 3 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -19,68 +19,11 @@ Agenda
1919
- Variables
2020
- Functions
2121

22-
Abstract syntax trees
23-
=====================
24-
25-
The basic representation of an analyzed program is an *abstract syntax tree (AST)*.
26-
27-
.. container:: column-left
28-
29-
.. code-block:: cpp
30-
31-
try {
32-
...
33-
} catch (AnException e) {
34-
}
35-
36-
.. container:: ast-graph
37-
38-
.. graphviz::
39-
40-
digraph {
41-
graph [ dpi = 1000 ]
42-
node [shape=polygon,sides=4,color=blue4,style="filled,rounded", fontname=consolas,fontcolor=white]
43-
a [label=<TryStmt>]
44-
b [label=<CatchBlock>]
45-
c [label=<...>,color=white,fontcolor=black]
46-
d [label=<Parameter>]
47-
e [label=<...>,color=white,fontcolor=black]
48-
f [label=<...>,color=white,fontcolor=black]
49-
g [label=<...>,color=white,fontcolor=black]
50-
51-
a -> {b, c}
52-
b -> {d, e}
53-
d -> {f, g}
54-
}
22+
.. insert abstract-syntax-tree.rst
5523
24+
.. include:: ../slide-snippets/abstract-syntax-tree.rst
5625

57-
58-
.. note::
59-
60-
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
8427
8528
AST QL classes
8629
==============
@@ -93,10 +36,6 @@ Important AST classes include:
9336

9437
These three (and all other AST classes) are subclasses of ``Element``.
9538

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-
10039
Symbol table
10140
============
10241

@@ -108,10 +47,6 @@ The database also includes information about the symbol table associated with a
10847

10948
- ``Type``: built-in and user-defined types
11049

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
114-
11550
Working with variables
11651
======================
11752

docs/language/ql-training-rst/cpp/snprintf.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ For this example you should download:
2424

2525
You can also query the project in `the query console <https://lgtm.com/query/project:1506087977050/lang:cpp/>`__ on LGTM.com.
2626

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
2832
2933
``snprintf``
3034
============

docs/language/ql-training-rst/java/apache-struts-java.rst

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,23 @@ For this example you should download:
2828

2929
You can also query the project in `the query console <https://lgtm.com/query/project:1878521151/lang:java/>`__ on LGTM.com.
3030

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
3236
3337
Unsafe deserialization in Struts
3438
================================
3539

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:
3741

3842
.. code-block:: java
3943
4044
void toObject(Reader in, Object target);
4145
4246
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.
4448

4549
RCE in Apache Struts
4650
====================
@@ -85,6 +89,7 @@ Model answer, step 1
8589
import java
8690
8791
/** The interface `org.apache.struts2.rest.handler.ContentTypeHandler`. */
92+
8893
class ContentTypeHandler extends RefType {
8994
ContentTypeHandler() {
9095
this.hasQualifiedName("org.apache.struts2.rest.handler", "ContentTypeHandler")

docs/language/ql-training-rst/java/data-flow-java.rst

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ For this example you should download:
2424

2525
You can also query the project in `the query console <https://lgtm.com/query/project:14040005/lang:java/>`__ on LGTM.com.
2626

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
2832
2933
.. rst-class:: agenda
3034

@@ -54,15 +58,15 @@ Motivation
5458

5559
If you have completed the “Example: Query injection” slide deck which was part of the previous course, this example will look familiar to you.
5660

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:
5862

5963
``“http://vivoweb.org/ontology/core#FacultyMember> ?p ?o . FILTER regex("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!", "(.*a){50}") } #``
6064

6165

6266
Example: SPARQL injection
6367
=========================
6468

65-
We can write a simple query that finds string concatenations that occur in calls SPARQL query APIs.
69+
We can write a simple query that finds string concatenations that occur in calls to SPARQL query APIs.
6670

6771
.. rst-class:: build
6872

@@ -80,7 +84,7 @@ Query finds a CVE reported by Semmle (CVE-2019-6986), plus one other result, but
8084

8185
- String concatenation occurs on a different line in the same method.
8286
- String concatenation occurs in a different method.
83-
- String concatenation occurs through StringBuilders or similar.
87+
- String concatenation occurs through ``StringBuilders`` or similar.
8488
- Entirety of user input is provided as the query.
8589

8690
We want to improve our query to catch more of these cases.

0 commit comments

Comments
 (0)