mirror of
https://github.com/github/codeql.git
synced 2025-12-17 17:23:36 +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.
52 lines
1.2 KiB
C#
52 lines
1.2 KiB
C#
public class D
|
|
{
|
|
object AutoProp { get; set; }
|
|
|
|
object trivialPropField;
|
|
object TrivialProp
|
|
{
|
|
get { return this.trivialPropField; }
|
|
set { this.trivialPropField = value; }
|
|
}
|
|
|
|
object ComplexProp
|
|
{
|
|
get { return this.trivialPropField; }
|
|
set { this.TrivialProp = value; }
|
|
}
|
|
|
|
static D Create(object o1, object o2, object o3)
|
|
{
|
|
var ret = new D();
|
|
ret.AutoProp = o1;
|
|
ret.TrivialProp = o2;
|
|
ret.ComplexProp = o3;
|
|
return ret;
|
|
}
|
|
|
|
private void M()
|
|
{
|
|
var o = new object();
|
|
|
|
var d = Create(o, null, null);
|
|
Sink(d.AutoProp); // flow
|
|
Sink(d.TrivialProp); // no flow
|
|
Sink(d.trivialPropField); // no flow
|
|
Sink(d.ComplexProp); // no flow
|
|
|
|
d = Create(null, o, null);
|
|
Sink(d.AutoProp); // no flow
|
|
Sink(d.TrivialProp); // flow
|
|
Sink(d.trivialPropField); // flow
|
|
Sink(d.ComplexProp); // flow
|
|
|
|
d = Create(null, null, o);
|
|
Sink(d.AutoProp); // no flow
|
|
Sink(d.TrivialProp); // flow
|
|
Sink(d.trivialPropField); // flow
|
|
Sink(d.ComplexProp); // flow
|
|
}
|
|
|
|
public static void Sink(object o) { }
|
|
}
|