Skip to content

Commit deec067

Browse files
authored
Merge pull request #23270 from yuan2li/docs-java-aliasing
Docs: describe aliasing in the Java data flow guide
2 parents c464772 + 26501b4 commit deec067

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,32 @@ For Java and Kotlin, you can increase the limit from the default of 5 to a maxim
236236

237237
A higher limit can find more flows, but the analysis takes more time and memory.
238238

239+
.. _aliasing-java:
240+
241+
Aliasing
242+
~~~~~~~~
243+
244+
The data flow library does not perform a general alias analysis. When data is stored in a field, the analysis tracks it through the reference used for the store and through references copied from that reference after the store.
245+
246+
The analysis does not track the stored data through a reference copied before the store, even though both references point to the same object. A flow that depends on such an alias is not reported, and no warning is given.
247+
248+
In the following example, the flow to ``sink(b.val)`` is reported, but the flow to ``sink(alias.val)`` is not:
249+
250+
.. code-block:: java
251+
252+
Box b = new Box();
253+
Box alias = b; // copied before the store
254+
b.val = source();
255+
sink(b.val); // reported
256+
sink(alias.val); // not reported
257+
258+
The same applies when:
259+
260+
* The copy is stored in a field before the store.
261+
* The data is stored through the copy and read through the original reference.
262+
263+
If the copy is made after the store, the flow is reported.
264+
239265
Using global taint tracking
240266
~~~~~~~~~~~~~~~~~~~~~~~~~~~
241267

0 commit comments

Comments
 (0)