Skip to content

Commit 440976f

Browse files
committed
C#: Convert System.Threading.Tasks.Task<> flow to CSV format.
1 parent cde98c7 commit 440976f

File tree

2 files changed

+64
-120
lines changed

2 files changed

+64
-120
lines changed

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

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

1368-
/** Data flow for `System.Threading.Tasks.Task<>`. */
1369-
class SystemThreadingTasksTaskTFlow extends LibraryTypeDataFlow, SystemThreadingTasksTaskTClass {
1370-
override predicate callableFlow(
1371-
CallableFlowSource source, AccessPath sourceAp, CallableFlowSink sink, AccessPath sinkAp,
1372-
SourceDeclarationCallable c, boolean preservesValue
1373-
) {
1374-
(
1375-
this.constructorFlow(source, sourceAp, sink, sinkAp, c)
1376-
or
1377-
this.methodFlow(source, sourceAp, sink, sinkAp, c)
1378-
) and
1379-
preservesValue = true
1380-
or
1381-
exists(Property p |
1382-
p = this.(SystemThreadingTasksTaskTClass).getResultProperty() and
1383-
source = TCallableFlowSourceQualifier() and
1384-
sourceAp = AccessPath::empty() and
1385-
sink = TCallableFlowSinkReturn() and
1386-
sinkAp = AccessPath::empty() and
1387-
c = p.getGetter() and
1388-
preservesValue = false
1389-
)
1390-
}
1391-
1392-
private predicate constructorFlow(
1393-
CallableFlowSource source, AccessPath sourceAp, CallableFlowSink sink, AccessPath sinkAp,
1394-
Constructor c
1395-
) {
1396-
// flow from supplied function into constructed Task
1397-
c.getDeclaringType() = this and
1398-
c.getParameter(0).getType() = any(SystemFuncDelegateType t).getAConstructedGeneric() and
1399-
source = TCallableFlowSourceDelegateArg(0) and
1400-
sourceAp = AccessPath::empty() and
1401-
sink = TCallableFlowSinkReturn() and
1402-
sinkAp = AccessPath::property(this.(SystemThreadingTasksTaskTClass).getResultProperty())
1403-
or
1404-
// flow from supplied state to supplied delegate
1405-
c.getDeclaringType() = this and
1406-
exists(ConstructedDelegateType func |
1407-
c.getParameter(1).getType() instanceof ObjectType and
1408-
c.getParameter(0).getType() = func and
1409-
func.getUnboundGeneric().(SystemFuncDelegateType).getNumberOfTypeParameters() = 2 and
1410-
func.getTypeArgument(0) instanceof ObjectType and
1411-
source = TCallableFlowSourceArg(1) and
1412-
sourceAp = AccessPath::empty() and
1413-
sink = getDelegateFlowSinkArg(c, 0, 0) and
1414-
sinkAp = AccessPath::empty()
1415-
)
1416-
}
1417-
1418-
private predicate methodFlow(
1419-
CallableFlowSource source, AccessPath sourceAp, CallableFlowSink sink, AccessPath sinkAp,
1420-
SourceDeclarationMethod m
1421-
) {
1422-
m.getDeclaringType() = this and
1423-
m.getName().regexpMatch("ContinueWith(<>)?") and
1424-
(
1425-
exists(ConstructedDelegateType delegate, int i, int j |
1426-
m.getParameter(i).getType() = delegate and
1427-
(
1428-
delegate.getUnboundGeneric() instanceof SystemActionTDelegateType or
1429-
delegate.getUnboundGeneric() instanceof SystemFuncDelegateType
1430-
)
1431-
|
1432-
// flow from supplied state to supplied delegate
1433-
exists(int k |
1434-
delegate.getTypeArgument(j) instanceof ObjectType and
1435-
m.getParameter(k).getType() instanceof ObjectType and
1436-
source = TCallableFlowSourceArg(k) and
1437-
sourceAp = AccessPath::empty() and
1438-
sink = getDelegateFlowSinkArg(m, i, j) and
1439-
sinkAp = AccessPath::empty()
1440-
)
1441-
or
1442-
// flow from this task to supplied delegate
1443-
delegate.getTypeArgument(j) = this and
1444-
source = TCallableFlowSourceQualifier() and
1445-
sourceAp = AccessPath::empty() and
1446-
sink = getDelegateFlowSinkArg(m, i, j) and
1447-
sinkAp = AccessPath::empty()
1448-
)
1449-
or
1450-
// flow out of supplied function
1451-
exists(ConstructedDelegateType func, int i |
1452-
m.getParameter(i).getType() = func and
1453-
func.getUnboundGeneric() instanceof SystemFuncDelegateType and
1454-
source = getDelegateFlowSourceArg(m, i) and
1455-
sourceAp = AccessPath::empty() and
1456-
sink = TCallableFlowSinkReturn() and
1457-
sinkAp = AccessPath::property(this.(SystemThreadingTasksTaskTClass).getResultProperty())
1458-
)
1459-
)
1460-
or
1461-
m = this.getGetAwaiterMethod() and
1462-
source = TCallableFlowSourceQualifier() and
1463-
sourceAp = AccessPath::empty() and
1464-
sink = TCallableFlowSinkReturn() and
1465-
sinkAp = AccessPath::synthetic(any(SyntheticTaskAwaiterUnderlyingTaskField s))
1466-
or
1467-
// var awaitable = task.ConfigureAwait(false); // <-- new ConfiguredTaskAwaitable<>(task, false)
1468-
// // m_configuredTaskAwaiter = new ConfiguredTaskAwaiter(task, false)
1469-
// // m_task = task
1470-
// var awaiter = awaitable.GetAwaiter();
1471-
// var result = awaiter.GetResult();
1472-
m = this.getConfigureAwaitMethod() and
1473-
source = TCallableFlowSourceQualifier() and
1474-
sourceAp = AccessPath::empty() and
1475-
sink = TCallableFlowSinkReturn() and
1476-
sinkAp =
1477-
AccessPath::cons(any(SyntheticFieldContent sfc |
1478-
sfc.getField() instanceof SyntheticConfiguredTaskAwaiterField
1479-
), AccessPath::synthetic(any(SyntheticConfiguredTaskAwaitableUnderlyingTaskField s)))
1480-
}
1481-
1482-
override predicate requiresAccessPath(Content head, AccessPath tail) {
1483-
head.(SyntheticFieldContent).getField() instanceof SyntheticConfiguredTaskAwaiterField and
1484-
tail = AccessPath::synthetic(any(SyntheticConfiguredTaskAwaitableUnderlyingTaskField s))
1485-
}
1486-
}
1487-
14881368
abstract private class SyntheticTaskField extends SyntheticField {
14891369
bindingset[this]
14901370
SyntheticTaskField() { any() }

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

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,67 @@ class SystemThreadingTasksTaskTClass extends SystemThreadingTasksUnboundGenericC
9090
/** Gets the `ConfigureAwait` method. */
9191
Method getConfigureAwaitMethod() { result = this.getAMethod("ConfigureAwait") }
9292
}
93+
94+
/** Data flow for `System.Threading.Tasks.Task<>`. */
95+
private class SystemThreadingTasksTaskTFlowModelCsv extends SummaryModelCsv {
96+
override predicate row(string row) {
97+
row =
98+
[
99+
"System.Threading.Tasks;Task<>;false;ConfigureAwait;(System.Boolean);;Argument[-1];SyntheticField[m_task_configured_task_awaitable] of SyntheticField[m_configuredTaskAwaiter] of ReturnValue;value",
100+
"System.Threading.Tasks;Task<>;false;ContinueWith;(System.Action<System.Threading.Tasks.Task<>,System.Object>,System.Object);;Argument[1];Parameter[1] of Argument[0];value",
101+
"System.Threading.Tasks;Task<>;false;ContinueWith;(System.Action<System.Threading.Tasks.Task<>,System.Object>,System.Object);;Argument[-1];Parameter[0] of Argument[0];value",
102+
"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",
103+
"System.Threading.Tasks;Task<>;false;ContinueWith;(System.Action<System.Threading.Tasks.Task<>,System.Object>,System.Object,System.Threading.CancellationToken);;Argument[-1];Parameter[0] of Argument[0];value",
104+
"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",
105+
"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[0] of Argument[0];value",
106+
"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",
107+
"System.Threading.Tasks;Task<>;false;ContinueWith;(System.Action<System.Threading.Tasks.Task<>,System.Object>,System.Object,System.Threading.Tasks.TaskContinuationOptions);;Argument[-1];Parameter[0] of Argument[0];value",
108+
"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",
109+
"System.Threading.Tasks;Task<>;false;ContinueWith;(System.Action<System.Threading.Tasks.Task<>,System.Object>,System.Object,System.Threading.Tasks.TaskScheduler);;Argument[-1];Parameter[0] of Argument[0];value",
110+
"System.Threading.Tasks;Task<>;false;ContinueWith;(System.Action<System.Threading.Tasks.Task<>>);;Argument[-1];Parameter[0] of Argument[0];value",
111+
"System.Threading.Tasks;Task<>;false;ContinueWith;(System.Action<System.Threading.Tasks.Task<>>,System.Threading.CancellationToken);;Argument[-1];Parameter[0] of Argument[0];value",
112+
"System.Threading.Tasks;Task<>;false;ContinueWith;(System.Action<System.Threading.Tasks.Task<>>,System.Threading.CancellationToken,System.Threading.Tasks.TaskContinuationOptions,System.Threading.Tasks.TaskScheduler);;Argument[-1];Parameter[0] of Argument[0];value",
113+
"System.Threading.Tasks;Task<>;false;ContinueWith;(System.Action<System.Threading.Tasks.Task<>>,System.Threading.Tasks.TaskContinuationOptions);;Argument[-1];Parameter[0] of Argument[0];value",
114+
"System.Threading.Tasks;Task<>;false;ContinueWith;(System.Action<System.Threading.Tasks.Task<>>,System.Threading.Tasks.TaskScheduler);;Argument[-1];Parameter[0] of Argument[0];value",
115+
"System.Threading.Tasks;Task<>;false;ContinueWith<>;(System.Func<System.Threading.Tasks.Task<>,System.Object,TNewResult>,System.Object);;Argument[1];Parameter[1] of Argument[0];value",
116+
"System.Threading.Tasks;Task<>;false;ContinueWith<>;(System.Func<System.Threading.Tasks.Task<>,System.Object,TNewResult>,System.Object);;Argument[-1];Parameter[0] of Argument[0];value",
117+
"System.Threading.Tasks;Task<>;false;ContinueWith<>;(System.Func<System.Threading.Tasks.Task<>,System.Object,TNewResult>,System.Object);;ReturnValue of Argument[0];Property[System.Threading.Tasks.Task<>.Result] of ReturnValue;value",
118+
"System.Threading.Tasks;Task<>;false;ContinueWith<>;(System.Func<System.Threading.Tasks.Task<>,System.Object,TNewResult>,System.Object,System.Threading.CancellationToken);;Argument[1];Parameter[1] of Argument[0];value",
119+
"System.Threading.Tasks;Task<>;false;ContinueWith<>;(System.Func<System.Threading.Tasks.Task<>,System.Object,TNewResult>,System.Object,System.Threading.CancellationToken);;Argument[-1];Parameter[0] of Argument[0];value",
120+
"System.Threading.Tasks;Task<>;false;ContinueWith<>;(System.Func<System.Threading.Tasks.Task<>,System.Object,TNewResult>,System.Object,System.Threading.CancellationToken);;ReturnValue of Argument[0];Property[System.Threading.Tasks.Task<>.Result] of ReturnValue;value",
121+
"System.Threading.Tasks;Task<>;false;ContinueWith<>;(System.Func<System.Threading.Tasks.Task<>,System.Object,TNewResult>,System.Object,System.Threading.CancellationToken,System.Threading.Tasks.TaskContinuationOptions,System.Threading.Tasks.TaskScheduler);;Argument[1];Parameter[1] of Argument[0];value",
122+
"System.Threading.Tasks;Task<>;false;ContinueWith<>;(System.Func<System.Threading.Tasks.Task<>,System.Object,TNewResult>,System.Object,System.Threading.CancellationToken,System.Threading.Tasks.TaskContinuationOptions,System.Threading.Tasks.TaskScheduler);;Argument[-1];Parameter[0] of Argument[0];value",
123+
"System.Threading.Tasks;Task<>;false;ContinueWith<>;(System.Func<System.Threading.Tasks.Task<>,System.Object,TNewResult>,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",
124+
"System.Threading.Tasks;Task<>;false;ContinueWith<>;(System.Func<System.Threading.Tasks.Task<>,System.Object,TNewResult>,System.Object,System.Threading.Tasks.TaskContinuationOptions);;Argument[1];Parameter[1] of Argument[0];value",
125+
"System.Threading.Tasks;Task<>;false;ContinueWith<>;(System.Func<System.Threading.Tasks.Task<>,System.Object,TNewResult>,System.Object,System.Threading.Tasks.TaskContinuationOptions);;Argument[-1];Parameter[0] of Argument[0];value",
126+
"System.Threading.Tasks;Task<>;false;ContinueWith<>;(System.Func<System.Threading.Tasks.Task<>,System.Object,TNewResult>,System.Object,System.Threading.Tasks.TaskContinuationOptions);;ReturnValue of Argument[0];Property[System.Threading.Tasks.Task<>.Result] of ReturnValue;value",
127+
"System.Threading.Tasks;Task<>;false;ContinueWith<>;(System.Func<System.Threading.Tasks.Task<>,System.Object,TNewResult>,System.Object,System.Threading.Tasks.TaskScheduler);;Argument[1];Parameter[1] of Argument[0];value",
128+
"System.Threading.Tasks;Task<>;false;ContinueWith<>;(System.Func<System.Threading.Tasks.Task<>,System.Object,TNewResult>,System.Object,System.Threading.Tasks.TaskScheduler);;Argument[-1];Parameter[0] of Argument[0];value",
129+
"System.Threading.Tasks;Task<>;false;ContinueWith<>;(System.Func<System.Threading.Tasks.Task<>,System.Object,TNewResult>,System.Object,System.Threading.Tasks.TaskScheduler);;ReturnValue of Argument[0];Property[System.Threading.Tasks.Task<>.Result] of ReturnValue;value",
130+
"System.Threading.Tasks;Task<>;false;ContinueWith<>;(System.Func<System.Threading.Tasks.Task<>,TNewResult>);;Argument[-1];Parameter[0] of Argument[0];value",
131+
"System.Threading.Tasks;Task<>;false;ContinueWith<>;(System.Func<System.Threading.Tasks.Task<>,TNewResult>);;ReturnValue of Argument[0];Property[System.Threading.Tasks.Task<>.Result] of ReturnValue;value",
132+
"System.Threading.Tasks;Task<>;false;ContinueWith<>;(System.Func<System.Threading.Tasks.Task<>,TNewResult>,System.Threading.CancellationToken);;Argument[-1];Parameter[0] of Argument[0];value",
133+
"System.Threading.Tasks;Task<>;false;ContinueWith<>;(System.Func<System.Threading.Tasks.Task<>,TNewResult>,System.Threading.CancellationToken);;ReturnValue of Argument[0];Property[System.Threading.Tasks.Task<>.Result] of ReturnValue;value",
134+
"System.Threading.Tasks;Task<>;false;ContinueWith<>;(System.Func<System.Threading.Tasks.Task<>,TNewResult>,System.Threading.CancellationToken,System.Threading.Tasks.TaskContinuationOptions,System.Threading.Tasks.TaskScheduler);;Argument[-1];Parameter[0] of Argument[0];value",
135+
"System.Threading.Tasks;Task<>;false;ContinueWith<>;(System.Func<System.Threading.Tasks.Task<>,TNewResult>,System.Threading.CancellationToken,System.Threading.Tasks.TaskContinuationOptions,System.Threading.Tasks.TaskScheduler);;ReturnValue of Argument[0];Property[System.Threading.Tasks.Task<>.Result] of ReturnValue;value",
136+
"System.Threading.Tasks;Task<>;false;ContinueWith<>;(System.Func<System.Threading.Tasks.Task<>,TNewResult>,System.Threading.Tasks.TaskContinuationOptions);;Argument[-1];Parameter[0] of Argument[0];value",
137+
"System.Threading.Tasks;Task<>;false;ContinueWith<>;(System.Func<System.Threading.Tasks.Task<>,TNewResult>,System.Threading.Tasks.TaskContinuationOptions);;ReturnValue of Argument[0];Property[System.Threading.Tasks.Task<>.Result] of ReturnValue;value",
138+
"System.Threading.Tasks;Task<>;false;ContinueWith<>;(System.Func<System.Threading.Tasks.Task<>,TNewResult>,System.Threading.Tasks.TaskScheduler);;Argument[-1];Parameter[0] of Argument[0];value",
139+
"System.Threading.Tasks;Task<>;false;ContinueWith<>;(System.Func<System.Threading.Tasks.Task<>,TNewResult>,System.Threading.Tasks.TaskScheduler);;ReturnValue of Argument[0];Property[System.Threading.Tasks.Task<>.Result] of ReturnValue;value",
140+
"System.Threading.Tasks;Task<>;false;GetAwaiter;();;Argument[-1];SyntheticField[m_task_task_awaiter] of ReturnValue;value",
141+
"System.Threading.Tasks;Task<>;false;Task;(System.Func<System.Object,TResult>,System.Object);;Argument[1];Parameter[0] of Argument[0];value",
142+
"System.Threading.Tasks;Task<>;false;Task;(System.Func<System.Object,TResult>,System.Object);;ReturnValue of Argument[0];Property[System.Threading.Tasks.Task<>.Result] of ReturnValue;value",
143+
"System.Threading.Tasks;Task<>;false;Task;(System.Func<System.Object,TResult>,System.Object,System.Threading.CancellationToken);;Argument[1];Parameter[0] of Argument[0];value",
144+
"System.Threading.Tasks;Task<>;false;Task;(System.Func<System.Object,TResult>,System.Object,System.Threading.CancellationToken);;ReturnValue of Argument[0];Property[System.Threading.Tasks.Task<>.Result] of ReturnValue;value",
145+
"System.Threading.Tasks;Task<>;false;Task;(System.Func<System.Object,TResult>,System.Object,System.Threading.CancellationToken,System.Threading.Tasks.TaskCreationOptions);;Argument[1];Parameter[0] of Argument[0];value",
146+
"System.Threading.Tasks;Task<>;false;Task;(System.Func<System.Object,TResult>,System.Object,System.Threading.CancellationToken,System.Threading.Tasks.TaskCreationOptions);;ReturnValue of Argument[0];Property[System.Threading.Tasks.Task<>.Result] of ReturnValue;value",
147+
"System.Threading.Tasks;Task<>;false;Task;(System.Func<System.Object,TResult>,System.Object,System.Threading.Tasks.TaskCreationOptions);;Argument[1];Parameter[0] of Argument[0];value",
148+
"System.Threading.Tasks;Task<>;false;Task;(System.Func<System.Object,TResult>,System.Object,System.Threading.Tasks.TaskCreationOptions);;ReturnValue of Argument[0];Property[System.Threading.Tasks.Task<>.Result] of ReturnValue;value",
149+
"System.Threading.Tasks;Task<>;false;Task;(System.Func<TResult>);;ReturnValue of Argument[0];Property[System.Threading.Tasks.Task<>.Result] of ReturnValue;value",
150+
"System.Threading.Tasks;Task<>;false;Task;(System.Func<TResult>,System.Threading.CancellationToken);;ReturnValue of Argument[0];Property[System.Threading.Tasks.Task<>.Result] of ReturnValue;value",
151+
"System.Threading.Tasks;Task<>;false;Task;(System.Func<TResult>,System.Threading.CancellationToken,System.Threading.Tasks.TaskCreationOptions);;ReturnValue of Argument[0];Property[System.Threading.Tasks.Task<>.Result] of ReturnValue;value",
152+
"System.Threading.Tasks;Task<>;false;Task;(System.Func<TResult>,System.Threading.Tasks.TaskCreationOptions);;ReturnValue of Argument[0];Property[System.Threading.Tasks.Task<>.Result] of ReturnValue;value",
153+
"System.Threading.Tasks;Task<>;false;get_Result;();;Argument[-1];ReturnValue;taint"
154+
]
155+
}
156+
}

0 commit comments

Comments
 (0)