mirror of
https://github.com/github/codeql.git
synced 2026-04-25 00:35:20 +02:00
C#: Add more flow-through data-flow tests
This commit is contained in:
@@ -174,6 +174,9 @@ edges
|
||||
| G.cs:52:14:52:21 | access to field boxfield [Box1, Elem] | G.cs:52:14:52:26 | access to field Box1 [Elem] : Elem |
|
||||
| G.cs:52:14:52:21 | this access [boxfield, Box1, ... (3)] | G.cs:52:14:52:21 | access to field boxfield [Box1, Elem] |
|
||||
| G.cs:52:14:52:26 | access to field Box1 [Elem] : Elem | G.cs:52:14:52:31 | access to field Elem |
|
||||
| H.cs:88:17:88:17 | [post] access to local variable a [FieldA] : Object | H.cs:89:14:89:14 | access to local variable a [FieldA] : Object |
|
||||
| H.cs:88:20:88:31 | object creation of type Object : Object | H.cs:88:17:88:17 | [post] access to local variable a [FieldA] : Object |
|
||||
| H.cs:89:14:89:14 | access to local variable a [FieldA] : Object | H.cs:89:14:89:21 | access to field FieldA |
|
||||
nodes
|
||||
| A.cs:5:17:5:23 | object creation of type C : C | semmle.label | object creation of type C : C |
|
||||
| A.cs:6:17:6:25 | call to method Make [c] : C | semmle.label | call to method Make [c] : C |
|
||||
@@ -371,6 +374,10 @@ nodes
|
||||
| G.cs:52:14:52:21 | this access [boxfield, Box1, ... (3)] | semmle.label | this access [boxfield, Box1, ... (3)] |
|
||||
| G.cs:52:14:52:26 | access to field Box1 [Elem] : Elem | semmle.label | access to field Box1 [Elem] : Elem |
|
||||
| G.cs:52:14:52:31 | access to field Elem | semmle.label | access to field Elem |
|
||||
| H.cs:88:17:88:17 | [post] access to local variable a [FieldA] : Object | semmle.label | [post] access to local variable a [FieldA] : Object |
|
||||
| H.cs:88:20:88:31 | object creation of type Object : Object | semmle.label | object creation of type Object : Object |
|
||||
| H.cs:89:14:89:14 | access to local variable a [FieldA] : Object | semmle.label | access to local variable a [FieldA] : Object |
|
||||
| H.cs:89:14:89:21 | access to field FieldA | semmle.label | access to field FieldA |
|
||||
#select
|
||||
| A.cs:7:14:7:16 | access to field c | A.cs:5:17:5:23 | object creation of type C : C | A.cs:7:14:7:16 | access to field c | $@ | A.cs:5:17:5:23 | object creation of type C : C | object creation of type C : C |
|
||||
| A.cs:14:14:14:20 | call to method Get | A.cs:13:15:13:22 | object creation of type C1 : C1 | A.cs:14:14:14:20 | call to method Get | $@ | A.cs:13:15:13:22 | object creation of type C1 : C1 | object creation of type C1 : C1 |
|
||||
@@ -410,3 +417,4 @@ nodes
|
||||
| G.cs:39:14:39:35 | call to method GetElem | G.cs:23:18:23:27 | object creation of type Elem : Elem | G.cs:39:14:39:35 | call to method GetElem | $@ | G.cs:23:18:23:27 | object creation of type Elem : Elem | object creation of type Elem : Elem |
|
||||
| G.cs:39:14:39:35 | call to method GetElem | G.cs:31:18:31:27 | object creation of type Elem : Elem | G.cs:39:14:39:35 | call to method GetElem | $@ | G.cs:31:18:31:27 | object creation of type Elem : Elem | object creation of type Elem : Elem |
|
||||
| G.cs:52:14:52:31 | access to field Elem | G.cs:44:18:44:27 | object creation of type Elem : Elem | G.cs:52:14:52:31 | access to field Elem | $@ | G.cs:44:18:44:27 | object creation of type Elem : Elem | object creation of type Elem : Elem |
|
||||
| H.cs:89:14:89:21 | access to field FieldA | H.cs:88:20:88:31 | object creation of type Object : Object | H.cs:89:14:89:21 | access to field FieldA | $@ | H.cs:88:20:88:31 | object creation of type Object : Object | object creation of type Object : Object |
|
||||
|
||||
152
csharp/ql/test/library-tests/dataflow/fields/H.cs
Normal file
152
csharp/ql/test/library-tests/dataflow/fields/H.cs
Normal file
@@ -0,0 +1,152 @@
|
||||
public class H
|
||||
{
|
||||
class A
|
||||
{
|
||||
public object FieldA;
|
||||
}
|
||||
|
||||
class B
|
||||
{
|
||||
public object FieldB;
|
||||
}
|
||||
|
||||
A Clone(A a)
|
||||
{
|
||||
var ret = new A();
|
||||
ret.FieldA = a.FieldA;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void M1(object o)
|
||||
{
|
||||
var a = new A();
|
||||
a.FieldA = new object();
|
||||
var clone = Clone(a);
|
||||
Sink(clone.FieldA); // flow [MISSING]
|
||||
|
||||
a = new A();
|
||||
a.FieldA = o;
|
||||
clone = Clone(a);
|
||||
Sink(clone.FieldA); // no flow
|
||||
}
|
||||
|
||||
B Transform(A a)
|
||||
{
|
||||
var b = new B();
|
||||
b.FieldB = a.FieldA;
|
||||
return b;
|
||||
}
|
||||
|
||||
void M2(object o)
|
||||
{
|
||||
var a = new A();
|
||||
a.FieldA = new object();
|
||||
var b = Transform(a);
|
||||
Sink(b.FieldB); // flow [MISSING]
|
||||
|
||||
a = new A();
|
||||
a.FieldA = o;
|
||||
b = Transform(a);
|
||||
Sink(b.FieldB); // no flow
|
||||
}
|
||||
|
||||
void TransformArg(A a, B b1, B b2)
|
||||
{
|
||||
b1.FieldB = a.FieldA;
|
||||
}
|
||||
|
||||
void M3(object o)
|
||||
{
|
||||
var a = new A();
|
||||
var b1 = new B();
|
||||
var b2 = new B();
|
||||
a.FieldA = new object();
|
||||
TransformArg(a, b1, b2);
|
||||
Sink(b1.FieldB); // flow [MISSING]
|
||||
Sink(b2.FieldB); // no flow
|
||||
|
||||
a = new A();
|
||||
b1 = new B();
|
||||
b2 = new B();
|
||||
a.FieldA = o;
|
||||
TransformArg(a, b1, b2);
|
||||
Sink(b1.FieldB); // no flow
|
||||
Sink(b2.FieldB); // no flow
|
||||
}
|
||||
|
||||
void SetArgs(A a, object o, B b1, B b2)
|
||||
{
|
||||
a.FieldA = o;
|
||||
TransformArg(a, b1, b2);
|
||||
}
|
||||
|
||||
void M4(object o)
|
||||
{
|
||||
var a = new A();
|
||||
var b1 = new B();
|
||||
var b2 = new B();
|
||||
SetArgs(a, new object(), b1, b2);
|
||||
Sink(a.FieldA); // flow
|
||||
Sink(b1.FieldB); // flow [MISSING]
|
||||
Sink(b2.FieldB); // no flow
|
||||
|
||||
a = new A();
|
||||
b1 = new B();
|
||||
b2 = new B();
|
||||
SetArgs(a, o, b1, b2);
|
||||
Sink(a.FieldA); // no flow
|
||||
Sink(b1.FieldB); // no flow
|
||||
Sink(b2.FieldB); // no flow
|
||||
}
|
||||
|
||||
B TransformWrap(A a)
|
||||
{
|
||||
var temp = new B();
|
||||
temp.FieldB = a;
|
||||
return Transform((A)temp.FieldB);
|
||||
}
|
||||
|
||||
void M5(object o)
|
||||
{
|
||||
var a = new A();
|
||||
a.FieldA = new object();
|
||||
var b = TransformWrap(a);
|
||||
Sink(b.FieldB); // flow [MISSING]
|
||||
|
||||
a = new A();
|
||||
a.FieldA = o;
|
||||
b = TransformWrap(a);
|
||||
Sink(b.FieldB); // no flow
|
||||
}
|
||||
|
||||
object Get(A a)
|
||||
{
|
||||
return Transform(a).FieldB;
|
||||
}
|
||||
|
||||
void M6(object o)
|
||||
{
|
||||
var a = new A();
|
||||
a.FieldA = new object();
|
||||
Sink(Get(a)); // flow [MISSING]
|
||||
|
||||
a = new A();
|
||||
a.FieldA = o;
|
||||
Sink(Get(a)); // no flow
|
||||
}
|
||||
|
||||
object Through(object o)
|
||||
{
|
||||
var a = new A();
|
||||
a.FieldA = o;
|
||||
return Transform(a).FieldB;
|
||||
}
|
||||
|
||||
void M7()
|
||||
{
|
||||
var o = Through(new object());
|
||||
Sink(o); // flow [MISSING]
|
||||
}
|
||||
|
||||
public static void Sink(object o) { }
|
||||
}
|
||||
Reference in New Issue
Block a user