Skip to content

Commit e9a0710

Browse files
committed
Rust: address review on docs
1 parent ad3a5d7 commit e9a0710

File tree

3 files changed

+20
-39
lines changed

3 files changed

+20
-39
lines changed

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

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ Using local data flow
2323
~~~~~~~~~~~~~~~~~~~~~
2424

2525
You can use the local data flow library by importing the ``codeql.rust.dataflow.DataFlow`` module. The library uses the class ``Node`` to represent any element through which data can flow.
26-
``Node``\ s are divided into expression nodes (``ExprNode``) and parameter nodes (``ParameterNode``).
27-
You can map a data flow ``ParameterNode`` to its corresponding ``Parameter`` AST node using the ``asParameter`` member predicate.
28-
Similarly, you can use the ``asExpr`` member predicate to map a data flow ``ExprNode`` to its corresponding ``ExprCfgNode`` in the control-flow library.
29-
26+
Common ``Node`` types include expression nodes (``ExprNode``) and parameter nodes (``ParameterNode``).
27+
You can use the ``asExpr`` member predicate to map a data flow ``ExprNode`` to its corresponding ``ExprCfgNode`` in the control-flow library.
28+
Similarly, you can map a data flow ``ParameterNode`` to its corresponding ``Parameter`` AST node using the ``asParameter`` member predicate.
3029
.. code-block:: ql
3130
3231
class Node {
@@ -39,22 +38,8 @@ Similarly, you can use the ``asExpr`` member predicate to map a data flow ``Expr
3938
...
4039
}
4140
42-
You can use the predicates ``exprNode`` and ``parameterNode`` to map from expressions and parameters to their data-flow node:
43-
44-
.. code-block:: ql
45-
46-
/**
47-
* Gets a node corresponding to expression `e`.
48-
*/
49-
ExprNode exprNode(CfgNodes::ExprCfgNode e) { ... }
50-
51-
/**
52-
* Gets the node corresponding to the value of parameter `p` at function entry.
53-
*/
54-
ParameterNode parameterNode(Parameter p) { ... }
55-
56-
Note that since ``asExpr`` and ``exprNode`` map between data-flow and control-flow nodes, you then need to call the ``getExpr`` member predicate on the control-flow node to map to the corresponding AST node,
57-
for example, by writing ``node.asExpr().getExpr()``.
41+
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,
42+
for example by writing ``node.asExpr().getExpr()``.
5843
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.
5944

6045
The predicate ``localFlowStep(Node nodeFrom, Node nodeTo)`` holds if there is an immediate data flow edge from the node ``nodeFrom`` to the node ``nodeTo``.
@@ -207,11 +192,7 @@ The global taint tracking library uses the same configuration module as the glob
207192
Predefined sources
208193
~~~~~~~~~~~~~~~~~~
209194

210-
The data flow library module ``codeql.rust.dataflow.FlowSources`` contains a number of predefined sources that you can use to write security queries to track data flow and taint flow.
211-
212-
- The class ``RemoteFlowSource`` represents data flow from remote network inputs and from other applications.
213-
- The class ``LocalFlowSource`` represents data flow from local user input.
214-
- The class ``FlowSource`` includes both of the above.
195+
The library module ``codeql.rust.Concepts`` contains a number of predefined sources and sinks that you can use to write security queries to track data flow and taint flow.
215196

216197
Examples of global data flow
217198
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -229,16 +210,16 @@ The following global taint-tracking query finds places where a string literal is
229210
import codeql.rust.dataflow.TaintTracking
230211
231212
module ConstantPasswordConfig implements DataFlow::ConfigSig {
232-
predicate isSource(DataFlow::Node node) { node.asExpr().getExpr() instanceof StringLiteralExpr }
233-
234-
predicate isSink(DataFlow::Node node) {
235-
// any argument going to a parameter called `password`
236-
exists(Function f, CallExpr call, int index |
237-
call.getArg(index) = node.asExpr().getExpr() and
238-
call.getStaticTarget() = f and
239-
f.getParam(index).getPat().(IdentPat).getName().getText() = "password"
240-
)
241-
}
213+
predicate isSource(DataFlow::Node node) { node.asExpr().getExpr() instanceof StringLiteralExpr }
214+
215+
predicate isSink(DataFlow::Node node) {
216+
// any argument going to a parameter called `password`
217+
exists(Function f, CallExpr call, int index |
218+
call.getArg(index) = node.asExpr().getExpr() and
219+
call.getStaticTarget() = f and
220+
f.getParam(index).getPat().(IdentPat).getName().getText() = "password"
221+
)
222+
}
242223
}
243224
244225
module ConstantPasswordFlow = TaintTracking::Global<ConstantPasswordConfig>;

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

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

1515
- :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.
16-
- :doc:`Analyzing data flow in Ruby <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.
16+
- :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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ CodeQL ships with a library for analyzing Rust code. The classes in this library
1212
abstractions and predicates to help you with common analysis tasks.
1313

1414
The library is implemented as a set of CodeQL modules, that is, files with the extension ``.qll``. The
15-
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 the complete
16-
library by beginning your query with:
15+
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
16+
by beginning your query with:
1717

1818
.. code-block:: ql
1919
2020
import rust
2121
22-
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,
22+
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
2323
to match syntactic elements in the source code. This can be used for example to find values, patterns and structures.
2424

2525
The control flow graph (CFG) is imported using

0 commit comments

Comments
 (0)