mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
C#: Add object initializer test.
This commit is contained in:
18
csharp/ql/test/library-tests/obinit/Flow.expected
Normal file
18
csharp/ql/test/library-tests/obinit/Flow.expected
Normal file
@@ -0,0 +1,18 @@
|
||||
edges
|
||||
| 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 | |
|
||||
| obinit.cs:5:27:5:34 | "source" : String | obinit.cs:5:23:5:23 | [post] this access : A [field s] : String | provenance | |
|
||||
| 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 | |
|
||||
| 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 | |
|
||||
| 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 | |
|
||||
| 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 | |
|
||||
nodes
|
||||
| obinit.cs:5:23:5:23 | [post] this access : A [field s] : String | semmle.label | [post] this access : A [field s] : String |
|
||||
| obinit.cs:5:27:5:34 | "source" : String | semmle.label | "source" : String |
|
||||
| obinit.cs:7:16:7:16 | this [Return] : A [field s] : String | semmle.label | this [Return] : A [field s] : String |
|
||||
| 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 |
|
||||
| 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 |
|
||||
| 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 |
|
||||
| obinit.cs:21:18:21:20 | access to field s | semmle.label | access to field s |
|
||||
subpaths
|
||||
#select
|
||||
| obinit.cs:21:18:21:20 | access to field s |
|
||||
22
csharp/ql/test/library-tests/obinit/Flow.ql
Normal file
22
csharp/ql/test/library-tests/obinit/Flow.ql
Normal file
@@ -0,0 +1,22 @@
|
||||
import csharp
|
||||
|
||||
module FlowConfig implements DataFlow::ConfigSig {
|
||||
predicate isSource(DataFlow::Node source) {
|
||||
source.asExpr().(StringLiteral).getValue() = "source"
|
||||
}
|
||||
|
||||
predicate isSink(DataFlow::Node sink) {
|
||||
exists(MethodCall mc |
|
||||
mc.getTarget().getUndecoratedName() = "Sink" and
|
||||
mc.getAnArgument() = sink.asExpr()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
module Flow = DataFlow::Global<FlowConfig>;
|
||||
|
||||
import Flow::PathGraph
|
||||
|
||||
from DataFlow::Node source, DataFlow::Node sink
|
||||
where Flow::flow(source, sink)
|
||||
select sink
|
||||
30
csharp/ql/test/library-tests/obinit/obinit.cs
Normal file
30
csharp/ql/test/library-tests/obinit/obinit.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
namespace ObInit {
|
||||
public class A {
|
||||
int x = 1;
|
||||
|
||||
public string s = "source";
|
||||
|
||||
public A() { }
|
||||
|
||||
public A(int y) { }
|
||||
|
||||
public A(int y, int z) : this(y) { }
|
||||
}
|
||||
|
||||
public class B : A {
|
||||
public B() : base(10) { }
|
||||
|
||||
static void Sink(string s) { }
|
||||
|
||||
static void Foo() {
|
||||
A a = new A();
|
||||
Sink(a.s);
|
||||
|
||||
A a2 = new A(0, 0);
|
||||
Sink(a2.s);
|
||||
|
||||
B b = new B();
|
||||
Sink(b.s);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user