Skip to content

Commit 8807217

Browse files
committed
C#: Add implicit conversion operator taint example.
1 parent a2f45f1 commit 8807217

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
3+
public class TestImplicitConversionOperator
4+
{
5+
static void Sink(object o) { }
6+
static void TaintArgument(ArraySegment<byte> segment) { }
7+
8+
public void M1()
9+
{
10+
byte[] bytes = new byte[1];
11+
TaintArgument(bytes);
12+
Sink(bytes);
13+
}
14+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
edges
2+
nodes
3+
subpaths
4+
#select
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* @kind path-problem
3+
*/
4+
5+
import csharp
6+
import semmle.code.csharp.dataflow.internal.DataFlowPrivate as DataFlowPrivate
7+
import Taint::PathGraph
8+
9+
module TaintConfig implements DataFlow::ConfigSig {
10+
predicate isSource(DataFlow::Node src) {
11+
exists(MethodCall mc |
12+
mc.getTarget().hasName("TaintArgument") and
13+
mc.getAnArgument() = src.(DataFlowPrivate::PostUpdateNode).getPreUpdateNode().asExpr()
14+
)
15+
}
16+
17+
predicate isSink(DataFlow::Node sink) {
18+
exists(MethodCall mc |
19+
mc.getTarget().hasName("Sink") and
20+
mc.getAnArgument() = sink.asExpr()
21+
)
22+
}
23+
}
24+
25+
module Taint = TaintTracking::Global<TaintConfig>;
26+
27+
from Taint::PathNode source, Taint::PathNode sink
28+
where Taint::flowPath(source, sink)
29+
select sink, source, sink, "$@", source, source.toString()

0 commit comments

Comments
 (0)