Skip to content

Commit 7c18195

Browse files
committed
C#: Add object initializer test.
1 parent b1ed72d commit 7c18195

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
edges
2+
| obinit.cs:5:23:5:23 | [post] this access : A [field s] : String | obinit.cs:7:16:7:16 | this [Return] : A [field s] : String | provenance | |
3+
| obinit.cs:5:27:5:34 | "source" : String | obinit.cs:5:23:5:23 | [post] this access : A [field s] : String | provenance | |
4+
| obinit.cs:7:16:7:16 | this [Return] : A [field s] : String | obinit.cs:20:19:20:25 | object creation of type A : A [field s] : String | provenance | |
5+
| obinit.cs:20:15:20:15 | access to local variable a : A [field s] : String | obinit.cs:21:18:21:18 | access to local variable a : A [field s] : String | provenance | |
6+
| obinit.cs:20:19:20:25 | object creation of type A : A [field s] : String | obinit.cs:20:15:20:15 | access to local variable a : A [field s] : String | provenance | |
7+
| obinit.cs:21:18:21:18 | access to local variable a : A [field s] : String | obinit.cs:21:18:21:20 | access to field s | provenance | |
8+
nodes
9+
| obinit.cs:5:23:5:23 | [post] this access : A [field s] : String | semmle.label | [post] this access : A [field s] : String |
10+
| obinit.cs:5:27:5:34 | "source" : String | semmle.label | "source" : String |
11+
| obinit.cs:7:16:7:16 | this [Return] : A [field s] : String | semmle.label | this [Return] : A [field s] : String |
12+
| obinit.cs:20:15:20:15 | access to local variable a : A [field s] : String | semmle.label | access to local variable a : A [field s] : String |
13+
| obinit.cs:20:19:20:25 | object creation of type A : A [field s] : String | semmle.label | object creation of type A : A [field s] : String |
14+
| obinit.cs:21:18:21:18 | access to local variable a : A [field s] : String | semmle.label | access to local variable a : A [field s] : String |
15+
| obinit.cs:21:18:21:20 | access to field s | semmle.label | access to field s |
16+
subpaths
17+
#select
18+
| obinit.cs:21:18:21:20 | access to field s |
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import csharp
2+
3+
module FlowConfig implements DataFlow::ConfigSig {
4+
predicate isSource(DataFlow::Node source) {
5+
source.asExpr().(StringLiteral).getValue() = "source"
6+
}
7+
8+
predicate isSink(DataFlow::Node sink) {
9+
exists(MethodCall mc |
10+
mc.getTarget().getUndecoratedName() = "Sink" and
11+
mc.getAnArgument() = sink.asExpr()
12+
)
13+
}
14+
}
15+
16+
module Flow = DataFlow::Global<FlowConfig>;
17+
18+
import Flow::PathGraph
19+
20+
from DataFlow::Node source, DataFlow::Node sink
21+
where Flow::flow(source, sink)
22+
select sink
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
namespace ObInit {
2+
public class A {
3+
int x = 1;
4+
5+
public string s = "source";
6+
7+
public A() { }
8+
9+
public A(int y) { }
10+
11+
public A(int y, int z) : this(y) { }
12+
}
13+
14+
public class B : A {
15+
public B() : base(10) { }
16+
17+
static void Sink(string s) { }
18+
19+
static void Foo() {
20+
A a = new A();
21+
Sink(a.s);
22+
23+
A a2 = new A(0, 0);
24+
Sink(a2.s);
25+
26+
B b = new B();
27+
Sink(b.s);
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)