Skip to content

Commit 4dfeff3

Browse files
committed
C#: Add dataflow field test for ref structs with ref and ordinary fields.
1 parent 73d0b7e commit 4dfeff3

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

csharp/ql/test/library-tests/dataflow/fields/E.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ static void NotASetter(S s, object o)
1717
s.Field = o;
1818
}
1919

20-
private void M()
20+
private void M1()
2121
{
2222
var o = Source<object>(1);
2323
var s = CreateS(o);
@@ -28,6 +28,35 @@ private void M()
2828
Sink(s.Field); // no flow
2929
}
3030

31+
ref struct RefS
32+
{
33+
public object Field;
34+
public ref object RefField;
35+
36+
public RefS(object o1, ref object o2)
37+
{
38+
Field = o1;
39+
RefField = ref o2;
40+
}
41+
}
42+
43+
static void PartialSetter(RefS s, object o)
44+
{
45+
s.Field = o;
46+
s.RefField = o;
47+
}
48+
49+
private void M2()
50+
{
51+
var o1 = new object();
52+
var o2 = new object();
53+
var refs = new RefS(o1, ref o2);
54+
var taint = Source<object>(2);
55+
PartialSetter(refs, taint);
56+
Sink(refs.Field); // no flow
57+
Sink(refs.RefField); // $ hasValueFlow=2
58+
}
59+
3160
public static void Sink(object o) { }
3261

3362
static T Source<T>(object source) => throw null;

csharp/ql/test/library-tests/dataflow/fields/FieldFlow.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
testFailures
2+
| E.cs:57:30:57:48 | // ... | Missing result:hasValueFlow=2 |
23
edges
34
| A.cs:5:17:5:28 | call to method Source<C> : C | A.cs:6:24:6:24 | access to local variable c : C |
45
| A.cs:5:17:5:28 | call to method Source<C> : C | A.cs:6:24:6:24 | access to local variable c : C |

0 commit comments

Comments
 (0)