Skip to content

Commit a3de138

Browse files
authored
Merge pull request github#18511 from owen-mc/go/docs/data-flow
Update documentation on data flow in Go (and some small fixes for java)
2 parents ed3ad1a + da86668 commit a3de138

13 files changed

+414
-290
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ Global data flow tracks data flow throughout the entire program, and is therefor
172172
Using global data flow
173173
~~~~~~~~~~~~~~~~~~~~~~
174174

175-
The global data flow library is used by implementing the signature ``DataFlow::ConfigSig`` and applying the module ``DataFlow::Global<ConfigSig>`` as follows:
175+
We can use the global data flow library by implementing the signature ``DataFlow::ConfigSig`` and applying the module ``DataFlow::Global<ConfigSig>``:
176176

177177
.. code-block:: ql
178178
@@ -314,7 +314,7 @@ Exercise 2: Write a query that finds all hard-coded strings used to create a ``h
314314

315315
Exercise 3: Write a class that represents flow sources from ``getenv``. (`Answer <#exercise-3>`__)
316316

317-
Exercise 4: Using the answers from 2 and 3, write a query which finds all global data flows from ``getenv`` to ``gethostbyname``. (`Answer <#exercise-4>`__)
317+
Exercise 4: Using the answers from 2 and 3, write a query which finds all global data flow paths from ``getenv`` to ``gethostbyname``. (`Answer <#exercise-4>`__)
318318

319319
Answers
320320
-------

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ Local taint tracking extends local data flow by including non-value-preserving f
6565

6666
.. code-block:: csharp
6767
68-
var temp = x;
69-
var y = temp + ", " + temp;
68+
var y = "Hello " + x;
7069
7170
If ``x`` is a tainted string then ``y`` is also tainted.
7271

@@ -104,7 +103,7 @@ Unfortunately this will only give the expression in the argument, not the values
104103
and DataFlow::localFlow(DataFlow::exprNode(src), DataFlow::exprNode(call.getArgument(0)))
105104
select src
106105
107-
Then we can make the source more specific, for example an access to a public parameter. This query finds instances where a public parameter is used to open a file:
106+
To restrict sources to only an access to a public parameter, rather than arbitrary expressions, we can modify this query as follows:
108107

109108
.. code-block:: ql
110109
@@ -117,7 +116,7 @@ Then we can make the source more specific, for example an access to a public par
117116
and call.getEnclosingCallable().(Member).isPublic()
118117
select p, "Opening a file from a public method."
119118
120-
This query finds calls to ``String.Format`` where the format string isn't hard-coded:
119+
The following query finds calls to ``String.Format`` where the format string isn't hard-coded:
121120

122121
.. code-block:: ql
123122
@@ -148,7 +147,7 @@ Global data flow tracks data flow throughout the entire program, and is therefor
148147
Using global data flow
149148
~~~~~~~~~~~~~~~~~~~~~~
150149

151-
The global data flow library is used by implementing the signature ``DataFlow::ConfigSig`` and applying the module ``DataFlow::Global<ConfigSig>``:
150+
We can use the global data flow library by implementing the signature ``DataFlow::ConfigSig`` and applying the module ``DataFlow::Global<ConfigSig>``:
152151

153152
.. code-block:: ql
154153
@@ -170,8 +169,8 @@ These predicates are defined in the configuration:
170169

171170
- ``isSource`` - defines where data may flow from.
172171
- ``isSink`` - defines where data may flow to.
173-
- ``isBarrier`` - optionally, restricts the data flow.
174-
- ``isAdditionalFlowStep`` - optionally, adds additional flow steps.
172+
- ``isBarrier`` - optional, defines where data flow is blocked.
173+
- ``isAdditionalFlowStep`` - optional, adds additional flow steps.
175174

176175
The data flow analysis is performed using the predicate ``flow(DataFlow::Node source, DataFlow::Node sink)``:
177176

@@ -288,7 +287,7 @@ Exercise 2: Find all hard-coded strings passed to ``System.Uri``, using global d
288287

289288
Exercise 3: Define a class that represents flow sources from ``System.Environment.GetEnvironmentVariable``. (`Answer <#exercise-3>`__)
290289

291-
Exercise 4: Using the answers from 2 and 3, write a query to find all global data flow from ``System.Environment.GetEnvironmentVariable`` to ``System.Uri``. (`Answer <#exercise-4>`__)
290+
Exercise 4: Using the answers from 2 and 3, write a query which finds all global data flow paths from ``System.Environment.GetEnvironmentVariable`` to ``System.Uri``. (`Answer <#exercise-4>`__)
292291

293292
Extending library data flow
294293
---------------------------

0 commit comments

Comments
 (0)