Skip to content

Commit

Permalink
C#: Add some source/sink examples where lifting is applied.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelnebel committed Jun 27, 2024
1 parent 64ac52e commit 3180d8f
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ extensions:
extensible: sinkModel
data:
- [ "Sinks", "NewSinks", False, "Sink", "(System.Object)", "", "Argument[0]", "test-sink", "manual"]
- [ "Sinks", "NewSinks", False, "Sink2", "(System.Object)", "", "Argument[0]", "test-sink2", "manual"]
- [ "Sinks", "NewSinks", False, "ManualSinkAlreadyDefined", "(System.Object)", "", "Argument[0]", "test-sink", "manual"]

- addsTo:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ extensions:
extensible: sourceModel
data:
- ["Sources", "NewSources", False, "ManualSourceAlreadyDefined", "()", "", "ReturnValue", "test-source", "manual"]
- ["Sources", "NewSources", False, "Source1", "()", "", "ReturnValue", "source-kind-1", "manual"]
- ["Sources", "NewSources", False, "Source2", "()", "", "ReturnValue", "source-kind-2", "manual"]

- addsTo:
pack: codeql/csharp-all
Expand Down
32 changes: 31 additions & 1 deletion csharp/ql/test/utils/modelgenerator/dataflow/Sinks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ public class NewSinks

// Sink defined in the extensible file next to the test.
// neutral=Sinks;NewSinks;Sink;(System.Object);summary;df-generated
public void Sink(object o) => throw null;
public static void Sink(object o) => throw null;

// Sink defined in the extensible file next to the test.
// neutral=Sinks;NewSinks;Sink2;(System.Object);summary;df-generated
public static void Sink2(object o) => throw null;

// New sink
// sink=Sinks;NewSinks;false;WrapResponseWrite;(System.Object);;Argument[0];html-injection;df-generated
Expand Down Expand Up @@ -105,6 +109,32 @@ public void ManualSinkAlreadyDefined(object o)
{
Sink(o);
}

public abstract class DataWriter
{
// neutral=Sinks;NewSinks+DataWriter;Write;(System.Object);summary;df-generated
public abstract void Write(object o);
}

public class DataWriterKind1 : DataWriter
{
// sink=Sinks;NewSinks+DataWriter;true;Write;(System.Object);;Argument[0];test-sink;df-generated
// neutral=Sinks;NewSinks+DataWriterKind1;Write;(System.Object);summary;df-generated
public override void Write(object o)
{
Sink(o);
}
}

public class DataWriterKind2 : DataWriter
{
// sink=Sinks;NewSinks+DataWriter;true;Write;(System.Object);;Argument[0];test-sink2;df-generated
// neutral=Sinks;NewSinks+DataWriterKind2;Write;(System.Object);summary;df-generated
public override void Write(object o)
{
Sink2(o);
}
}
}

public class CompoundSinks
Expand Down
35 changes: 35 additions & 0 deletions csharp/ql/test/utils/modelgenerator/dataflow/Sources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ namespace Sources;

public class NewSources
{
// Defined as source in the extensions file next to the test.
// neutral=Sources;NewSources;Source1;();summary;df-generated
public static string Source1() => throw null;

// Defined as source in the extensions file next to the test.
// neutral=Sources;NewSources;Source2;();summary;df-generated
public static string Source2() => throw null;


// New source
// source=Sources;NewSources;false;WrapConsoleReadLine;();;ReturnValue;local;df-generated
// neutral=Sources;NewSources;WrapConsoleReadLine;();summary;df-generated
Expand Down Expand Up @@ -79,4 +88,30 @@ public string ManualSourceAlreadyDefined()
{
return Console.ReadLine();
}

public abstract class DataReader
{
// neutral=Sources;NewSources+DataReader;Read;();summary;df-generated
public abstract string Read();
}

public class DataReaderKind1 : DataReader
{
// source=Sources;NewSources+DataReader;true;Read;();;ReturnValue;source-kind-1;df-generated
// neutral=Sources;NewSources+DataReaderKind1;Read;();summary;df-generated
public override string Read()
{
return Source1();
}
}

public class DataReaderKind2 : DataReader
{
// source=Sources;NewSources+DataReader;true;Read;();;ReturnValue;source-kind-2;df-generated
// neutral=Sources;NewSources+DataReaderKind2;Read;();summary;df-generated
public override string Read()
{
return Source2();
}
}
}

0 comments on commit 3180d8f

Please sign in to comment.