Skip to content

Commit dc7a0c1

Browse files
authored
Merge pull request #2442 from hvitved/csharp/dataflow/conversion-operator
Approved by calumgrant
2 parents f958916 + 04cecc0 commit dc7a0c1

File tree

6 files changed

+42
-1
lines changed

6 files changed

+42
-1
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Improvements to C# analysis
2+
3+
The following changes in version 1.24 affect C# analysis in all applications.
4+
5+
## General improvements
6+
7+
## New queries
8+
9+
| **Query** | **Tags** | **Purpose** |
10+
|-----------------------------|-----------|--------------------------------------------------------------------|
11+
12+
## Changes to existing queries
13+
14+
| **Query** | **Expected impact** | **Change** |
15+
|----------------------------|------------------------|------------------------------------------------------------------|
16+
17+
## Changes to libraries
18+
19+
* The taint tracking library now tracks flow through (implicit or explicit) conversion operator calls.

csharp/ql/src/semmle/code/csharp/dataflow/internal/TaintTrackingPrivate.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ private class LocalTaintExprStepConfiguration extends ControlFlowReachabilityCon
113113
scope = e2 and
114114
isSuccessor = true
115115
)
116+
or
117+
e2 = any(OperatorCall oc |
118+
oc.getTarget().(ConversionOperator).fromLibrary() and
119+
e1 = oc.getAnArgument() and
120+
isSuccessor = true
121+
)
116122
)
117123
}
118124

csharp/ql/test/library-tests/dataflow/local/DataFlowStep.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,9 @@
586586
| LocalDataFlow.cs:480:67:480:68 | os | LocalDataFlow.cs:486:32:486:33 | access to parameter os |
587587
| LocalDataFlow.cs:483:21:483:21 | access to parameter x | LocalDataFlow.cs:483:16:483:21 | ... = ... |
588588
| LocalDataFlow.cs:486:32:486:33 | access to parameter os | LocalDataFlow.cs:486:26:486:33 | ... = ... |
589+
| LocalDataFlow.cs:491:41:491:44 | args | LocalDataFlow.cs:493:29:493:32 | access to parameter args |
590+
| LocalDataFlow.cs:493:29:493:32 | [post] access to parameter args | LocalDataFlow.cs:494:27:494:30 | access to parameter args |
591+
| LocalDataFlow.cs:493:29:493:32 | access to parameter args | LocalDataFlow.cs:494:27:494:30 | access to parameter args |
589592
| SSA.cs:5:17:5:17 | SSA entry def(this.S) | SSA.cs:67:9:67:14 | access to field S |
590593
| SSA.cs:5:17:5:17 | this | SSA.cs:67:9:67:12 | this access |
591594
| SSA.cs:5:26:5:32 | tainted | SSA.cs:8:24:8:30 | access to parameter tainted |

csharp/ql/test/library-tests/dataflow/local/LocalDataFlow.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,4 +485,12 @@ public void AssignmentFlow(IDisposable x, IEnumerable<object> os)
485485
IEnumerable<object> os2;
486486
foreach(var o in os2 = os) { }
487487
}
488+
489+
public static implicit operator LocalDataFlow(string[] args) => null;
490+
491+
public void ConversionFlow(string[] args)
492+
{
493+
Span<object> span = args; // flow (library operator)
494+
LocalDataFlow x = args; // no flow (source code operator)
495+
}
488496
}

csharp/ql/test/library-tests/dataflow/local/TaintTrackingStep.expected

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,11 @@
736736
| LocalDataFlow.cs:480:67:480:68 | os | LocalDataFlow.cs:486:32:486:33 | access to parameter os |
737737
| LocalDataFlow.cs:483:21:483:21 | access to parameter x | LocalDataFlow.cs:483:16:483:21 | ... = ... |
738738
| LocalDataFlow.cs:486:32:486:33 | access to parameter os | LocalDataFlow.cs:486:26:486:33 | ... = ... |
739+
| LocalDataFlow.cs:491:41:491:44 | args | LocalDataFlow.cs:491:41:491:44 | args |
740+
| LocalDataFlow.cs:491:41:491:44 | args | LocalDataFlow.cs:493:29:493:32 | access to parameter args |
741+
| LocalDataFlow.cs:493:29:493:32 | [post] access to parameter args | LocalDataFlow.cs:494:27:494:30 | access to parameter args |
742+
| LocalDataFlow.cs:493:29:493:32 | access to parameter args | LocalDataFlow.cs:493:29:493:32 | call to operator implicit conversion |
743+
| LocalDataFlow.cs:493:29:493:32 | access to parameter args | LocalDataFlow.cs:494:27:494:30 | access to parameter args |
739744
| SSA.cs:5:17:5:17 | SSA entry def(this.S) | SSA.cs:67:9:67:14 | access to field S |
740745
| SSA.cs:5:17:5:17 | this | SSA.cs:67:9:67:12 | this access |
741746
| SSA.cs:5:26:5:32 | tainted | SSA.cs:5:26:5:32 | tainted |

csharp/ql/test/library-tests/frameworks/EntityFramework/EntityFrameworkCore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void TestDataFlow()
5050
Sink(taintSource); // Tainted
5151
Sink(new RawSqlString(taintSource)); // Tainted
5252
Sink((RawSqlString)taintSource); // Tainted
53-
Sink((RawSqlString)(FormattableString)$"{taintSource}"); // Not tainted
53+
Sink((RawSqlString)(FormattableString)$"{taintSource}"); // Tainted, but not reported because conversion operator is in a stub .cs file
5454

5555
// Tainted via database, even though technically there were no reads or writes to the database in this particular case.
5656
var p1 = new Person { Name = taintSource };

0 commit comments

Comments
 (0)