Skip to content

Commit 500ea12

Browse files
yoffRasmusWL
andauthored
Apply suggestions from code review
Co-authored-by: Rasmus Wriedt Larsen <rasmuswriedtlarsen@gmail.com>
1 parent 09bb300 commit 500ea12

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

python/ql/src/semmle/python/dataflow/new/internal/DataFlowPrivate.qll

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,7 @@ predicate subscriptReadStep(CfgNode nodeFrom, Content c, CfgNode nodeTo) {
10291029
* Note that (CodeQL modeling of) content does not have to change type on data-flow
10301030
* paths _inside_ the LHS, as the different allowed syntaxes here are merely a convenience.
10311031
* Consequently, we model all LHS sequences as tuples, which have the more precise content
1032-
* model, making flow to the elements more precise. If an element is a starred varibale,
1032+
* model, making flow to the elements more precise. If an element is a starred variable,
10331033
* we will have to mutate the content type to be list content.
10341034
*
10351035
* We may for instance have
@@ -1107,6 +1107,33 @@ predicate subscriptReadStep(CfgNode nodeFrom, Content c, CfgNode nodeTo) {
11071107
*
11081108
*
11091109
* We illustrate the above steps on the assignment
1110+
*
1111+
* ```python
1112+
* (a, b) = ["a", SOURCE]
1113+
* ```
1114+
*
1115+
* Looking at the content propagation to `a`:
1116+
* `["a", SOURCE]`: [ListElementContent]
1117+
*
1118+
* --Step 1-->
1119+
*
1120+
* `TIterableSequence((a, b))`: [ListElementContent]
1121+
*
1122+
* --Step 3-->
1123+
*
1124+
* `TIterableElement((a, b))`: []
1125+
*
1126+
* --Step 4-->
1127+
*
1128+
* `(a, b)`: [TupleElementContent(0)]
1129+
*
1130+
* --Step 5c-->
1131+
*
1132+
* `a`: []
1133+
*
1134+
* Meaning there is data-flow from the RHS to `a` (an over approximation). The same logic would be applied to show there is data-flow to `b`. Note that _Step 3_ and _Step 4_ would not have been needed if the RHS had been a tuple (since that would have been able to use _Step 2_ instead).
1135+
*
1136+
* Another, more complicated example:
11101137
* ```python
11111138
* (a, [b, *c]) = ["a", [SOURCE]]
11121139
* ```

0 commit comments

Comments
 (0)