Skip to content

Commit cde98c7

Browse files
committed
C#: Convert System.Threading.Tasks.Task flow to CSV format.
1 parent 90d7b94 commit cde98c7

File tree

3 files changed

+46
-90
lines changed

3 files changed

+46
-90
lines changed

csharp/ql/lib/semmle/code/csharp/dataflow/ExternalFlow.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ private module Frameworks {
100100
private import semmle.code.csharp.frameworks.system.IO
101101
private import semmle.code.csharp.frameworks.system.io.Compression
102102
private import semmle.code.csharp.frameworks.system.Xml
103+
private import semmle.code.csharp.frameworks.system.threading.Tasks
103104
}
104105

105106
/**

csharp/ql/lib/semmle/code/csharp/dataflow/LibraryTypeDataFlow.qll

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,96 +1365,6 @@ class SystemTupleFlow extends LibraryTypeDataFlow, ValueOrRefType {
13651365
}
13661366
}
13671367

1368-
/** Data flow for `System.Threading.Tasks.Task`. */
1369-
class SystemThreadingTasksTaskFlow extends LibraryTypeDataFlow, SystemThreadingTasksTaskClass {
1370-
override predicate callableFlow(
1371-
CallableFlowSource source, AccessPath sourceAp, CallableFlowSink sink, AccessPath sinkAp,
1372-
SourceDeclarationCallable c, boolean preservesValue
1373-
) {
1374-
(
1375-
this.constructorFlow(source, sink, c) and
1376-
sourceAp = AccessPath::empty() and
1377-
sinkAp = AccessPath::empty()
1378-
or
1379-
this.methodFlow(source, sourceAp, sink, sinkAp, c)
1380-
) and
1381-
preservesValue = true
1382-
}
1383-
1384-
private predicate constructorFlow(CallableFlowSource source, CallableFlowSink sink, Constructor c) {
1385-
// flow from supplied state to supplied delegate
1386-
c.getDeclaringType() = this and
1387-
exists(ConstructedDelegateType action |
1388-
c.getParameter(1).getType() instanceof ObjectType and
1389-
c.getParameter(0).getType() = action and
1390-
action.getUnboundGeneric().(SystemActionTDelegateType).getNumberOfTypeParameters() = 1 and
1391-
action.getTypeArgument(0) instanceof ObjectType and
1392-
source = TCallableFlowSourceArg(1) and
1393-
sink = getDelegateFlowSinkArg(c, 0, 0)
1394-
)
1395-
}
1396-
1397-
private predicate methodFlow(
1398-
CallableFlowSource source, AccessPath sourceAp, CallableFlowSink sink, AccessPath sinkAp,
1399-
SourceDeclarationMethod m
1400-
) {
1401-
m.getDeclaringType() = this and
1402-
(
1403-
m.getName().regexpMatch("ContinueWith(<>)?") and
1404-
sourceAp = AccessPath::empty() and
1405-
(
1406-
// flow from supplied state to supplied delegate
1407-
exists(ConstructedDelegateType delegate, int i, int j, int k |
1408-
m.getParameter(i).getType() instanceof ObjectType and
1409-
m.getParameter(j).getType() = delegate and
1410-
(
1411-
delegate.getUnboundGeneric() instanceof SystemActionTDelegateType or
1412-
delegate.getUnboundGeneric() instanceof SystemFuncDelegateType
1413-
) and
1414-
delegate.getTypeArgument(k) instanceof ObjectType and
1415-
source = TCallableFlowSourceArg(i) and
1416-
sink = getDelegateFlowSinkArg(m, j, k) and
1417-
sinkAp = AccessPath::empty()
1418-
)
1419-
or
1420-
// flow out of supplied function
1421-
exists(ConstructedDelegateType func, int i |
1422-
m.getParameter(i).getType() = func and
1423-
func.getUnboundGeneric() instanceof SystemFuncDelegateType and
1424-
source = getDelegateFlowSourceArg(m, i) and
1425-
sink = TCallableFlowSinkReturn() and
1426-
sinkAp = AccessPath::property(any(SystemThreadingTasksTaskTClass c).getResultProperty())
1427-
)
1428-
)
1429-
or
1430-
m.hasName("FromResult<>") and
1431-
source = TCallableFlowSourceArg(0) and
1432-
sourceAp = AccessPath::empty() and
1433-
sink = TCallableFlowSinkReturn() and
1434-
sinkAp = AccessPath::property(any(SystemThreadingTasksTaskTClass c).getResultProperty())
1435-
or
1436-
m.getName().regexpMatch("Run(<>)?") and
1437-
m.getReturnType() = any(SystemThreadingTasksTaskTClass c).getAConstructedGeneric() and
1438-
m.(UnboundGenericMethod).getNumberOfTypeParameters() = 1 and
1439-
source = TCallableFlowSourceDelegateArg(0) and
1440-
sourceAp = AccessPath::empty() and
1441-
sink = TCallableFlowSinkReturn() and
1442-
sinkAp = AccessPath::property(any(SystemThreadingTasksTaskTClass c).getResultProperty())
1443-
or
1444-
m.getName().regexpMatch("WhenAll(<>)?|WhenAny(<>)?") and
1445-
m.getReturnType() = any(SystemThreadingTasksTaskTClass c).getAConstructedGeneric() and
1446-
m.(UnboundGenericMethod).getNumberOfTypeParameters() = 1 and
1447-
source = getFlowSourceArg(m, _, _) and
1448-
sourceAp = AccessPath::properties(any(SystemThreadingTasksTaskTClass c).getResultProperty()) and
1449-
sink = TCallableFlowSinkReturn() and
1450-
sinkAp =
1451-
AccessPath::cons(any(PropertyContent c |
1452-
c.getProperty() = any(SystemThreadingTasksTaskTClass tc).getResultProperty()
1453-
), AccessPath::element())
1454-
)
1455-
}
1456-
}
1457-
14581368
/** Data flow for `System.Threading.Tasks.Task<>`. */
14591369
class SystemThreadingTasksTaskTFlow extends LibraryTypeDataFlow, SystemThreadingTasksTaskTClass {
14601370
override predicate callableFlow(

csharp/ql/lib/semmle/code/csharp/frameworks/system/threading/Tasks.qll

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import csharp
44
private import semmle.code.csharp.frameworks.system.Threading
5+
private import semmle.code.csharp.dataflow.ExternalFlow
56

67
/** The `System.Threading.Tasks` namespace. */
78
class SystemThreadingTasksNamespace extends Namespace {
@@ -28,6 +29,50 @@ class SystemThreadingTasksTaskClass extends SystemThreadingTasksClass {
2829
SystemThreadingTasksTaskClass() { this.hasName("Task") }
2930
}
3031

32+
/** Data flow for `System.Threading.Tasks.Task`. */
33+
private class SystemThreadingTasksTaskFlowModelCsv extends SummaryModelCsv {
34+
override predicate row(string row) {
35+
row =
36+
[
37+
"System.Threading.Tasks;Task;false;ContinueWith;(System.Action<System.Threading.Tasks.Task,System.Object>,System.Object);;Argument[1];Parameter[1] of Argument[0];value",
38+
"System.Threading.Tasks;Task;false;ContinueWith;(System.Action<System.Threading.Tasks.Task,System.Object>,System.Object,System.Threading.CancellationToken);;Argument[1];Parameter[1] of Argument[0];value",
39+
"System.Threading.Tasks;Task;false;ContinueWith;(System.Action<System.Threading.Tasks.Task,System.Object>,System.Object,System.Threading.CancellationToken,System.Threading.Tasks.TaskContinuationOptions,System.Threading.Tasks.TaskScheduler);;Argument[1];Parameter[1] of Argument[0];value",
40+
"System.Threading.Tasks;Task;false;ContinueWith;(System.Action<System.Threading.Tasks.Task,System.Object>,System.Object,System.Threading.Tasks.TaskContinuationOptions);;Argument[1];Parameter[1] of Argument[0];value",
41+
"System.Threading.Tasks;Task;false;ContinueWith;(System.Action<System.Threading.Tasks.Task,System.Object>,System.Object,System.Threading.Tasks.TaskScheduler);;Argument[1];Parameter[1] of Argument[0];value",
42+
"System.Threading.Tasks;Task;false;ContinueWith<>;(System.Func<System.Threading.Tasks.Task,System.Object,TResult>,System.Object);;Argument[1];Parameter[1] of Argument[0];value",
43+
"System.Threading.Tasks;Task;false;ContinueWith<>;(System.Func<System.Threading.Tasks.Task,System.Object,TResult>,System.Object);;ReturnValue of Argument[0];Property[System.Threading.Tasks.Task<>.Result] of ReturnValue;value",
44+
"System.Threading.Tasks;Task;false;ContinueWith<>;(System.Func<System.Threading.Tasks.Task,System.Object,TResult>,System.Object,System.Threading.CancellationToken);;Argument[1];Parameter[1] of Argument[0];value",
45+
"System.Threading.Tasks;Task;false;ContinueWith<>;(System.Func<System.Threading.Tasks.Task,System.Object,TResult>,System.Object,System.Threading.CancellationToken);;ReturnValue of Argument[0];Property[System.Threading.Tasks.Task<>.Result] of ReturnValue;value",
46+
"System.Threading.Tasks;Task;false;ContinueWith<>;(System.Func<System.Threading.Tasks.Task,System.Object,TResult>,System.Object,System.Threading.CancellationToken,System.Threading.Tasks.TaskContinuationOptions,System.Threading.Tasks.TaskScheduler);;Argument[1];Parameter[1] of Argument[0];value",
47+
"System.Threading.Tasks;Task;false;ContinueWith<>;(System.Func<System.Threading.Tasks.Task,System.Object,TResult>,System.Object,System.Threading.CancellationToken,System.Threading.Tasks.TaskContinuationOptions,System.Threading.Tasks.TaskScheduler);;ReturnValue of Argument[0];Property[System.Threading.Tasks.Task<>.Result] of ReturnValue;value",
48+
"System.Threading.Tasks;Task;false;ContinueWith<>;(System.Func<System.Threading.Tasks.Task,System.Object,TResult>,System.Object,System.Threading.Tasks.TaskContinuationOptions);;Argument[1];Parameter[1] of Argument[0];value",
49+
"System.Threading.Tasks;Task;false;ContinueWith<>;(System.Func<System.Threading.Tasks.Task,System.Object,TResult>,System.Object,System.Threading.Tasks.TaskContinuationOptions);;ReturnValue of Argument[0];Property[System.Threading.Tasks.Task<>.Result] of ReturnValue;value",
50+
"System.Threading.Tasks;Task;false;ContinueWith<>;(System.Func<System.Threading.Tasks.Task,System.Object,TResult>,System.Object,System.Threading.Tasks.TaskScheduler);;Argument[1];Parameter[1] of Argument[0];value",
51+
"System.Threading.Tasks;Task;false;ContinueWith<>;(System.Func<System.Threading.Tasks.Task,System.Object,TResult>,System.Object,System.Threading.Tasks.TaskScheduler);;ReturnValue of Argument[0];Property[System.Threading.Tasks.Task<>.Result] of ReturnValue;value",
52+
"System.Threading.Tasks;Task;false;ContinueWith<>;(System.Func<System.Threading.Tasks.Task,TResult>);;ReturnValue of Argument[0];Property[System.Threading.Tasks.Task<>.Result] of ReturnValue;value",
53+
"System.Threading.Tasks;Task;false;ContinueWith<>;(System.Func<System.Threading.Tasks.Task,TResult>,System.Threading.CancellationToken);;ReturnValue of Argument[0];Property[System.Threading.Tasks.Task<>.Result] of ReturnValue;value",
54+
"System.Threading.Tasks;Task;false;ContinueWith<>;(System.Func<System.Threading.Tasks.Task,TResult>,System.Threading.CancellationToken,System.Threading.Tasks.TaskContinuationOptions,System.Threading.Tasks.TaskScheduler);;ReturnValue of Argument[0];Property[System.Threading.Tasks.Task<>.Result] of ReturnValue;value",
55+
"System.Threading.Tasks;Task;false;ContinueWith<>;(System.Func<System.Threading.Tasks.Task,TResult>,System.Threading.Tasks.TaskContinuationOptions);;ReturnValue of Argument[0];Property[System.Threading.Tasks.Task<>.Result] of ReturnValue;value",
56+
"System.Threading.Tasks;Task;false;ContinueWith<>;(System.Func<System.Threading.Tasks.Task,TResult>,System.Threading.Tasks.TaskScheduler);;ReturnValue of Argument[0];Property[System.Threading.Tasks.Task<>.Result] of ReturnValue;value",
57+
"System.Threading.Tasks;Task;false;FromResult<>;(TResult);;Argument[0];Property[System.Threading.Tasks.Task<>.Result] of ReturnValue;value",
58+
"System.Threading.Tasks;Task;false;Run<>;(System.Func<System.Threading.Tasks.Task<TResult>>);;ReturnValue of Argument[0];Property[System.Threading.Tasks.Task<>.Result] of ReturnValue;value",
59+
"System.Threading.Tasks;Task;false;Run<>;(System.Func<System.Threading.Tasks.Task<TResult>>,System.Threading.CancellationToken);;ReturnValue of Argument[0];Property[System.Threading.Tasks.Task<>.Result] of ReturnValue;value",
60+
"System.Threading.Tasks;Task;false;Run<>;(System.Func<TResult>);;ReturnValue of Argument[0];Property[System.Threading.Tasks.Task<>.Result] of ReturnValue;value",
61+
"System.Threading.Tasks;Task;false;Run<>;(System.Func<TResult>,System.Threading.CancellationToken);;ReturnValue of Argument[0];Property[System.Threading.Tasks.Task<>.Result] of ReturnValue;value",
62+
"System.Threading.Tasks;Task;false;Task;(System.Action<System.Object>,System.Object);;Argument[1];Parameter[0] of Argument[0];value",
63+
"System.Threading.Tasks;Task;false;Task;(System.Action<System.Object>,System.Object,System.Threading.CancellationToken);;Argument[1];Parameter[0] of Argument[0];value",
64+
"System.Threading.Tasks;Task;false;Task;(System.Action<System.Object>,System.Object,System.Threading.CancellationToken,System.Threading.Tasks.TaskCreationOptions);;Argument[1];Parameter[0] of Argument[0];value",
65+
"System.Threading.Tasks;Task;false;Task;(System.Action<System.Object>,System.Object,System.Threading.Tasks.TaskCreationOptions);;Argument[1];Parameter[0] of Argument[0];value",
66+
"System.Threading.Tasks;Task;false;WhenAll<>;(System.Collections.Generic.IEnumerable<System.Threading.Tasks.Task<TResult>>);;Property[System.Threading.Tasks.Task<>.Result] of Element of Argument[0];Element of Property[System.Threading.Tasks.Task<>.Result] of ReturnValue;value",
67+
"System.Threading.Tasks;Task;false;WhenAll<>;(System.Threading.Tasks.Task<TResult>[]);;Property[System.Threading.Tasks.Task<>.Result] of Element of Argument[0];Element of Property[System.Threading.Tasks.Task<>.Result] of ReturnValue;value",
68+
"System.Threading.Tasks;Task;false;WhenAny<>;(System.Collections.Generic.IEnumerable<System.Threading.Tasks.Task<TResult>>);;Property[System.Threading.Tasks.Task<>.Result] of Element of Argument[0];Element of Property[System.Threading.Tasks.Task<>.Result] of ReturnValue;value",
69+
"System.Threading.Tasks;Task;false;WhenAny<>;(System.Threading.Tasks.Task<TResult>,System.Threading.Tasks.Task<TResult>);;Property[System.Threading.Tasks.Task<>.Result] of Element of Argument[0];Element of Property[System.Threading.Tasks.Task<>.Result] of ReturnValue;value",
70+
"System.Threading.Tasks;Task;false;WhenAny<>;(System.Threading.Tasks.Task<TResult>,System.Threading.Tasks.Task<TResult>);;Property[System.Threading.Tasks.Task<>.Result] of Element of Argument[1];Element of Property[System.Threading.Tasks.Task<>.Result] of ReturnValue;value",
71+
"System.Threading.Tasks;Task;false;WhenAny<>;(System.Threading.Tasks.Task<TResult>[]);;Property[System.Threading.Tasks.Task<>.Result] of Element of Argument[0];Element of Property[System.Threading.Tasks.Task<>.Result] of ReturnValue;value",
72+
]
73+
}
74+
}
75+
3176
/** The `System.Threading.Tasks.Task<T>` class. */
3277
class SystemThreadingTasksTaskTClass extends SystemThreadingTasksUnboundGenericClass {
3378
SystemThreadingTasksTaskTClass() { this.hasName("Task<>") }

0 commit comments

Comments
 (0)