Skip to content

Commit b6f94ea

Browse files
committed
C#: Add example test of field flow via the spread operator, which leads to a false positive.
1 parent cd5f678 commit b6f94ea

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

csharp/ql/test/library-tests/dataflow/collections/CollectionFlow.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,4 +473,12 @@ public static class IntegerCollectionBuilder
473473
public static IntegerCollection Create(ReadOnlySpan<int> elements)
474474
=> new IntegerCollection(elements);
475475
}
476+
477+
public void CollectionExpressionSpreadElementNoFieldFlow()
478+
{
479+
IntegerCollection ic0 = [0];
480+
ic0.Payload = new A();
481+
IntegerCollection ic1 = [.. ic0];
482+
Sink(ic1.Payload); // No flow
483+
}
476484
}

csharp/ql/test/library-tests/dataflow/collections/CollectionFlow.expected

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,9 @@ edges
245245
| CollectionFlow.cs:448:20:448:22 | [...] : A[] [element] : A | CollectionFlow.cs:450:14:450:18 | access to local variable array : A[] [element] : A |
246246
| CollectionFlow.cs:448:21:448:21 | access to local variable a : A | CollectionFlow.cs:448:20:448:22 | [...] : A[] [element] : A |
247247
| CollectionFlow.cs:450:14:450:18 | access to local variable array : A[] [element] : A | CollectionFlow.cs:450:14:450:21 | access to array element |
248+
| CollectionFlow.cs:480:9:480:11 | [post] access to local variable ic0 : IntegerCollection [property Payload] : A | CollectionFlow.cs:482:14:482:16 | access to local variable ic1 : IntegerCollection [property Payload] : A |
249+
| CollectionFlow.cs:480:23:480:29 | object creation of type A : A | CollectionFlow.cs:480:9:480:11 | [post] access to local variable ic0 : IntegerCollection [property Payload] : A |
250+
| CollectionFlow.cs:482:14:482:16 | access to local variable ic1 : IntegerCollection [property Payload] : A | CollectionFlow.cs:482:14:482:24 | access to property Payload |
248251
nodes
249252
| CollectionFlow.cs:14:40:14:41 | ts : A[] [element] : A | semmle.label | ts : A[] [element] : A |
250253
| CollectionFlow.cs:14:40:14:41 | ts : null [element] : A | semmle.label | ts : null [element] : A |
@@ -495,6 +498,10 @@ nodes
495498
| CollectionFlow.cs:448:21:448:21 | access to local variable a : A | semmle.label | access to local variable a : A |
496499
| CollectionFlow.cs:450:14:450:18 | access to local variable array : A[] [element] : A | semmle.label | access to local variable array : A[] [element] : A |
497500
| CollectionFlow.cs:450:14:450:21 | access to array element | semmle.label | access to array element |
501+
| CollectionFlow.cs:480:9:480:11 | [post] access to local variable ic0 : IntegerCollection [property Payload] : A | semmle.label | [post] access to local variable ic0 : IntegerCollection [property Payload] : A |
502+
| CollectionFlow.cs:480:23:480:29 | object creation of type A : A | semmle.label | object creation of type A : A |
503+
| CollectionFlow.cs:482:14:482:16 | access to local variable ic1 : IntegerCollection [property Payload] : A | semmle.label | access to local variable ic1 : IntegerCollection [property Payload] : A |
504+
| CollectionFlow.cs:482:14:482:24 | access to property Payload | semmle.label | access to property Payload |
498505
subpaths
499506
| CollectionFlow.cs:44:20:44:22 | access to local variable as : null [element] : A | CollectionFlow.cs:22:34:22:35 | ts : null [element] : A | CollectionFlow.cs:22:41:22:45 | access to array element : A | CollectionFlow.cs:44:14:44:23 | call to method First<A> |
500507
| CollectionFlow.cs:62:20:62:23 | access to field As : A[] [element] : A | CollectionFlow.cs:22:34:22:35 | ts : A[] [element] : A | CollectionFlow.cs:22:41:22:45 | access to array element : A | CollectionFlow.cs:62:14:62:24 | call to method First<A> |
@@ -579,3 +586,4 @@ subpaths
579586
| CollectionFlow.cs:427:17:427:23 | object creation of type A : A | CollectionFlow.cs:427:17:427:23 | object creation of type A : A | CollectionFlow.cs:429:14:429:21 | access to array element | $@ | CollectionFlow.cs:429:14:429:21 | access to array element | access to array element |
580587
| CollectionFlow.cs:434:17:434:23 | object creation of type A : A | CollectionFlow.cs:434:17:434:23 | object creation of type A : A | CollectionFlow.cs:436:14:436:17 | access to indexer | $@ | CollectionFlow.cs:436:14:436:17 | access to indexer | access to indexer |
581588
| CollectionFlow.cs:447:17:447:23 | object creation of type A : A | CollectionFlow.cs:447:17:447:23 | object creation of type A : A | CollectionFlow.cs:450:14:450:21 | access to array element | $@ | CollectionFlow.cs:450:14:450:21 | access to array element | access to array element |
589+
| CollectionFlow.cs:480:23:480:29 | object creation of type A : A | CollectionFlow.cs:480:23:480:29 | object creation of type A : A | CollectionFlow.cs:482:14:482:24 | access to property Payload | $@ | CollectionFlow.cs:482:14:482:24 | access to property Payload | access to property Payload |

0 commit comments

Comments
 (0)