mirror of
https://github.com/github/codeql.git
synced 2026-05-04 05:05:12 +02:00
C#: Add dataflow field test for ref structs with ref and ordinary fields.
This commit is contained in:
@@ -17,7 +17,7 @@ public class E
|
||||
s.Field = o;
|
||||
}
|
||||
|
||||
private void M()
|
||||
private void M1()
|
||||
{
|
||||
var o = Source<object>(1);
|
||||
var s = CreateS(o);
|
||||
@@ -28,6 +28,35 @@ public class E
|
||||
Sink(s.Field); // no flow
|
||||
}
|
||||
|
||||
ref struct RefS
|
||||
{
|
||||
public object Field;
|
||||
public ref object RefField;
|
||||
|
||||
public RefS(object o1, ref object o2)
|
||||
{
|
||||
Field = o1;
|
||||
RefField = ref o2;
|
||||
}
|
||||
}
|
||||
|
||||
static void PartialSetter(RefS s, object o)
|
||||
{
|
||||
s.Field = o;
|
||||
s.RefField = o;
|
||||
}
|
||||
|
||||
private void M2()
|
||||
{
|
||||
var o1 = new object();
|
||||
var o2 = new object();
|
||||
var refs = new RefS(o1, ref o2);
|
||||
var taint = Source<object>(2);
|
||||
PartialSetter(refs, taint);
|
||||
Sink(refs.Field); // no flow
|
||||
Sink(refs.RefField); // $ hasValueFlow=2
|
||||
}
|
||||
|
||||
public static void Sink(object o) { }
|
||||
|
||||
static T Source<T>(object source) => throw null;
|
||||
|
||||
Reference in New Issue
Block a user