mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Initial implementation of data flow through fields, using the algorithm of the
shared data flow implementation. Fields (and field-like properties) are covered,
and stores can be either
- ordinary assignments, `Foo = x`,
- object initializers, `new C() { Foo = x }`, or
- field initializers, `int Foo = x`.
For field initializers, we need to synthesize calls (`SynthesizedCall`),
callables (`SynthesizedCallable`), parameters (`InstanceParameterNode`), and
arguments (`SynthesizedThisArgumentNode`), as the C# extractor does not (yet)
extract such entities. For example, in
```
class C
{
int Field1 = 1;
int Field2 = 2;
C() { }
}
```
there is a synthesized call from the constructor `C`, with a synthesized `this`
argument, and the targets of that call are two synthesized callables with bodies
`this.Field1 = 1` and `this.Field2 = 2`, respectively.
A consequence of this is that `DataFlowCallable` is no longer an alias for
`DotNet::Callable`, but instead an IPA type.
30 lines
653 B
C#
30 lines
653 B
C#
public class F
|
|
{
|
|
object Field1;
|
|
object Field2;
|
|
|
|
static F Create(object o1, object o2) => new F() { Field1 = o1, Field2 = o2 };
|
|
|
|
private void M()
|
|
{
|
|
var o = new object();
|
|
var f = Create(o, null);
|
|
Sink(f.Field1); // flow
|
|
Sink(f.Field2); // no flow
|
|
|
|
f = Create(null, o);
|
|
Sink(f.Field1); // no flow
|
|
Sink(f.Field2); // flow
|
|
|
|
f = new F() { Field1 = o };
|
|
Sink(f.Field1); // flow
|
|
Sink(f.Field2); // no flow
|
|
|
|
f = new F() { Field2 = o };
|
|
Sink(f.Field1); // no flow
|
|
Sink(f.Field2); // flow
|
|
}
|
|
|
|
public static void Sink(object o) { }
|
|
}
|