Skip to content

Commit 9c06a82

Browse files
redsun82sunbrye
andauthored
Rust: apply suggestions from code review
Co-authored-by: Sunbrye Ly <56200261+sunbrye@users.noreply.github.com>
1 parent f812b64 commit 9c06a82

File tree

3 files changed

+23
-26
lines changed

3 files changed

+23
-26
lines changed

docs/codeql/codeql-language-guides/analyzing-data-flow-in-rust.rst

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ For a more general introduction to modeling data flow, see ":ref:`About data flo
1717
Local data flow
1818
---------------
1919

20-
Local data flow tracks the flow of data within a single method or callable. Local data flow is easier, faster, and more precise than global data flow. Before looking at more complex tracking, you should always consider local tracking because it is sufficient for many queries.
20+
Local data flow tracks the flow of data within a single method or callable. Local data flow is easier, faster, and more precise than global data flow. Before using more complex tracking, consider local tracking, as it is sufficient for many queries.
2121

2222
Using local data flow
2323
~~~~~~~~~~~~~~~~~~~~~
@@ -43,13 +43,11 @@ Similarly, you can map a data flow ``ParameterNode`` to its corresponding ``Para
4343
...
4444
}
4545
46-
47-
Note that since ``asExpr`` maps from data-flow to control-flow nodes, you then need to call the ``getExpr`` member predicate on the control-flow node to map to the corresponding AST node,
48-
for example by writing ``node.asExpr().getExpr()``.
46+
Note that because ``asExpr`` maps from data-flow to control-flow nodes, you need to call the ``getExpr`` member predicate on the control-flow node to map to the corresponding AST node. For example, you can write ``node.asExpr().getExpr()``.
4947
A control-flow graph considers every way control can flow through code, consequently, there can be multiple data-flow and control-flow nodes associated with a single expression node in the AST.
5048

5149
The predicate ``localFlowStep(Node nodeFrom, Node nodeTo)`` holds if there is an immediate data flow edge from the node ``nodeFrom`` to the node ``nodeTo``.
52-
You can apply the predicate recursively, by using the ``+`` and ``*`` operators, or you can use the predefined recursive predicate ``localFlow``.
50+
You can apply the predicate recursively by using the ``+`` and ``*`` operators, or you can use the predefined recursive predicate ``localFlow``.
5351

5452
For example, you can find flow from an expression ``source`` to an expression ``sink`` in zero or more local steps:
5553

@@ -71,7 +69,7 @@ If ``x`` is a tainted string then ``y`` is also tainted.
7169

7270
The local taint tracking library is in the module ``TaintTracking``.
7371
Like local data flow, a predicate ``localTaintStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo)`` holds if there is an immediate taint propagation edge from the node ``nodeFrom`` to the node ``nodeTo``.
74-
You can apply the predicate recursively, by using the ``+`` and ``*`` operators, or you can use the predefined recursive predicate ``localTaint``.
72+
You can apply the predicate recursively by using the ``+`` and ``*`` operators, or you can use the predefined recursive predicate ``localTaint``.
7573

7674
For example, you can find taint propagation from an expression ``source`` to an expression ``sink`` in zero or more local steps:
7775

@@ -83,14 +81,14 @@ For example, you can find taint propagation from an expression ``source`` to an
8381
Using local sources
8482
~~~~~~~~~~~~~~~~~~~
8583

86-
When exploring local data flow or taint propagation between two expressions as above, you would normally constrain the expressions to be relevant to your investigation.
87-
The next section gives some concrete examples, but first it's helpful to introduce the concept of a local source.
84+
When exploring local data flow or taint propagation between two expressions, such as in the previous example, you typically constrain the expressions to those relevant to your investigation.
85+
The next section provides concrete examples, but first introduces the concept of a local source.
8886

8987
A local source is a data-flow node with no local data flow into it.
90-
As such, it is a local origin of data flow, a place where a new value is created.
88+
It is a local origin of data flow, a place where a new value is created.
9189
This includes parameters (which only receive values from global data flow) and most expressions (because they are not value-preserving).
9290
The class ``LocalSourceNode`` represents data-flow nodes that are also local sources.
93-
It comes with a useful member predicate ``flowsTo(DataFlow::Node node)``, which holds if there is local data flow from the local source to ``node``.
91+
It includes a useful member predicate ``flowsTo(DataFlow::Node node)``, which holds if there is local data flow from the local source to ``node``.
9492

9593
Examples of local data flow
9694
~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -105,8 +103,7 @@ This query finds the argument passed in each call to ``File::create``:
105103
where call.getStaticTarget().(Function).getCanonicalPath() = "<std::fs::File>::create"
106104
select call.getArg(0)
107105
108-
Unfortunately this will only give the expression in the argument, not the values which could be passed to it.
109-
So we use local data flow to find all expressions that flow into the argument:
106+
Unfortunately, this only returns the expression used as the argument, not the possible values that could be passed to it. To address this, you can use local data flow to find all expressions that flow into the argument.
110107

111108
.. code-block:: ql
112109
@@ -120,7 +117,7 @@ So we use local data flow to find all expressions that flow into the argument:
120117
DataFlow::localFlow(source, sink)
121118
select source, sink
122119
123-
We can vary the source, for example, making the source the parameter of a function rather than an expression. The following query finds where a parameter is used for the file creation:
120+
You can vary the source by making the source the parameter of a function instead of an expression. The following query finds where a parameter is used in file creation:
124121

125122
.. code-block:: ql
126123
@@ -183,8 +180,8 @@ The last line (``module MyDataFlow = ...``) instantiates the parameterized modul
183180
Using global taint tracking
184181
~~~~~~~~~~~~~~~~~~~~~~~~~~~
185182

186-
Global taint tracking is to global data flow what local taint tracking is to local data flow.
187-
That is, global taint tracking extends global data flow with additional non-value-preserving steps.
183+
Global taint tracking relates to global data flow in the same way that local taint tracking relates to local data flow.
184+
In other words, global taint tracking extends global data flow with additional non-value-preserving steps.
188185
The global taint tracking library uses the same configuration module as the global data flow library. You can perform taint flow analysis using ``TaintTracking::Global``:
189186

190187
.. code-block:: ql
@@ -207,7 +204,7 @@ The following global taint-tracking query finds places where a string literal is
207204
- Since this is a taint-tracking query, the ``TaintTracking::Global`` module is used.
208205
- The ``isSource`` predicate defines sources as any ``StringLiteralExpr``.
209206
- The ``isSink`` predicate defines sinks as arguments to a ``CallExpr`` called "password".
210-
- The sources and sinks may need tuning to a particular use, for example, if passwords are represented by a type other than ``String`` or passed in arguments of a different name than "password".
207+
- The sources and sinks may need to be adjusted for a particular use. For example, passwords might be represented by a type other than ``String`` or passed in arguments with a different name than "password".
211208

212209
.. code-block:: ql
213210

docs/codeql/codeql-language-guides/codeql-for-rust.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ Experiment and learn how to write effective and efficient queries for CodeQL dat
1212
codeql-library-for-rust
1313
analyzing-data-flow-in-rust
1414

15-
- :doc:`CodeQL library for Rust <codeql-library-for-rust>`: When you're analyzing Rust code, you can make use of the large collection of classes in the CodeQL library for Rust.
15+
- :doc:`CodeQL library for Rust <codeql-library-for-rust>`: When analyzing Rust code, you can make use of the large collection of classes in the CodeQL library for Rust.
1616
- :doc:`Analyzing data flow in Rust <analyzing-data-flow-in-rust>`: You can use CodeQL to track the flow of data through a Rust program to places where the data is used.

docs/codeql/codeql-language-guides/codeql-library-for-rust.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
CodeQL library for Rust
44
=================================
55

6-
When you're analyzing Rust code, you can make use of the large collection of classes in the CodeQL library for Rust.
6+
When analyzing Rust code, you can make use of the large collection of classes in the CodeQL library for Rust.
77

88
Overview
99
--------
1010

1111
CodeQL ships with a library for analyzing Rust code. The classes in this library present the data from a CodeQL database in an object-oriented form and provide
1212
abstractions and predicates to help you with common analysis tasks.
1313

14-
The library is implemented as a set of CodeQL modules, that is, files with the extension ``.qll``. The
14+
The library is implemented as a set of CodeQL modules, which are files with the extension ``.qll``. The
1515
module `rust.qll <https://github.com/github/codeql/blob/main/rust/ql/lib/rust.qll>`__ imports most other standard library modules, so you can include them
1616
by beginning your query with:
1717

@@ -20,27 +20,27 @@ by beginning your query with:
2020
import rust
2121
2222
The CodeQL libraries model various aspects of Rust code. The above import includes the abstract syntax tree (AST) library, which is used for locating program elements
23-
to match syntactic elements in the source code. This can be used for example to find values, patterns and structures.
23+
to match syntactic elements in the source code. This can be used to find values, patterns, and structures.
2424

25-
The control flow graph (CFG) is imported using
25+
The control flow graph (CFG) is imported using:
2626

2727
.. code-block:: ql
2828
2929
import codeql.rust.controlflow.ControlFlowGraph
3030
31-
The CFG models the control flow between statements and expressions, for example whether one expression can
31+
The CFG models the control flow between statements and expressions. For example, it can determine whether one expression can
3232
be evaluated before another expression, or whether an expression "dominates" another one, meaning that all paths to an
3333
expression must flow through another expression first.
3434

35-
The data flow library is imported using
35+
The data flow library is imported using:
3636

3737
.. code-block:: ql
3838
3939
import codeql.rust.dataflow.DataFlow
4040
41-
Data flow tracks the flow of data through the program, including through function calls (interprocedural data flow) and between steps in a job or workflow.
42-
Data flow is particularly useful for security queries, where untrusted data flows to vulnerable parts of the program. Related to data flow is the taint-tracking library,
43-
which finds how data can *influence* other values in a program, even when it is not copied exactly.
41+
Data flow tracks the flow of data through the program, including across function calls (interprocedural data flow) and between steps in a job or workflow.
42+
Data flow is particularly useful for security queries, where untrusted data flows to vulnerable parts of the program. The taint-tracking library is related to data flow,
43+
and helps you find how data can *influence* other values in a program, even when it is not copied exactly.
4444

4545
To summarize, the main Rust library modules are:
4646

0 commit comments

Comments
 (0)