diff --git a/csharp/ql/test/library-tests/obinit/Flow.expected b/csharp/ql/test/library-tests/obinit/Flow.expected new file mode 100644 index 00000000000..dea9d8df930 --- /dev/null +++ b/csharp/ql/test/library-tests/obinit/Flow.expected @@ -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 | diff --git a/csharp/ql/test/library-tests/obinit/Flow.ql b/csharp/ql/test/library-tests/obinit/Flow.ql new file mode 100644 index 00000000000..93c4bd24e5a --- /dev/null +++ b/csharp/ql/test/library-tests/obinit/Flow.ql @@ -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; + +import Flow::PathGraph + +from DataFlow::Node source, DataFlow::Node sink +where Flow::flow(source, sink) +select sink diff --git a/csharp/ql/test/library-tests/obinit/obinit.cs b/csharp/ql/test/library-tests/obinit/obinit.cs new file mode 100644 index 00000000000..e4e851ed1d8 --- /dev/null +++ b/csharp/ql/test/library-tests/obinit/obinit.cs @@ -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); + } + } +}