mirror of
https://github.com/github/codeql.git
synced 2026-04-28 02:05:14 +02:00
C#: Add ContentDataFlow test
This commit is contained in:
31
csharp/ql/test/library-tests/dataflow/content/ContentFlow.cs
Normal file
31
csharp/ql/test/library-tests/dataflow/content/ContentFlow.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
|
||||
public class ContentFlow
|
||||
{
|
||||
public class A
|
||||
{
|
||||
public A FieldA;
|
||||
public B FieldB;
|
||||
}
|
||||
public class B
|
||||
{
|
||||
public A FieldA;
|
||||
public B FieldB;
|
||||
}
|
||||
|
||||
public void M(A a, B b)
|
||||
{
|
||||
var a1 = new A();
|
||||
Sink(a1.FieldA.FieldB);
|
||||
|
||||
a.FieldA.FieldB = new B();
|
||||
Sink(a);
|
||||
|
||||
var a2 = new A();
|
||||
b.FieldB.FieldA = a2.FieldB.FieldA;
|
||||
Sink(b);
|
||||
}
|
||||
|
||||
public static void Sink<T>(T t) { }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
| ContentFlow.cs:18:18:18:24 | object creation of type A | field FieldB.field FieldA. | ContentFlow.cs:19:14:19:29 | access to field FieldB | | true |
|
||||
| ContentFlow.cs:21:27:21:33 | object creation of type B | | ContentFlow.cs:22:14:22:14 | access to parameter a | field FieldA.field FieldB. | true |
|
||||
| ContentFlow.cs:24:18:24:24 | object creation of type A | field FieldA.field FieldB. | ContentFlow.cs:26:14:26:14 | access to parameter b | field FieldB.field FieldA. | true |
|
||||
23
csharp/ql/test/library-tests/dataflow/content/ContentFlow.ql
Normal file
23
csharp/ql/test/library-tests/dataflow/content/ContentFlow.ql
Normal file
@@ -0,0 +1,23 @@
|
||||
import csharp
|
||||
import semmle.code.csharp.dataflow.internal.ContentDataFlow
|
||||
|
||||
class Conf extends ContentDataFlow::Configuration {
|
||||
Conf() { this = "ContentFlowConf" }
|
||||
|
||||
override predicate isSource(DataFlow::Node src) { src.asExpr() instanceof ObjectCreation }
|
||||
|
||||
override predicate isSink(DataFlow::Node sink) {
|
||||
exists(MethodCall mc |
|
||||
mc.getTarget().hasUndecoratedName("Sink") and
|
||||
mc.getAnArgument() = sink.asExpr()
|
||||
)
|
||||
}
|
||||
|
||||
override int accessPathLimit() { result = 2 }
|
||||
}
|
||||
|
||||
from
|
||||
Conf conf, ContentDataFlow::Node source, ContentDataFlow::AccessPath sourceAp,
|
||||
ContentDataFlow::Node sink, ContentDataFlow::AccessPath sinkAp, boolean preservesValue
|
||||
where conf.hasFlow(source, sourceAp, sink, sinkAp, preservesValue)
|
||||
select source, sourceAp, sink, sinkAp, preservesValue
|
||||
Reference in New Issue
Block a user